Commit 66ae6238 authored by Emiliano Merlin's avatar Emiliano Merlin

v2.1

parent b1a49ae6
......@@ -26,12 +26,16 @@ Script to make output LRI catalog the same length as any input catalog
adding fake entries for missing sources
"""
def adapt(hrcat,LRIcat,OUTcat):
def adapt(hrcat,LRIcat,OUTcat,Nhead):
fff=open(LRIcat,'r')
lines=fff.readlines()
out=open(OUTcat,'w')
out.write("# 1 ObjectID\n# 2 X\n# 3 Y\n# 4 Cell \n# 5 cx X pos in cell \n# 6 cy Y pos in cell \n# 7 Rcell \n# 8 FitQty Fit Quantity (Flux or Scale Factor)\n# 9 FitQuErr Variance of Fit Quantity\n# 10 SExF SExtractor flux_best in hires catalog\n# 11 Totflux Total flux in hires cutout\n# 12 Flag Flag for saturation and/or prior blending\n# 13 NumFits Number of fits for this object\n# 14 MaxFlag Max flag value in object template\n# 15 MaxCvID\n# 16 MaxCvRatio\n")
out.write("# 1 ObjectID\n# 2 X\n# 3 Y\n# 4 Cell \n# 5 cx X pos in cell \n# 6 cy Y pos in cell \n# 7 Rcell \n# 8 FitQty Fit Quantity (Flux or Scale Factor)\n# 9 FitQuErr Variance of Fit Quantity\n# 10 SExF SExtractor flux_best in hires catalog\n# 11 Totflux Total flux in hires cutout\n# 12 Flag Flag for saturation and/or prior blending\n# 13 NumFits Number of fits for this object\n# 14 MaxFlag Max flag value in object template\n")
if Nhead==16:
out.write("# 15 MaxCvID\n# 16 MaxCvRatio\n")
#hrcat=ascii.read(HRIcat)
lrcat=ascii.read(LRIcat)
......@@ -41,6 +45,8 @@ def adapt(hrcat,LRIcat,OUTcat):
sniffer = csv.Sniffer()
for lll in hrcat:
while (lll[0]==' ') or (lll[0]==''):
lll=lll[1:]
dialect = sniffer.sniff(lll)
sep=dialect.delimiter
......@@ -54,7 +60,7 @@ def adapt(hrcat,LRIcat,OUTcat):
if id in IDsLR:
idx=IDsLR.index(id)
out.write(lines[idx+16])
out.write(lines[idx+Nhead])
else:
out.write("%d %f %f 0 0.0000 0.0000 0.0000 -0.990000E+02 0.990000E+10 0.0 0.0 100 0 -99 0 99.0000\n"%(id,x,y))
......
......@@ -210,7 +210,6 @@ def run2(covarname,catname,cdict=None,cat=None):
cat.addemptycolumn('maxcvid','Int32')
cat.addemptycolumn('maxcvflux','Float32')
print "ooooooooooo"
for ob in cat:
obid=cat.objectid[ob]
print obid
......
......@@ -249,9 +249,10 @@ def main(tphotcat, modelfile, loresfile, templatedir, templatecat, tphotcovar, e
idmapname,
header=lores.h)
tphotcat_best=tphotcat+"_best"
if writecovar:
# calculate covariance index and append to tphot cat file
tphotcovardir=tphotcovar+"_covardir"
tphotcat_best=tphotcat+"_best"
tphotcat_new=tphotcat_best+"_plus_covar"
set_covar_info.covar(tphotcat_best,tphotcovardir)
......@@ -259,9 +260,15 @@ def main(tphotcat, modelfile, loresfile, templatedir, templatecat, tphotcovar, e
os.system("mv %s %s" % (tphotcat_best,tphotcat_best+"_OLD") )
os.system("mv %s %s" % (tphotcat_new, tphotcat_best) )
if not (writecovar):
os.remove(tphotcovar)
shutil.rmtree(tphotcovardir)
Nhead=16
else:
Nhead=14
# else: # writecovar:
# os.remove(tphotcovar)
# shutil.rmtree(tphotcovardir)
# If required, do statistics on residual image
if residstats==True:
......@@ -274,6 +281,7 @@ def main(tphotcat, modelfile, loresfile, templatedir, templatecat, tphotcovar, e
# than input catalog(s) and if so make it good
fullcat=[]
for catt in inputcats:
try:
i=open(catt)
il=i.readlines()
......@@ -298,9 +306,10 @@ def main(tphotcat, modelfile, loresfile, templatedir, templatecat, tphotcovar, e
for iii in fullcat:
if iii[0]!='#':
nini+=1
if (nini != N.size(ol)-16):
if (nini != N.size(ol)-Nhead):
print ("Finalizing output catalog including previously rejected sources")
stat=adapt(fullcat,fo,fout)
stat=adapt(fullcat,fo,fout,Nhead)
if stat!=0:
print "WARNING: could not reshape final catalog. Skipping"
else:
......
......@@ -232,6 +232,7 @@ def excerpt_fit_pars(d):
cmd+=' '+str(orderedfile)
cmd+=' '+str(1)
if d.has_key('apertures'):
cmd+=' '+str(d['tphotcat'])+'_apertures'
naper=np.size(d['apertures'])
cmd+=' '+str(naper)
for ap in range(naper):
......@@ -239,48 +240,6 @@ def excerpt_fit_pars(d):
return cmd
"""
# Write ParameterFile
out=open(d['fitpars'],'w')
out.write("LOW_RES_IMAGE %s \n"%d['loresfile'])
out.write("OBJECT_LIST %s \n"%catal)
out.write("TEMPLATE_DIR %s/ \n"%d['templatedir'])
out.write("OUTPUT_LIST %s \n"%d['tphotcat'])
out.write("CELLFILE %s \n"%d['tphotcell'])
if d.has_key('hiresseg'):
out.write("SEGM_IMAGE %s \n"%d['hiresseg'])
out.write("USE_ERRORS %s \n"%d['errtype'].upper())
out.write("ERR_MAP %s \n"%d['loreserr'])
out.write("RMS_CONSTANT %f \n"%d['rmsconstant'])
out.write("CELLMASK %s \n"%d['cellmask'])
out.write("FLOOR %g \n"%d['maskfloor'])
out.write("DITHERCELL %s \n"%d['dithercell'])
out.write("FLAG_MAP %s \n"%d.get('loresflag','None'))
out.write("MAX_FLAG %d \n"%d['maxflag'])
out.write("FIT_BACKGROUND %s \n"%d['fitbackground'])
out.write("BG_CONSTANT %g \n"%d['bgconstant'])
out.write("EXPORT_COVAR_INFO True\n") #%d['writecovar'])
out.write("COVARIANCE_FILE %s \n"%d['tphotcovar'])
out.write("XBUFFERSIZE %d\n"%d['cell_xdim'])
out.write("YBUFFERSIZE %d\n"%d['cell_ydim'])
out.write("FLAG_DISTANCE %d\n"%d['cell_overlap'])
out.write("THRESHOLD %f\n"%d['threshold'])
out.write("LINSYS_SOLVER %s\n"%d['linsyssolver'].upper())
out.write("CLIP %s\n"%d['clip'])
out.write("NPROC %d\n"%d['nproc'])
out.write("ZPHR %f\n"%d.get('zphr',0.0))
out.write("ZPLR %f\n"%d.get('zplr',0.0))
out.write("FLUXORDEREDCATALOG %s\n"%orderedfile)
out.write()MEPROC
if d.has_key('apertures'):
naper=np.size(d['apertures'])
out.write("NAPER %d\n"%naper)
for ap in range(naper):
out.write("APER%d %f\n"%(ap+1,d['apertures'][ap]))
out.close()
return d['fitpars']
"""
#---------------------------------------------------------------------------
def minimize(d):
......@@ -322,6 +281,7 @@ def minimize(d):
outfile=d['tphotcat']
outcell=d['tphotcell']
if (d['writecovar']):
outcovar=d['tphotcovar']
if (nproc>1):
......@@ -372,9 +332,11 @@ def minimize(d):
if (d['writecovar']):
covar.close()
else:
os.rename(outfile+"_1",outfile)
os.rename(outcell+"_1",outcell)
if (d['writecovar']):
os.rename(outcovar+"_1",outcovar)
# If apertures, order catalog
......@@ -385,6 +347,7 @@ def minimize(d):
ascii.write(c,'temp')
os.rename('temp',ap)
if (d['writecovar']):
# produce covariance matrix for each object in fits format
# files are placed under a subdirectory called tfitcovar+'_covardir'
# where tfitcovar is the name of the covariance matrix (ascii file)
......
TPHOT 2.1
Sep 24 2019
E. Merlin
Corrected a few bugs caused by the latest modifications.
***
TPHOT 2.0.9
Apr 4 2019
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment