def photautocal(self,reference,reflimit=30,selflimit=30): """Find the rough WCS for this image, based on reference star_phootmetry, by cross-identifying stars by ID in DS9""" iraf.display(self.image,1) temp = iraf.pdump(self.photfile,"xcen,ycen,id","MAG<%f"%selflimit,Stdout=1) iraf.tvmark(1,"STDIN",Stdin=temp) iraf.display(reference.image,2) temp = iraf.pdump(reference.photfile,"xcen,ycen,id","MAG<%f"%reflimit,Stdout=1) iraf.tvmark(2,"STDIN",Stdin=temp) fred = open('tempautocal','w') input1=None input2=None print "Cross identify at least five stars, <q> to continue" while (input1!='q')and(input2!='q'): print input1 = raw_input("Star ID on Frame 1: ") input2 = raw_input("Matches star ID on Frame 2: ") try: star1 = self[int(input1)] star2 = reference[int(input2)] except: print "Known star integers required" continue fred.write("%f %f %f %f\n"%(star1[1],star1[2],star2[7],star2[8])) fred.close() iraf.ccmap(input='tempautocal',images=self.image,lngunits='degrees', database='database',fit='rxyscale',update='yes',inter='yes') print "Recalculating data" self.calcradec() print "If happy, now run ast_by_photometry"
def main(): files = np.loadtxt("filenames_M8_wcs.txt", dtype='str') for infile in files: print infile ccmapfile = open('Lagoon_2MASS_xy_radec.dat', 'w') newfile = infile.replace('wcs', 'wcs2') copyfile(infile, newfile) coords = np.loadtxt('Lagoon_2MASS_radec_amended.dat', dtype=str) ra = coords[:, 0] ra = np.array([float(i) for i in ra]) dec = coords[:, 1] dec = np.array([float(i) for i in dec]) # open image: instr = fits.open(infile, mode='readonly', memmap=True) pixels = instr[0].data[:] crval1p = instr[0].header['CRVAL1P'] crval2p = instr[0].header['CRVAL2P'] instr.close() for i in np.arange(len(ra)): skyposition = SkyCoord(ra[i], dec[i], unit=('deg', 'deg'), frame='icrs') wcs = WCS(infile) pixelpos = skycoord_to_pixel(skyposition, wcs=wcs) columns = str(int(round(pixelpos[0]))) rows = str(int(round(pixelpos[1]))) ## Guess at flux: fluxguess = str(pixels[int(rows), int(columns)]) result = kepprf_AMC.kepprf_AMC(infile,'1',columns,rows,fluxguess,border=1,background='yes',focus='no', \ prfdir='/Users/acody/Data/Kepler',xtol=0.0001,ftol=0.01,verbose=False,logfile='kepprf.log') newx = result[1] - crval1p + 1 newy = result[2] - crval2p + 1 print >> ccmapfile, newx, newy, ra[i], dec[i] ccmapfile.close() # Call ccmap to compute new wcs iraf.ccmap("Lagoon_2MASS_xy_radec.dat", "Lagoon_coordfit.db", images=newfile, lngunit="degrees", latunit="degrees", update="yes", verbose="no", interactive="no") os.remove('Lagoon_2MASS_xy_radec.dat') os.remove('Lagoon_coordfit.db')
def rscale_ccmap(ccmap_in, database, images, xcol=1, ycol=2, racol=3, deccol=4, lngunits='degrees', latunits='degrees', interactive=True): """ Uses the pyraf ccmap task to update the WCS """ from pyraf import iraf iraf.ccmap(ccmap_in,database,images=images,xcolumn=xcol,ycolumn=ycol, lngcolumn=racol,latcolumn=deccol,lngunits=lngunits, latunits=latunits,insystem='j2000',fitgeometry='rscale', maxiter=1,reject=2.5,update=True,interactive=interactive)
def ast(self,RA,dec,limit): """Does the astrometric calibration. You can call this directly, if you want to load data and filter before calibrating""" fred = open('tempcoordfile','w') for i in range(len(RA)): star = self.starbyWCS(RA[i],dec[i],limit=limit) if not(star is None): fred.write("%f %f %f %f\n"%(star[1],star[2],RA[i],dec[i])) fred.close() iraf.ccmap(input='tempcoordfile',images=self.image,lngunits='degrees', database='database',fit='rxyscale',update='yes',inter='yes') print "Recalculating data" self.calcradec()
def autoast(self,infile='asu.fit',RAfield='RAJ2000',decfield='DEJ2000',magfield='Vmag',magoff=None, markmax=30,crosses=False): """Calibrate image from file of data (2mass etc) by making initial astrometry by selecting a handful of stars, them using the other cal routines RAfield: column with RA (decimal!). decfield: column with dec (decimal!). magfield: column to calibrate magnitude by""" global xpoint,ypoint if self.image is None: print "No image to calibrate data by" return RA,dec,mag = load_data(infile,RAfield,decfield,magfield) fig = pylab.figure(figsize=(8,8)) pylab.clf() try: magoff = magoff or mag.max() pylab.scatter(RA[mag>0],dec[mag>0],s=10**(0.4*(magoff-mag[mag>0])),hold=0,alpha=0.5) except: crosses=True if crosses: pylab.plot(RA,dec,'k+') pylab.axis([RA.max(),RA.min(),dec.min(),dec.max()]) pylab.draw() cid = fig.canvas.mpl_connect('button_press_event',self._on_press) iraf.display(self.image,1) iraf.tvmark(1,"STDIN",Stdin=iraf.pdump(self.photfile,"xcen,ycen,id","MAG<%f"%markmax,Stdout=1)) print "Pick five stars with middle button, then enter their IDs in order,\n<q> to continue" ids = []; self.xpoint=[]; self.ypoint=[] select = None while not(select=='q'): select=raw_input('Star ID: ') try: ids.append(int(select)) except: pass fig.canvas.mpl_disconnect('button_press_event') fred = open('autocalcoords','w') for i in range(min(len(ids),len(self.xpoint))): try: x,y = self[ids[i]][[1,2]] locmin = ((self.xpoint[i]-RA)**2+(self.ypoint[i]-dec)**2).argmin() fred.write('%f %f %15.12e %15.12e\n'%(x,y,RA[locmin],dec[locmin])) except: print "Coord pair %i failed"%i fred.close() iraf.ccmap(input='autocalcoords',images=self.image,lngunits='degrees', database='database',fit='rxyscale',update='yes',inter='yes') print "Recalculating..." self.calcradec() print "If happy, now run ast_by_file"
def findbettersolution(image,alsfile,datafile,source="GSC",maxmag=30,minmag=10,chicut=3): stars = CMD.star_photometry(alsfile,image,True) for star in stars.data: if star[3]>maxmag or star[3]<minmag or star[6]>chicut: star[7]=-5000 #don't find stars outside mag range datfile = pyfits.open(datafile) mydata = datfile[-1].data datfile.close() rafield,decfield = fields[source] fred=open('ccmapfile','w') for refstar in mydata: ra = refstar.field(fields[source][0]) dec= refstar.field(fields[source][1]) mystar = stars.starbyWCS(ra,dec,limit=2./3600) if type(mystar) is not type(None): fred.write("%7.2f %7.2f %10.6f %10.6f\n"%(mystar[1],mystar[2],ra,dec)) fred.close() iraf.ccmap('ccmapfile','database',images=image,xcolumn=1,ycolumn=2,lngcolumn=3, latcolumn=4,lngunits='degrees',latunits='degrees',insystem='j2000', fitgeometry='general')
def findsolution(image,alsfile,datafile,source="GSC"): stars = CMD.star_photometry(alsfile,image,False) datfile = pyfits.open(datafile) mydata=datfile[-1].data datfile.close() iraf.display(image,1) temp=iraf.pdump(alsfile,'xcen,ycen,id','yes',Stdout=1) iraf.tvmark(1,"STDIN",Stdin=temp) rafield,decfield = fields[source] ra = mydata.field(rafield) dec= mydata.field(decfield) raint = int(min(ra)) decint= int(min(dec)) print "ra offset by %i, dec by %i\n"%(raint,decint) clf() plot(ra-raint,dec-decint,'k+') print "Require 4 stars matched to make simple solution" print "Enter co-ordinates as acurately as you can:-" fred = open('ccmapfile','w') for i in range(4): idin=input("Star %i ID: "%i) mystar=stars[idin] rain=input("Star %i RA: " %i) + raint decin=input("Star %i DEC: "%i) + decint radiff = ra-rain decdiff = dec-decin radecdiff = radiff**2+decdiff**2 locmin = radecdiff.argmin() raout = ra[locmin] decout = dec[locmin] fred.write("%7.2f %7.2f %10.6f %10.6f\n"%(mystar[1],mystar[2],raout,decout)) fred.close() iraf.ccmap('ccmapfile','database',images=image,xcolumn=1,ycolumn=2,lngcolumn=3, latcolumn=4,lngunits='degrees',latunits='degrees',insystem='j2000', fitgeometry='rxyscale') findbettersolution(image,alsfile,datafile,source=source)
fw = [] for i in range(len(idcat)): _x, _y, _fw = xycoo[i].split() gg.write(_x+' '+_y+' '+str(_racat[idcat[i]-1])+' '+\ str(_decat[idcat[i]-1])+' \n') fw.append(float(_fw)) gg.close() src.updateheader(img, 0, 'Seeing', mean(fw)) gg = open('tmp.coo', 'w') for i in range(len(_racat)): gg.write(str(_racat[i]) + ' ' + str(_decat[i]) + ' \n') gg.close() iraf.ccmap('tmp.ccmap','tmp.ccdb',images=img,fitgeome='rscale',\ xcolum=1,ycolum=2,lngcolum=3,latcolumn=4,lngunit='degrees',\ update='yes',interact=False,verbose='yes') tmp = iraf.ccfind('tmp.coo','tmp.star',img,lngcolu=1,latcolu=2,\ lngunit='degrees',usewcs='yes',verbose='yes',Stderr=1) print '>>>', tmp[-2] if int(tmp[-2].split()[1]) <= 3: print "!!! Error: stars are not matched !!!" sys.exit() iraf.ccmap('tmp.star','tmp.ccdb',solution='tmp.sol',images=img,\ fitgeome='rscale',xcolum=3,ycolum=4,lngcolum=1,\ latcolumn=2,lngunit='degrees',\ update='yes',interact=False) iraf.ccmap('tmp.ccmap',
rr = ff.readlines() ff.close() gg = open('tmp.ccmap', 'w') fw = [] for i in range(len(idcat)): _rr = string.split(rr[idcat[i] - 1]) _x, _y, _fw = string.split(xycoo[i]) gg.write(_x + ' ' + _y + ' ' + _rr[0] + ' ' + _rr[1] + ' \n') fw.append(float(_fw)) gg.close() iraf.hedit(img, 'Seeing', mean(fw), add='yes', update='yes', verify='yes') iraf.ccmap('tmp.ccmap', 'tmp.ccdb', images=img, fitgeome='rscale', lngunit='degrees', update='yes', interact=False) iraf.ccfind('tmp.cat', 'tmp.star', img, lngcolu=2, latcolu=3, lngunit='degrees', usewcs='yes') iraf.ccmap('tmp.star', 'tmp.ccdb', images=img, fitgeome='general',
def lot2(input): dir = os.getcwd() line1 = dir.strip().split("/") print line1 ndir = len(line1) log = "" for i in range(ndir - 1): if i == ndir - 2: log = log + line1[i + 1] else: log = log + line1[i + 1] + "_" log = log + ".log" print "log=", log flog = open(log, "w") fitsname = input[1] if len(input) > 2: op2 = "1" else: op2 = "0" os.system("cp -f " + softwaredir + "/config.txt .") os.system("cp -f " + softwaredir + "/default.* .") os.system("cp -f " + softwaredir + "/fort.93 .") dtor = 3.1415926 / 180.0 namelist = Q.dec_dataname(fitsname) # os.system("rm -f *ty2*.cat") for line in namelist: #----------------------------------------------- fail = "n" fitsname = line.strip().split()[0] basename, ext = fitsname.strip().split(".") print "fitsname=", fitsname ccdtype = Q.getkeyword(fitsname, "CCDTYPE") if ccdtype != "OBJECT": continue telescope = Q.getkeyword(fitsname, "TERMTYPE") camera = Q.getkeyword(fitsname, "CAM_ID") telescope = telescope + camera database,xformat,yformat,scale,pt,x1s,x2s,y1s,y2s,x1p,x2p,y1p,y2p,\ epsi,angle_lowl,angle_upl=Q.deconfig(telescope) print telescope, camera print "This is a program for astrometric calibrations" # os.system("cp ~/gwac_astrometry/software/default.* .") sra = Q.getkeyword(fitsname, "RA") sdec = Q.getkeyword(fitsname, "DEC") if len(sra.split(":")) == 1: ra = float(sra) else: ra = float(Q.hms2dec(sra)) * 15.0 if len(sdec.split(":")) == 1: dec = float(sdec) else: dec = float(Q.hms2dec(sdec)) print sra, sdec, ra, dec jfovcali = "n" if telescope[0:4] == "JFoV": maglim1 = 1.0 maglim2 = 9.0 cali = telescope + ".cali" print "cali=", cali, softwaredir + "/" + cali if os.path.isfile(softwaredir + "/" + cali): os.system("cp " + softwaredir + "/" + cali + " .") print "ther is a position calibration for this camera" jfovcali = "y" ra0, dec0 = jfovcen(ra, dec, cali) ra = ra0 dec = dec0 if telescope[0:4] == "FFoV": maglim1 = 5.0 maglim2 = 9.0 lng, lat = Q.calgalactic(ra, dec) fcen = open("cen.xy", "w") xc = float(xformat) / 2.0 yc = float(yformat) / 2.0 fcen.write(str(xc) + " " + str(yc) + "\n") fcen.write("1.0 1.0 \n") fcen.write(str(xformat) + " 1\n") fcen.write(str(xformat) + " " + str(yformat) + "\n") fcen.write("1.0 " + str(yformat) + "\n") fcen.write(str(x1p) + " " + str(y1p) + "\n") fcen.write(str(x2p) + " " + str(y1p) + "\n") fcen.write(str(x2p) + " " + str(y2p) + "\n") fcen.write(str(x1p) + " " + str(y2p) + "\n") fcen.close() fov = (float(x2s) - float(x1s)) * float(scale) * 1.414 / 2.0 / 3600.0 ira = int(round(ra * math.cos(dec * dtor)) / 2) idec = int(round(dec) / 2) if idec >= 0: ty2cat = str(ira) + "+" + str( idec) + "_" + telescope[0:4] + "_tyc2.cat" ty2bcat = str(ira) + "+" + str( idec) + "_" + telescope[0:4] + "_tyc2b.cat" else: ty2cat = str(ira) + "-" + str( -idec) + "_" + telescope[0:4] + "_tyc2.cat" ty2bcat = str(ira) + "-" + str( -idec) + "_" + telescope[0:4] + "_tyc2b.cat" if telescope == "xl30cm" and not os.path.isfile("cencc.dat"): firstfits = namelist[0].strip().split()[0] print "first fits images : ", firstfits rac = 15.0 * Q.hms2dec(Q.getkeyword(firstfits, "OBJCTRA")) decc = Q.hms2dec(Q.getkeyword(firstfits, "OBJCTDEC")) print "rac decc =", rac, decc fcencc = open("cencc.dat", "w") fcencc.write("%12.6f %12.6f \n" % (rac, decc)) fcencc.close() # radius=radius/2.0 if telescope[0:4] == "JFoV": if jfovcali == "n": radius = 18.0 * 3600.0 if jfovcali == "y": radius = 8.0 * 3600.0 if telescope[0:4] == "FFoV": radius = 8.0 * 3600.0 print "radius=", radius print ty2cat, ra, dec, radius if idec >= 0: allangle = str(ira) + "+" + str( idec) + "_" + telescope[0:4] + ".aag" refcat = str(ira) + "+" + str(idec) + "_" + telescope[0:4] + ".ref" else: allangle = str(ira) + "-" + str( -idec) + "_" + telescope[0:4] + ".aag" refcat = str(ira) + "-" + str( -idec) + "_" + telescope[0:4] + ".ref" if not os.path.isfile(ty2cat) or not os.path.isfile(ty2bcat): if abs(lat) < 25: maglim2 = 8.0 Q.makedsscat1(ty2cat, ra, dec, radius, maglim1, maglim2, 600) if Q.filelength(ty2cat) < 200: Q.maketyc2cat(ty2cat, ra, dec, radius, maglim1, maglim2, 600) Q.cattrim(ty2cat, ty2bcat, maglim1, maglim2) if telescope[0:4] == "FFoV": num = 100 if telescope[0:4] == "JFoV": if jfovcali == "n": num = 400 else: num = 100 # aa="triangle1 "+telescope+" "+ty2bcat+" "+str(num) aa = "triangle1 FFoV " + ty2bcat + " " + str(num) print aa aa_out = os.popen(aa).readlines() aa = "sort triangleall.dat >aangle.dat" os.system(aa) os.system("cp aangle.dat " + allangle) os.system("cp refcat.dat " + refcat) else: os.system("cp " + allangle + " aangle.dat") os.system("cp " + refcat + " refcat.dat") #----------------------------------------------- if not os.path.isfile(basename + ".sexb"): subfits1 = "sub1.fits" subfits2 = "sub2.fits" if os.path.isfile(subfits1): os.remove(subfits1) if os.path.isfile(subfits2): os.remove(subfits2) iraf.imcopy( fitsname + "[" + str(x1s) + ":" + str(x2s) + "," + str(y1s) + ":" + str(y2s) + "]", subfits1) iraf.imcopy( fitsname + "[" + str(x1p) + ":" + str(x2p) + "," + str(y1p) + ":" + str(y2p) + "]", subfits2) if os.path.isfile("test.cat"): os.remove("test.cat") for i in range(6): sigma1 = 50.0 / (2.0**float(i)) sigma2 = 20.0 / (2.0**float(i)) print i, sigma1, sigma2 if telescope[0:4] == "JFoV": os.system( "sex " + subfits1 + " -DETECT_THRESH " + str(sigma1) + " -DETECT_MINAREA 4 -FILTER N -PHOT_APERTURES 10 -SATUR_LEVEL 70000.0" ) os.system("read3 " + basename + ".sexb1") nstar = Q.filelength(basename + ".sexb1") if i == 0: nstar0 = nstar if nstar < 50: print "nstar0=", nstar0 fail = "y" break if nstar > 200: break elif telescope[0:4] == "FFoV": print "ok" os.system( "sex " + subfits1 + " -DETECT_THRESH " + str(sigma2) + " -DETECT_MINAREA 4 -FILTER N -PHOT_APERTURES 8 -SATUR_LEVEL 60000.0" ) os.system("read3 " + basename + ".sexb1") nstar = Q.filelength(basename + ".sexb1") if i == 0: nstar0 = nstar if nstar < 20: print "nstar0=", nstar0 fail = "y" break if nstar > 200: break print "ok1" if fail == "y": continue for i in range(6): sigma1 = 100.0 / (2.0**float(i)) sigma2 = 50.0 / (2.0**float(i)) print i, sigma1, sigma2 if telescope[0:4] == "JFoV": os.system( "sex " + subfits2 + " -DETECT_THRESH " + str(sigma1) + " -DETECT_MINAREA 4 -FILTER N -PHOT_APERTURES 5 -SATUR_LEVEL 60000.0" ) print "sex " + fitsname + " -DETECT_THRESH " + str( sigma1 ) + " -DETECT_MINAREA 4 -FILTER N -PHOT_APERTURES 8 -SATUR_LEVEL 60000.0" elif telescope[0:4] == "FFoV": os.system( "sex " + subfits2 + " -DETECT_THRESH " + str(sigma2) + " -DETECT_MINAREA 4 -FILTER N -PHOT_APERTURES 6 -SATUR_LEVEL 60000.0" ) print "sex " + fitsname + " -DETECT_THRESH " + str( sigma2 ) + " -DETECT_MINAREA 4 -FILTER N -PHOT_APERTURES 8 -SATUR_LEVEL 60000.0" # if telescope!="FFoV" telescope!="FFoV": else: os.system( "sex " + fitsname + " -DETECT_THRESH 10 -PHOT_APERTURES 4 -SATUR_LEVEL 60000.0 \ -SEEING_FWHM 3 ") os.system("read3 " + basename + ".sexb") if Q.filelength(basename + ".sexb") < 10: break if Q.filelength(basename + ".sexb") > 2000: break Q.xyaddzero(basename + ".sexb1", basename + ".sexb1", x1s, y1s) Q.xyaddzero(basename + ".sexb", basename + ".sexb", x1p, y1p) # Q.sourcetrim(basename+".sexb1",basename+".xy" ,x1s, x2s, y1s, y2s) # Q.sourcetrim(basename+".sexb",basename+".xy" ,x1s, x2s, y1s, y2s) if not os.path.isfile(basename + ".sexb1"): fail = "y" nstar = 0 else: nstar0 = Q.filelength(basename + ".sexb1") if nstar0 < 20: fail = "y" if fail == "y": print "It is fail to process the image: few star in the image" flog.write(fitsname + " fail due to the few stars in the image.\n") flog.write("%s %5.5d fail due to the few stars in the image \n" % (fitsname, nstar0)) continue aa="xyfileter "+basename+".xy "+basename+".xy "+str(x1s)+" "+str(x2s)+\ " "+str(y1s)+" "+str(y2s ) # os.system(aa) Q.filetrim(basename + ".sexb1", basename + ".xy", 100) if os.path.isfile(basename + ".xycc"): os.remove(basename + ".xycc") aa = "tmatch1 " + basename + ".xy " + basename + ".xycc " + str( scale) + " " + str(angle_lowl) + " " + str(angle_upl) + " " + str( epsi) + " " + str(pt * 3.0) if op2 == "0": if abs(lat) < 25: aa_out = os.popen(aa + " 10").readlines() aa_out = os.popen(aa + " 20").readlines() print aa + " 20" if not os.path.isfile(basename + ".xycc") or Q.filelength(basename + ".xycc") < 5: if op2 == "0": if abs(lat) < 25: aa_out = os.popen(aa + " 15").readlines() aa_out = os.popen(aa + " 30").readlines() print aa + " 30" if not os.path.isfile(basename + ".xycc") or Q.filelength(basename + ".xycc") < 5: if op2 == "0": aa_out = os.popen(aa + " 50").readlines() print aa + " 50" if not os.path.isfile(basename + ".xycc") or Q.filelength(basename + ".xycc") < 5: aa="op2 "+basename+".xy "+basename+".xycc "+database+" "\ +str(scale)+" "+str(angle_lowl)+" "+str(angle_upl)+" "+str(epsi)+" "+str(pt*1.0) print aa + " 10" os.system(aa + " 10") if not os.path.isfile(basename + ".xycc") or Q.filelength(basename + ".xycc") < 5: os.system(aa + " 15") if not os.path.isfile(basename + ".xycc") or Q.filelength(basename + ".xycc") < 5: os.system(aa + " 20") print aa + " 20" if not os.path.isfile(basename + ".xycc") or Q.filelength(basename + ".xycc") < 5: os.system(aa + " 30") print aa + " 30" if not os.path.isfile(basename + ".xycc") or Q.filelength( basename + ".xycc") < 5: os.system(aa + " 40") print aa + " 40" if not os.path.isfile(basename + ".xycc") or Q.filelength(basename + ".xycc") < 5: continue if os.path.isfile(basename + ".xycc") and Q.filelength(basename + ".xycc") >= 5: if Q.filelength(basename + ".xycc") > 20: if os.path.isfile(basename + ".cc"): os.remove(basename + ".cc") iraf.ccmap(basename+".xycc",basename+".cc",solutio="first",\ images="",\ xcolumn=1, ycolumn=2, lngcolu=3, latcolu=4,\ xmin=x1s, ymin=y1s, xmax=x2s, ymax=y2s,lngunit="degrees",\ insystem="J2000.0", refpoint="coords",\ fitgeometry="general",function="legendre",\ xxorder=3, xyorder=3, xxterms="half",yxorder=3,yyorder=3,\ yxterms="half",maxiter=3,reject=2.0,\ latunit="degrees",inter="no", verbose="yes", update="yes") if Q.filelength(basename + ".xycc") <= 20: if os.path.isfile(basename + ".cc"): os.remove(basename + ".cc") iraf.ccmap(basename+".xycc",basename+".cc",solutio="first",\ images="",\ xcolumn=1, ycolumn=2, lngcolu=3, latcolu=4,\ xmin=x1s, ymin=y1s, xmax=x2s, ymax=y2s,lngunit="degrees",\ fitgeometry="general",function="legendre",\ insystem="J2000.0", refpoint="coords",\ xxorder=2, xyorder=2, xxterms="none",yxorder=2,yyorder=2,\ yxterms="none",maxiter=3,reject=2.0,\ latunit="degrees",inter="no", verbose="yes", update="yes") if os.path.isfile(basename + ".cencc"): os.remove(basename + ".cencc") iraf.cctran(input="cen.xy",output=basename+".cencc",database=basename+".cc",\ solutions="first",geometry="geometric",forward="yes",\ xcolumn=1,ycolumn=2,\ lngunit="degrees", latunit="degrees",\ lngformat="%12.6f",latformat="%12.6f") # os.system("getcat "+ basename+".cencc "+basename+".catcc 6.8") #--------------redo ccmap to project at the center of fov xirms = Q.readacc(basename + ".cc", "xirms") etarms = Q.readacc(basename + ".cc", "etarms") if telescope[0:4] == "JFoV": if xirms > 30 or etarms > 30: continue if telescope[0:4] == "FFoV": if xirms > 80 or etarms > 80: continue fcencc = open(basename + ".cencc", 'r') fcencctmp = fcencc.readline().strip().split() ra1 = float(fcencctmp[0]) dec1 = float(fcencctmp[1]) fcencc.close() ira1 = int(round(ra1 * math.cos(dec1 * dtor)) / 2) idec1 = int(round(dec1) / 2) print "new cencc:", ra1, dec1 lng, lat = Q.calgalactic(ra1, dec1) print "galactic coords:", lng, lat if os.path.isfile(basename + ".cc"): os.remove(basename + ".cc") if Q.filelength(basename + ".xycc") > 20: if os.path.isfile(basename + ".cc"): os.remove(basename + ".cc") iraf.ccmap(basename+".xycc",basename+".cc",solutio="first",\ images="",\ xcolumn=1, ycolumn=2, lngcolu=3, latcolu=4,\ xmin=x1s, ymin=y1s, xmax=x2s, ymax=y2s,lngunit="degrees",\ fitgeometry="general",function="legendre",\ insystem="J2000.0", refpoint="user",lngref=ra1,latref=dec1,\ xxorder=3, xyorder=3, xxterms="half",yxorder=3,yyorder=3,\ yxterms="half",maxiter=2,\ latunit="degrees",inter="no", verbose="yes", update="yes") if Q.filelength(basename + ".xycc") <= 20: if os.path.isfile(basename + ".cc"): os.remove(basename + ".cc") iraf.ccmap(basename+".xycc",basename+".cc",solutio="first",\ images="",\ xcolumn=1, ycolumn=2, lngcolu=3, latcolu=4,\ xmin=x1s, ymin=y1s, xmax=x2s, ymax=y2s,lngunit="degrees",\ fitgeometry="general",function="legendre",\ insystem="J2000.0", refpoint="user",lngref=ra1,latref=dec1,\ xxorder=2, xyorder=2, xxterms="none",yxorder=2,yyorder=2,\ yxterms="none",maxiter=2,\ latunit="degrees",inter="no", verbose="yes", update="yes") #------------------------------------- if telescope[0:4] == "JFoV": maglim1 = 8 maglim2 = 11 radius1 = 9.9 * 3600.0 if idec1 >= 0: JFoV_cat = str(ira1) + "+" + str(idec1) + "_JFoV_tyc2c.cat" else: JFoV_cat = str(ira1) + "-" + str( -idec1) + "_JFoV_tyc2c.cat" if not os.path.isfile(JFoV_cat): lng, lat = Q.calgalactic(ra1, dec1) if abs(lat) < 25: maglim2 = 10.0 Q.makedsscat1(JFoV_cat, ra1, dec1, radius1, maglim1, maglim2, 2000) if Q.filelength(JFoV_cat) < 500: Q.maketyc2cat(JFoV_cat, ra1, dec1, radius1, maglim1, maglim2, 2000) # Q.cattrim(JFoV_cat,JFoV_cat,maglim1,maglim2) os.system("cp " + JFoV_cat + " " + basename + ".catcc") else: print "FFoV:" maglim1 = 6 maglim2 = 11 radius1 = 19.0 * 3600.0 if idec1 >= 0: FFoV_cat = str(ira1) + "+" + str(idec1) + "_FFoV_tyc2c.cat" else: FFoV_cat = str(ira1) + "-" + str( -idec1) + "_FFoV_tyc2c.cat" if not os.path.isfile(FFoV_cat): Q.maketyc2cat(FFoV_cat, ra1, dec1, radius1, maglim1, maglim2, 2000) if Q.filelength(FFoV_cat) < 500: maglim1 = 6.0 maglim2 = 10.0 Q.makedsscat1(FFoV_cat, ra1, dec1, radius1, maglim1, maglim2, 1000) Q.cattrim(FFoV_cat, FFoV_cat, maglim1, maglim2) os.system("cp " + FFoV_cat + " " + basename + ".catcc") # Q.filetrim(dsscat,basename+".catcc",800) #--------------first match with stars less than 100---------------------------- # os.system("cp "+basename+".catcc "+basename+".catcc1") Q.filetrim(basename + ".catcc", basename + ".catcc1", 600) if os.path.isfile(basename + ".catxy1"): os.remove(basename + ".catxy1") iraf.cctran(input=basename+".catcc1",output=basename+".catxy1",database=basename+".cc",\ solutions="first",geometry="geometric",forward="no",\ xcolumn=1,ycolumn=2,\ lngunit="degrees", latunit="degrees",\ lngformat="%12.6f",latformat="%12.6f") # Q.sortfile(basename+".catxy",3,0) # Q.sortfilie(basename+".catcc",3,0) print "x1p,x2p,y1p,y2p", x1p, x2p, y1p, y2p os.system("cp " + basename + ".catxy tmp.catxy") Q.sourcestrim(basename + ".catxy1", basename + ".catcc1", x1p, x2p, y1p, y2p) Q.sourcetrim(basename + ".sexb", basename + ".bsxy", x1p, x2p, y1p, y2p) Q.filetrim(basename + ".bsxy", basename + ".bsxy", 600) aa="xyfileter "+basename+".bsxy "+basename+".bsxy1 "+str(x1p)+" "+str(x2p)+\ " "+str(y1p)+" "+str(y2p ) os.system(aa) # # Q.filetrim(basename+".sexb",basename+".bsxy",1200) # last term in aa is cross-error radius, change to 10" error1 = Q.readacc(basename + ".cc", "xirms") error2 = Q.readacc(basename + ".cc", "etarms") error = ((error1 * 2.0 + error2**2.0)**0.5) / scale if telescope[0:4] == "FFoV": error = 30 if telescope[0:4] == "JFoV": error = 30 # if telescope[0:4]=="JFoV": error=error*5.0 aa="crossxy "+basename+".catxy1 "+basename+".bsxy1 "\ +basename+".catcc1 "+basename+".axycc "+str(error) print aa os.system(aa) naxycc = Q.filelength(basename + ".axycc") print "number of axycc:", naxycc # if naxycc>500: Q.filetrim(basename+".axycc",basename+".axycc",500) aa="accfileter "+basename+".axycc "+basename+".axycc1 "+str(x1p)+" "+str(x2p)+\ " "+str(y1p)+" "+str(y2p) os.system(aa) Q.ccmapfit(basename + ".axycc1", basename + ".acc1", x1p, x2p, y1p, y2p, ra1, dec1) #---------------second fitting with stars around 1000------------------------ os.system("cp " + basename + ".catcc " + basename + ".catcc2") if os.path.isfile(basename + ".catxy"): os.remove(basename + ".catxy") iraf.cctran(input=basename+".catcc2",output=basename+".catxy",database=basename+".acc1",\ solutions="first",geometry="geometric",forward="no",\ xcolumn=1,ycolumn=2,\ lngunit="degrees", latunit="degrees",\ lngformat="%12.6f",latformat="%12.6f") # Q.sourcestrim(basename+".catxy",basename+".catcc2",x1p,x2p,y1p,y2p) Q.sourcetrim(basename + ".sexb", basename + ".bsxy", x1p, x2p, y1p, y2p) aa="xyfileter "+basename+".bsxy "+basename+".bsxy "+str(x1p)+" "+str(x2p)+\ " "+str(y1p)+" "+str(y2p ) os.system(aa) error1 = Q.readacc(basename + ".acc1", "xirms") error2 = Q.readacc(basename + ".acc1", "etarms") error = ((error1 * 2.0 + error2**2.0)**0.5) / scale if abs(lat) < 25: if telescope[0:4] == "FFoV": error = 5.0 if telescope[0:4] == "JFoV": error = 5.0 else: if telescope[0:4] == "FFoV": error = 5.0 if telescope[0:4] == "JFoV": error = 5.0 aa="crossxy "+basename+".catxy "+basename+".bsxy "\ +basename+".catcc2 "+basename+".axycc "+str(error) print aa os.system(aa) aa="accfileter "+basename+".axycc "+basename+".axycc "+str(x1p)+" "+str(x2p)+\ " "+str(y1p)+" "+str(y2p) os.system(aa) Q.ccmapfit(basename + ".axycc", basename + ".acc", x1p, x2p, y1p, y2p, ra1, dec1) iraf.cctran(input="cen.xy",output=basename+".cencc1",database=basename+".acc",\ solutions="first",geometry="geometric",forward="yes",\ xcolumn=1,ycolumn=2,\ lngunit="degrees", latunit="degrees",\ lngformat="%12.6f",latformat="%12.6f") xirms = Q.readacc(basename + ".acc", "xirms") etarms = Q.readacc(basename + ".acc", "etarms") flog.write("%s %5.5d %6.2f %6.2f \n" % (fitsname, nstar0, xirms, etarms)) flog.close()
def register_module(img, _system, coordinatelist, interactive, logincl, _filter): from snoopy2 import src import snoopy2 import string, os # logincl=src.open_program() from pyraf import iraf iraf.astcat(_doprint=0) iraf.imcoords(_doprint=0) iraf.set(stdimage='imt1024') iraf.tv.rimexam.backgrou = 'yes' subdirectory = ['optical/', 'infrared/', 'sloan/'] iraf.delete(coordinatelist + ".tv", verify='no') iraf.delete(coordinatelist + "_templ.coo", verify='no') iraf.delete("_templ.*", verify='no') try: dir_system = subdirectory[_system] iraf.fields('home$coordinate_std/' + dir_system + coordinatelist + '.list', '2,3,1', Stdout=coordinatelist + '.tv') iraf.fields('home$coordinate_std/' + dir_system + coordinatelist + '.list', '1', Stdout='_templ.coo') iraf.wcsctran(coordinatelist + '.tv', '_templ.coo2', 'home$coordinate_std/' + dir_system + coordinatelist + '_templ.fits', inwcs='world', units='degrees degrees', outwcs='logical', columns='1 2', formats='%10.1f %10.1f') a = iraf.fields('_templ.coo', '1', Stdout=1) b = iraf.fields('_templ.coo2', '1,2', Stdout=1)[2:] ff = open(coordinatelist + '_templ.coo', 'w') for i in range(len(a)): ff.write(b[i] + '\t' + a[i] + ' \n') ff.close() if _system == 0 or _system == 2: standard = iraf.fields('home$coordinate_std/' + dir_system + coordinatelist + '.list', '1,4,5,6,7,8', Stdout=1) else: standard = iraf.fields('home$coordinate_std/' + dir_system + coordinatelist + '.list', '1,4,5,6', Stdout=1) except Exception as e: print e print "WARNING: no coordinate " + coordinatelist + " file found in " + snoopy2.__path__[ 0] + '/coordinate_std/' + dir_system + ' !!! ' src.close_program(logincl) stars = [] for i in standard: nome = string.split(i) stars.append(nome[0]) # _filter='XXX' src.delete("tmp." + img + ".coo") iraf.wcsctran(coordinatelist + '.tv', 'tmp.' + img + '.coo', img, inwcs='world', units='degrees degrees', outwcs='logical', columns='1 2', formats='%10.1f %10.1f') if interactive: print '######### Select FRAME TILE on your DS9 !!!!!' _z1, _z2, goon = src.display_image( snoopy2.__path__[0] + '/coordinate_std/' + dir_system + coordinatelist + '_templ.fits', 2, '', '', False) if not goon: src.close_program(logincl) iraf.tvmark(2, coordinatelist + '_templ.coo', mark="circle", number='no', label='yes', radii=20, nxoffse=15, nyoffse=15, color=214, txsize=4) _z1, _z2, goon = src.display_image(img, 1, '', '', False) if not goon: src.close_program(logincl) iraf.tvmark(1, 'tmp.' + img + '.coo', mark="circle", number='no', label='yes', radii=20, nxoffse=15, nyoffse=15, color=205, txsize=2) answ = raw_input( 'is the astrometry of the field good ? \n [y/n] ? [y] ') if not answ: answ = 'y' if answ == 'n': try: src.delete('tmp.' + img + '.coo') src.delete('tmp.ccdb') iraf.ccmap('_first.ccmap', 'tmp.ccdb', images=img, fitgeome='rscale', lngunit='degrees', update='yes', interact=False) iraf.wcsctran('_first_image.tv', 'tmp.' + img + '.coo', img, inwcs='world', units='degrees degrees', outwcs='logical', columns='1 2', formats='%10.1f %10.1f') iraf.tvmark(1, 'tmp.' + img + '.coo', mark="circle", number='no', label='yes', radii=20, nxoffse=15, nyoffse=15, color=206, txsize=4) answ = raw_input( 'AND NOW, is the astrometry of the field good [y/n] ? [y] ' ) if not answ: answ = 'y' except: pass while answ == 'n': _z1, _z2, goon = src.display_image(img, 1, '', '', False) if not goon: src.close_program(logincl) print '>> Identify (minimum 2, preferably 3) reference stars (mark with "a")' iraf.delete('tmp.coo', verify='no') iraf.imexamine(img, 1, logfile='tmp.coo', keeplog='yes') iraf.tvmark(1, 'tmp.coo', mark="circle", number='yes', label='no', radii=15, nxoffse=15, nyoffse=15, color=214, txsize=4) xycoo = iraf.fields('tmp.coo', '1,2,13', Stdout=1) print '>> Identify reference stars' idcat = [] for i in range(len(xycoo)): idcat.append(raw_input('Star ' + str(i + 1) + '= ? ')) ff = open(coordinatelist + '.tv', 'r') rr = ff.readlines() ff.close() gg = open('tmp.ccmap', 'w') fw = [] for i in range(len(idcat)): idpos = stars.index(idcat[i]) _rr = string.split(rr[idpos]) _x, _y, _fw = string.split(xycoo[i]) gg.write(_x + ' ' + _y + ' ' + _rr[0] + ' ' + _rr[1] + ' \n') fw.append(float(_fw)) gg.close() iraf.delete('_first_image.tv', verify='no') iraf.delete('_first.ccmap', verify='no') os.system('cp ' + coordinatelist + '.tv _first_image.tv') os.system('cp tmp.ccmap _first.ccmap') iraf.ccmap('tmp.ccmap', 'tmp.ccdb', images=img, fitgeome='rscale', lngunit='degrees', update='yes', interact=False) _z1, _z2, goon = src.display_image(img, 1, '', '', False) if not goon: src.close_program(logincl) iraf.delete('tmp.' + img + '.coo', verify='no') iraf.wcsctran(coordinatelist + '.tv', 'tmp.' + img + '.coo', img, inwcs='world', units='degrees degrees', outwcs='logical', columns='1 2', formats='%10.1f %10.1f') iraf.tvmark(1, 'tmp.' + img + '.coo', mark="circle", number='yes', label='no', radii=20, nxoffse=15, nyoffse=15, color=205, txsize=4) iraf.delete("tmp.ccmap", verify='no') iraf.delete("tmp.coo", verify='no') iraf.delete("tmp.ccdb", verify='no') answ = raw_input( 'is the astrometry of the field good [y/n] ? [y]') if not answ: answ = 'y' iraf.delete("tmp.star", verify='no') iraf.ccfind('home$coordinate_std/' + dir_system + coordinatelist + '.list', 'tmp.star', img, lngcolu=2, latcolu=3, lngunit='degrees', usewcs='yes') iraf.ccmap('tmp.star', 'tmp.ccdb', images=img, fitgeome='rscale', xcolum=9, ycolum=10, lngcolum=2, latcolumn=3, lngunit='degrees', update='yes', interact=False) iraf.delete('tmp.' + img + '.coo', verify='no') iraf.wcsctran(coordinatelist + '.tv', 'tmp.' + img + '.coo', img, inwcs='world', units='degrees degrees', outwcs='logical', columns='1 2', formats='%10.1f %10.1f') iraf.delete("tmp.ccdb", verify='no') iraf.delete("tmp.star", verify='no') iraf.delete("tmp.coo", verify='no') return stars, 'tmp.' + img + '.coo'