def runall(prefixes,cat): for prefix in prefixes: images=glob.glob(prefix) iraf.imgets(images[0],'FILTER') filter=str(iraf.imgets.value) for im in images: runsextractor(im) t=im.split('.') if cat < 0.1: out='sdssmatch-'+str(t[0]) refcat='sdsscoords.dat' s='cat '+out+' >> sdssmatch'+filter plotsdsspos(im) if cat > .1: out='2massmatch-'+str(t[0]) refcat='2masscoords.dat' s='cat '+out+' >> 2massmatch'+filter plot2masspos(im) #iraf.xyxymatch(input='testxy.cat',reference='sdsscoords.dat',output=out,tolerance=20.,refpoints='refpoints',interactive='yes') iraf.xyxymatch(input='testxy.cat',reference=refcat,output=out,tolerance=10.,refpoints='refpoints',interactive='no') os.system(s) infile='sdssmatch'+filter infile='2massmatch'+filter iraf.geomap(input=infile,database='PiscesBok',transform=filter,xmin=1.,xmax=1024,ymin=1.,ymax=1024.)
def getpositions(ximage, yimage, isoarea, im): dmin = 30. #minimum distance to object + sqrt(isoarea) iraf.imgets(image=im, param='naxis1') #get RA of image t = float(iraf.imgets.value) xmax = t xcenter = t / 2. iraf.imgets(image=im, param='naxis2') #get RA of image t = float(iraf.imgets.value) ymax = t ycenter = t / 2. xpos = [] ypos = [] da = N.sqrt(isoarea) d = N.zeros(len(ximage), 'f') #print len(d) i = 0 while i < npoints: xtemp = random.uniform(0, 1) * xmax ytemp = random.uniform(0, 1) * ymax dcenter = N.sqrt((xtemp - xcenter)**2 + (ytemp - ycenter)**2) if (dcenter < 500.): j = 0 d = N.sqrt((ximage - xtemp)**2 + (yimage - ytemp)**2) - da #for j in range(len(ximage)): #print j,len(ximage),len(yimage),len(da),len(d) #d[j] = N.sqrt((ximage[j]-xtemp)**2+(yimage[j]-ytemp)**2)-da[j] if (min(d) > dmin): xpos.append(xtemp) ypos.append(ytemp) i = i + 1 xpos = N.array(xpos, 'f') ypos = N.array(ypos, 'f') return xpos, ypos
def getpositionsLCS(ximage,yimage,isoarea,im,coverage_map): iraf.imgets(image=im,param='naxis1')#get RA of image t=float(iraf.imgets.value) xmax=t xcenter=t/2. iraf.imgets(image=im,param='naxis2')#get RA of image t=float(iraf.imgets.value) ymax=t ycenter=t/2. xpos=[] ypos=[] da = N.sqrt(isoarea) d = N.zeros(len(ximage),'f') #print len(d) i=0 covimage=pyfits.open(coverage_map) cov_data=(covimage[0].data) covimage.close() while i < npoints: xtemp=random.uniform(0,1)*xmax ytemp=random.uniform(0,1)*ymax # check coverage map to make sure point is on science area # coverage map values > 6 are ok if cov_data[ytemp,xtemp] > 6: d = N.sqrt((ximage-xtemp)**2+(yimage-ytemp)**2) if (min(d) > dmin): xpos.append(xtemp) ypos.append(ytemp) i=i+1 #print 'found a good place to measure sky!',i,npoints xpos=N.array(xpos,'f') ypos=N.array(ypos,'f') return xpos,ypos
def rotate24(): for i in range(len(images24)): #for i in range(1): iraf.imgets( image=images24[i], param='CROTA2') #[deg] Orientation of axis 2 (W of N, +=CW) print iraf.imgets.value rot24 = float(iraf.imgets.value) iraf.imgets( image=images[i], param='ORIENTAT') #position angle of image y axis (deg. e of n) print iraf.imgets.value rotacs = float(iraf.imgets.value) angle = -1 * rot24 - rotacs outimage = rimages24[i] iraf.rotate(input=images24[i], output=outimage, rotation=angle)
def geton24imageflag(self): iraf.imgets(image=self.image24,param='CD1_1')#get x plate scale on rotated image #print iraf.imgets.value xplate=abs(float(iraf.imgets.value))#deg/pixel dpix=deltaCutout/3600./xplate/2. # requires a 50 arcsec buffer b/w center of galaxy and edge of image iraf.imgets(image=self.image24,param='naxis1')#get x value corresponding to RA xpixmax=(int(iraf.imgets.value))#deg/pixel iraf.imgets(image=self.image24,param='naxis2')#get x value corresponding to RA ypixmax=(int(iraf.imgets.value))#deg/pixel # write RA and Dec to ascii file t = atpy.Table() t.add_column('RA',self.ndat.RA) t.add_column('DEC',self.ndat.DEC) outfile=self.nsadir+self.prefix+'_RADEC.txt' out1=open(outfile,'w') for i in range(len(self.ndat.RA)): s='%12.8f %12.8f \n'%(self.ndat.RA[i],self.ndat.DEC[i]) out1.write(s) out1.close() # transform RA and Dec to pixels using wcsctran print 'transforming 24um coords' outcoords=self.nsadir+str(self.prefix)+'xy24.txt' if os.path.exists(outcoords): os.remove(outcoords) iraf.imcoords.wcsctran(image=self.image24,input=outfile,output=outcoords,inwcs='world',outwcs='logical',verbose='no') # read in pixel coordinates self.mipscoords=atpy.Table(outcoords,type='ascii') x=self.mipscoords['col1'] y=self.mipscoords['col2'] self.On24ImageFlag= (x > dpix) & (x < (xpixmax-dpix)) & (y > dpix) & (y < (ypixmax-dpix)) print self.prefix,': # on 24um image = ',sum(self.On24ImageFlag)
def makecutouts(): cutouts = [] for i in range(len(images)): #for i in range(1): #print i,prefix,prefix[i] outcoords = str(prefix[i]) + '.xy' iraf.imgets(image=images[i], param='CD2_1') #get x value corresponding to RA xplate = abs(float(iraf.imgets.value)) #deg/pixel dpix = delta / 3600. / xplate / 2. print dpix #delta=100. infile = open(outcoords, 'r') for line in infile: if line.find('#') > -1: continue if len(line) < 2: continue x, y, id = line.split() x = float(x) y = float(y) xmin = int(round(x - dpix)) xmax = int(round(x + dpix)) ymin = int(round(y - dpix)) ymax = int(round(y + dpix)) s = images[i] + '[%i:%i,%i:%i]' % (xmin, xmax, ymin, ymax) print s #print ra[i],dec[i] outim = id + 'cutout.fits' print outim iraf.imcopy(s, outim) cutouts.append(outim) infile.close() return cutouts
def makecutouts24(delta): cutouts24 = [] images24 = rimages24 for i in range(len(images24)): #for i in range(1): #print i,prefix,prefix[i] outcoords = str(prefix[i]) + '.xy24' #iraf.imgets(image=images24[i],param='CDELT1')#get x plate scale iraf.imgets(image=images24[i], param='CD2_1') #get x plate scale on rotated image print iraf.imgets.value xplate = abs(float(iraf.imgets.value)) #deg/pixel dpix = delta / 3600. / xplate / 2. iraf.imgets(image=images24[i], param='naxis1') #get x value corresponding to RA xpixmax = (int(iraf.imgets.value)) #deg/pixel iraf.imgets(image=images24[i], param='naxis2') #get x value corresponding to RA ypixmax = (int(iraf.imgets.value)) #deg/pixel infile = open(outcoords, 'r') #print outcoords for line in infile: #print images24[i],line,outcoords if line.find('#') > -1: continue if len(line) < 2: continue x, y, id = line.split() x = float(x) y = float(y) #delta=100. xmin = int(round(x - dpix)) xmax = int(round(x + dpix)) ymin = int(round(y - dpix)) ymax = int(round(y + dpix)) if xmin < 1: xmin = 1 if ymin < 1: ymin = 1 if xmax > xpixmax: xmax = xpixmax if ymax > ypixmax: ymax = ypixmax s = images24[i] + '[%i:%i,%i:%i]' % (xmin, xmax, ymin, ymax) print s #print ra[i],dec[i] outim = id + 'cutout24.fits' print outim iraf.imcopy(s, outim) cutouts24.append(outim) infile.close() return cutouts24
def imgets(img,field): iraf.flprcache() iraf.flprcache() iraf.imgets(img,field) return iraf.imgets.value
#! /usr/bin/env python from pylab import * from pyraf import iraf import glob files = glob.glob('*.fits') for file in files: iraf.imgets(image=file, param='FILENAME') #get RA of image originalName = iraf.imgets.value #print file, originalName iraf.imrename(file, originalName) print "All Done!"
photometry.correct_coordinates([corrbyhand[i]["filename_incl_path"]], radius=10., twomassmag = 17.) photometry.correct_coordinates([corrbyhand[i]["filename_incl_path"]], radius=10., twomassmag = 17.) iraf.centerpars.cbox = 9. iraf.centerpars.maxshift = 1. # apply the coordinate transformations done for the individual images also to their respective masks. This is not strictly necessary, because the mask trimming and dividing is done on a pixel-by-pixel basis, but it's nicer this way when you want to look at the mask in ds9 and compare things by eye. trimpath = input_info.resultfolder + '*YSO*/*_wcs_unnormed.fits' trimlist = glob.glob(trimpath) trimlist.sort() masklist = deepcopy(trimlist) for i in np.arange(0, len(masklist)): masklist[i] = masklist[i].replace('_wcs_unnormed.fits', '_coadd.weight.fits') for f in masklist: image = f.replace('_coadd.weight.fits','_wcs_unnormed.fits') for headerkeyword in ['RADECSYS', 'CTYPE1', 'CRVAL1', 'CRPIX1', 'CD1_1', 'CD1_2', 'CTYPE2', 'CRVAL2', 'CRPIX2', 'CD2_1', 'CD2_2']: iraf.imgets(image, headerkeyword) iraf.hedit(images=f, fields=headerkeyword, value=iraf.imgets.value, verify="no") # now trim the images so that only parts with good exposure are retained: trimpath = input_info.resultfolder + '*YSO*/*_wcs_unnormed.fits' trimlist = glob.glob(trimpath) trimlist.sort() masklist = deepcopy(trimlist) for i in np.arange(0, len(masklist)): masklist[i] = masklist[i].replace('_wcs_unnormed.fits', '_coadd.weight.fits') print "trimming..." for i in np.arange(0, len(masklist)): #for i in np.arange(0, 1):
"Is everything ok? Press 'enter' to continue, 'e' to exit.\t") # option to exit if getout == 'e' or getout == 'E': print "\nexiting then... Bye!\n" raise SystemExit # preparing header fields (input of imagetyp, exptime/darktime) print "> preparing the image headers" #l.write("\n> preparing the image headers") unlearn(iraf.ccdhedit) iraf.ccdhedit("Dark*.fit", parameter="imagetyp", value="dark") iraf.ccdhedit("Flat*.fit", parameter="imagetyp", value="flat") iraf.ccdhedit(rname + "_*.fit", parameter="imagetyp", value="object") for im in glob.glob('*.fit*'): unlearn(iraf.imgets) iraf.imgets(im, param="inttime") iraf.hedit(im, fields="exptime", value=iraf.imgets.value, add="no", addonly="yes", delete="no", verify="no", show="no", update="yes") for im in glob.glob("Dark*.fit"): unlearn(iraf.imgets) iraf.imgets(im, param="inttime") iraf.hedit(im, fields="darktime", value=iraf.imgets.value,
def autoalign(images): ra = [] dec = [] xcenter = [] ycenter = [] dx = [] dy = [] xpscale = [] ypscale = [] for im in images: iraf.imgets(image=im, param='CRVAL1') #get RA of image in deg t = iraf.imgets.value ra.append(float(t)) iraf.imgets(image=im, param='CRPIX1') #get pix of RA t = iraf.imgets.value xcenter.append(float(t)) iraf.imgets(image=im, param='CD1_1') #get pix of RA t = iraf.imgets.value xpscale.append(float(t)) iraf.imgets(image=im, param='CRVAL2') #get RA of image t = iraf.imgets.value dec.append(float(t)) iraf.imgets(image=im, param='CRPIX2') #get RA of image t = iraf.imgets.value ycenter.append(float(t)) iraf.imgets(image=im, param='CD2_2') #get RA of image t = iraf.imgets.value ypscale.append(float(t)) dra = (ra - ra[0]) * N.cos( N.pi / 180. * dec) #correct delta ra for cos declination ddec = (dec - dec[0]) dx = dra / xpscale + (xcenter - xcenter[0]) dy = dra / ypscale + (ycenter - ycenter[0]) xshift = dx yshift = -1. * dy outfile = open('shifts', 'w') for i in range(len(xshift)): s = '%8.3f %8.3f \n' % (xshift[i], yshift[i]) outfile.write(s) outfile.close()
def writegmoscat(gmosim): iraf.imgets(image=gmosim, param='i_naxis1') t = iraf.imgets.value gxmax = (float(t)) iraf.imgets(image=gmosim, param='i_naxis2') t = iraf.imgets.value gymax = (float(t)) gxmin = 1 gymin = 1 outfile2 = prefix + '-GMOSxy.dat' #file containing x and y pixels values on gmos image gmosx = [] gmosy = [] input = open(outfile2, 'r') for line in input: t = line.split() gmosx.append(float(t[0])) gmosy.append(float(t[1])) input.close() gmosx = N.array(gmosx, 'f') gmosy = N.array(gmosy, 'f') #get gmos ra and dec positions from x,y pixels values radecfile = prefix + '-GMOSradec.dat' iraf.wcsctran(outfile2, radecfile, image=gmosim, inwcs='physical', outwcs='world', columns='1 2', verbose='no') infile = open(radecfile, 'r') gmosra = [] gmosdec = [] for line in infile: if line.find('#') > -1: continue t = line.split() gmosra.append(float(t[0])) gmosdec.append(float(t[1])) infile.close() gmosra = N.array(gmosra, 'f') gmosdec = N.array(gmosdec, 'f') s = prefix + '.reg' dsfile = open(s, 'w') s = "global color=green font='helvetica 10 normal' select=1 highlite=1 edit=1 move=1 delete=1 include=1 fixed=0 source\n" dsfile.write(s) s = "fk5 \n" dsfile.write(s) infile = '/Users/rfinn/clusters/spitzer/Mastertables/' + prefix + 'mastertable24.dat' gmoscat = prefix + 'mastertable24GMOS.dat' input = open(infile, 'r') output = open(gmoscat, 'w') i = 0 for line in input: if line.find('#') > -1: #skip lines with '#' in them output.write(line) continue if line.find('\\') > -1: #skip lines with '#' in them output.write(line) continue if line.find('|') > -1: #skip lines with '#' in them output.write(line) continue if gmosx[i] < 1.: print "bad x value: ", gmosx[i], 1, gxmax i = i + 1 continue if gmosx[i] > gxmax: print "bad x value: ", gmosx[i], 1, gxmax i = i + 1 continue if gmosy[i] < 1.: print "bad y value (too small): ", i, gmosy[i], 1, gymax i = i + 1 continue if gmosy[i] > gymax: print "bad y value: ", i, gmosy[i], 1, gymax i = i + 1 continue line = line[0:(len(line) - 1)] #get rid of \n at end of line s = " %10.3f %10.3f %13.8f %13.8f \n" % (gmosx[i], gmosy[i], gmosra[i], gmosdec[i]) outline = line + s #append gmos x and y pixels to the end of the line output.write(outline) string1 = "circle(%12.8f, %12.8f, 3\") \n" % (gmosra[i], gmosdec[i]) dsfile.write(string1) i = i + 1 input.close() dsfile.close()
def imgets(img, field): iraf.flprcache() iraf.flprcache() iraf.imgets(img, field) return iraf.imgets.value
def run(funcname,outname): # output as SExtractor format #iraf.ls('obj*_out.fits',Stdout='tmplist') outlist = glob.glob('obj*_out.fits') f = open('tmplist','wb') for t in outlist: f.write('%s\n' % t) f.close() if funcname=="sersic": f2=open(outname,"w") colnames = ['OBJNUM','XCENT','XCENTERR','YCENT','YCENTERR','MAG', 'MAGERR','RE','REERR','N','NERR','AR','ARERR','PA','PAERR', 'CHISQ','CHISQNU'] writeheader(f2,colnames) #if funcname=="devauc": # f2=open(outname,"w") # colnames=['#OBJNUM','XCENT1','YCENT1','MAG1','MAG1ERR','RE1','RE1ERR', # 'AR1','AR1ERR','PA1','PA1ERR','XCENT2','YCENT2','MAG2', # 'MAG2ERR','RS2','RS2ERR','AR2','AR2ERR','PA2','PA2ERR' # 'CHISQ','CHISQNU'] # writeheader(f2,colnames) f=open('tmplist') objnum = [] xcent = [] xcenterr = [] ycent = [] ycenterr = [] mag = [] magerr = [] re = [] reerr = [] sersicn = [] sersicnerr = [] axratio = [] axratioerr = [] pa = [] paerr = [] chisq = [] chisqnu = [] for line in f.readlines(): id = line.split()[0] imgroot=id+"[2]" comp1=funcname if comp1=="sersic": iraf.imgets.saveParList(filename="imgets.par") # figure out how many components there are n = 1 ifcomp = 1 while ifcomp: compstr = 'COMP_%d' % n iraf.imgets(imgroot,compstr) if iraf.imgets.value == 'sersic': # nth fitted component found xcstrn = '%d_XC' % n # x center iraf.imgets(imgroot,xcstrn) hxcentn=str(iraf.imgets.value) hxcentn=hxcentn.split('+/-') if len(hxcentn) == 1: xcentn = hxcentn[0] xcenterrn = '1.e-6' # there's no x center error information else: xcentn,xcenterrn=hxcentn xcent += [xcentn] xcenterr += [xcenterrn] ycstrn = '%d_YC' % n # y center iraf.imgets(imgroot,ycstrn) hycentn=str(iraf.imgets.value) hycentn=hycentn.split('+/-') if len(hycentn) == 1: ycentn = hycentn[0] ycenterrn = '1.e-6' # there's no y center error information else: ycentn,ycenterrn=hycentn ycent += [ycentn] ycenterr += [ycenterrn] magstrn = '%d_MAG' % n # mag iraf.imgets(imgroot,magstrn) hmagn=str(iraf.imgets.value) magn,magerrn=hmagn.split('+/-') mag += [magn] magerr += [magerrn] restrn = '%d_RE' % n # effective radius r_e iraf.imgets(imgroot,restrn) hren=str(iraf.imgets.value) ren,reerrn=hren.split('+/-') re += [ren] reerr += [reerrn] sersicnstrn = '%d_N' % n # sersic n iraf.imgets(imgroot,sersicnstrn) hsersicnn=str(iraf.imgets.value) sersicnn,sersicnerrn=hsersicnn.split('+/-') sersicn += [sersicnn] sersicnerr += [sersicnerrn] axratiostrn = '%d_AR' % n # axial ratio iraf.imgets(imgroot,axratiostrn) haxration=str(iraf.imgets.value) axration,axratioerrn=haxration.split('+/-') axratio += [axration] axratioerr += [axratioerrn] pastrn = '%d_PA' % n # position angle iraf.imgets(imgroot,pastrn) hpan=str(iraf.imgets.value) pan,paerrn=hpan.split('+/-') pa += [pan] paerr += [paerrn] iraf.imgets(imgroot,'CHISQ') # chi-square (same for the same image) hchisq=str(iraf.imgets.value) chisq += [hchisq] iraf.imgets(imgroot,'CHI2NU') # reduced chi-square (same for the same image) hchisqnu=str(iraf.imgets.value) chisqnu += [hchisqnu] iraf.imgets(imgroot,'OBJNUM') # object number (same for the same image!) hobjnum=str(iraf.imgets.value) objnum += [hobjnum] # process other attributes... n += 1 # jump to next possible component else: ifcomp = 0 # the last n will be 1 greater than the number of components # now start to print out the entries for i in range(n-1): f2.write("%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n" %(objnum[i],xcent[i],xcenterr[i],ycent[i],ycenterr[i],mag[i],magerr[i], re[i],reerr[i],sersicn[i],sersicnerr[i],axratio[i],axratioerr[i], pa[i],paerr[i],chisq[i],chisqnu[i])) f.close() f2.close() iraf.delete(files="tmplist", verify="no")
def getgain(im): iraf.imgets(image=im, param='GAIN') t = float(iraf.imgets.value) return t
def getheader(im, keyword): iraf.imgets(image=im, param=keyword) t = float(iraf.imgets.value) return t
def rotate24(): #for i in range(len(images24)): for i in range(3,6): #for i in range(1): iraf.imgets(image=images24[i],param='CROTA2')#[deg] Orientation of axis 2 (W of N, +=CW)
def createartcat(self, nstar=100, covimageflag=0, covimage='null', ncov=6, galcatflag=0): # add sources at random positions on image # even if a previous source is there, we need to know how crowding affects completeness # if there is a covereage map, like in the case of the rotated 24um image # need to take into account that some areas of the image have no exposure # ncov = min number of images iraf.imgets(image=self.inputimage, param='naxis1') #get RA of image xmax = float(iraf.imgets.value) iraf.imgets(image=self.inputimage, param='naxis2') #get RA of image ymax = float(iraf.imgets.value) xpos = [] ypos = [] mag = [] rad = [] BA = [] PA = [] if covimageflag: covimage = pyfits.open(covimage) cov_data = (covimage[0].data) covimage.close() i = 0 while i < nstar: xtemp = int(round(1 + rand() * (xmax - 2))) ytemp = int(round(1 + rand() * (ymax - 2))) if covimageflag: # check coverage map to make sure point is on science area # coverage map values > 6 are ok if cov_data[ytemp, xtemp] < ncov: continue xpos.append(xtemp) ypos.append(ytemp) # create magnitudes that sample linearly w/flux #flux=fmin+rand()*(fmax-fmin) #m=zp-2.5*log10(flux) if galcatflag: m = minmaggal + rand() * (maxmaggal - minmaggal) else: m = minmag + rand() * (maxmag - minmag) mag.append(m) r = rmin + rand() * (rmax - rmin) rad.append(r) b = BAmin + rand() * (BAmax - BAmin) BA.append(b) p = PAmin + rand() * (PAmax - PAmin) PA.append(p) i = i + 1 self.xpos = array(xpos, 'f') self.ypos = array(ypos, 'f') mag = array(mag, 'f') rad = array(rad, 'f') BA = array(BA, 'f') PA = array(PA, 'f') if galcatflag: outf = 'galaxies.coords.dat' else: outf = 'stars.coords.dat' outfile = open(self.imagedir + outf, 'w') for i in range(len(self.xpos)): if galcatflag: # x, y, mag, model (expdisk/devauc) radius B/A pa s = '%8.2f %8.2f %8.2f expdisk %6.2f %5.2f %6.2f\n' % ( self.xpos[i], self.ypos[i], mag[i], rad[i], BA[i], PA[i]) else: s = '%8.2f %8.2f %8.2f \n' % (self.xpos[i], self.ypos[i], mag[i]) outfile.write(s) outfile.close()
def plot2masspos(im): infile=open('fp_2mass.fp_psc1374.tbl','r') dra=[] ddec=[] iraf.imgets(image=im,param='RA')#get RA of image t=iraf.imgets.value t1=t.split(':') for i in range(len(t1)):#convert to floats t1[i]=float(t1[i]) RAcenter=15.*(t1[0]+t1[1]/60.+t1[2]/3600.)#convert to degrees iraf.imgets(image=im,param='DEC')#get RA of image t=iraf.imgets.value t1=t.split(':') for i in range(len(t1)):#convert to floats t1[i]=float(t1[i]) DECcenter=(t1[0]+t1[1]/60.+t1[2]/3600.)#convert to degrees for line in infile: if line.find('\\') > -1: continue if line.find('=') > -1: continue if line.find('|') > -1: continue t=line.split() if (float(t[6]) >15.): continue ra=(float(t[1])-RAcenter)*N.cos(N.pi/180.*float(t[2]))#correct delta ra for cos declination dec=(DECcenter-float(t[2]))#makes east to the left ra=ra*3600.#convert to arcsec dec=dec*3600. dra.append(ra)#save offsets from center position ddec.append(dec)#save offsets from center dra=N.array(dra,'f') ddec=N.array(ddec,'f') infile.close() xcenter=512 ycenter=512 plate=0.5#arcsec/pixel #convert offsets to pixels on pisces at 90" x=dra/plate y=ddec/plate #center at (512,512) in pixel coordinates x=x+xcenter y=y+ycenter #reflect about y axis and then swap x & y to match the orientation of pisces x=imxmax-x#reflect about x yt=x#swap x & t xt=y xt=imxmax-xt dy=-26. dx=20. for i in range(1000): yt=yt+dy xt=xt+dx outfile=open('2masscoords.dat','w') for i in range(len(x)): s="%8.2f %8.2f \n"%(xt[i],yt[i]) outfile.write(s) outfile.close() iraf.display(im,2) iraf.tvmark(2,'testxy.cat',color=207,radii=5) iraf.tvmark(2,'2masscoords.dat',color=206,radii=7.) try: flag= raw_input("how does it look? 1=keep, 0=adjust positions \n") flag=float(flag) except ValueError: print "Sorry, didn't get that. Let's try one more time." flag= raw_input("how does it look? 1=keep, 0=adjust positions \n") flag=float(flag) if flag > .1: break dx=raw_input("enter new x offset for sdss coords\n") dx=float(dx) dy=raw_input("enter new y offset for sdss coords\n") dy=float(dy)
def irafflatten(): os.system('cp /Users/rfinn/clusters/spitzer/flatsexfiles/* .') infile=open('InputImageList.txt','r') outfile=open('FlatImageList.txt','w') sky=[] for line in infile: im=line[0:(len(line)-1)] mask='mask'+im skyim='s'+im outline='f'+line iraf.imgets(im,'DRIBKGND') t=iraf.imgets.value sky.append(float(t)) outfile.write(outline) #get object positions using sextractor iraf.imarith(im,'-',t,skyim)#subtract sky before running sextractor (otherwise it doesn't detect any objects - don't know why...) s='sex '+skyim os.system(s) x=[] y=[] catfile=open('test.cat','r') for line in catfile: if line.find('#') > -1: continue t=line.split() x.append(float(t[10])) y.append(float(t[11])) catfile.close() x=N.array(x,'f') y=N.array(y,'f') try:#create image of ones same size as image iraf.imarith(im,'/',im,'mask') except: iraf.imdelete('mask') iraf.imarith(im,'/',im,'mask') print "masking objects" for j in range(len(x)): #mask objects and radius around each position using imreplace, radius=10 pix for k in range(11): y1=int(y[j]+5-k) if y1 < 1: continue if y1 > 128: continue xmin=int(x[j]-5) if xmin < 1: xmin=1 xmax=int(x[j]+5) if xmax > 128: xmax=128 s='mask['+str(xmin)+':'+str(xmax)+","+str(y1)+":"+str(y1)+"]" iraf.imreplace(s,0.) iraf.imrename('mask',mask) print "updating BPM field in header" iraf.hedit(im,fields='BPM',value=mask,add='yes',verify='no',update='yes') outfile.close() infile.close() avesky=N.average(N.array(sky,'f')) lthresh=avesky-1. hthresh=avesky+.6 iraf.imcombine('@InputImageList.txt','flat',combine='average',reject='ccdclip',scale='none',zero='mode',lthreshold=lthresh,hthreshold=hthresh,lsigma=2.,hsigma=2.,rdnoise=5.,gain=5.,blank=1.,grow=12.,masktype='badvalue',maskvalue='0') t=iraf.imstat('flat',fields='mean',format='no',Stdout=1) ave=float(t[0]) iraf.imarith('flat','/',ave,'nflat') iraf.imarith('@InputImageList.txt','/','nflat','@FlatImageList.txt')
def getxyfromradec(im, ra, dec): iraf.imgets(image=im, param='CRVAL1') #get RA of image in deg t = iraf.imgets.value RAcenter = float(t) iraf.imgets(image=im, param='CRVAL2') #get RA of image t = iraf.imgets.value DECcenter = float(t) dra = (RAcenter - ra) * cos( pi / 180. * dec) #correct delta ra for cos declination ddec = (dec - DECcenter) #ra=ra*3600.#convert to arcsec #dec=dec*3600. #dra=N.array(dra,'f') #ddec=N.array(ddec,'f') iraf.imgets(image=im, param='CRPIX1') #get x value corresponding to RA t = float(iraf.imgets.value) xcenter = t iraf.imgets(image=im, param='CRPIX2') #get y value corresponding to dec t = float(iraf.imgets.value) ycenter = t iraf.imgets(image=im, param='CD1_1') #get x value corresponding to RA xplate = abs(float(iraf.imgets.value)) #deg/pixel iraf.imgets(image=im, param='CD2_2') #get x value corresponding to RA yplate = abs(float(iraf.imgets.value)) #deg/pixel #convert offsets to pixels on pisces at 90" x = dra / xplate + xcenter y = ddec / yplate + ycenter return x, y
prefix = ['D17s', 'EGSdJ', 'EGSdn', 'EGSsn', 'standA'] iraf.images() iraf.images.imutil() iraf.immatch() for name in prefix: i = 0 s = name + "*.fits" files = glob.glob(s) for file in files: (pre, junk) = file.split('.') index = pre[(len(pre) - 4):len(pre)] iraf.imgets(image=file, param='FILTER') #get RA of image filter = iraf.imgets.value if my.beginsWith('D17s', file) > .1: outname = 'D17s' + str( file[7]) + "-" + str(filter) + "-" + str(index) + ".fits" s = "cp " + file + " " + outname + " \n" os.system(s) if my.beginsWith('EGSd', file) > .1: outname = 'EGS' + "-" + str(filter) + "-n1-" + str(index) + ".fits" s = "cp " + file + " " + outname + " \n" os.system(s) if my.beginsWith('EGSs', file) > .1: outname = 'EGSs' + str(int(file[7]) + 1) + "-" + str( filter) + "-" + str(index) + ".fits"
def alignimages(im1, im2): runsex = 1 #run sextractor to get object catalogs auto = 0. t = im1.split('.') prefixim1 = t[0] t = prefixim1.split('pre') fieldid = t[0] #saves cl1018 or whatever as fieldid t = im2.split('.') prefixim2 = t[0] filexy1 = prefixim1 + '-xy.cat' filexy2 = prefixim2 + '-xy.cat' print "aligning images for ", fieldid if runsex > 0: runsextractor(im1, auto) infile = open('test.cat', 'r') #keep only sources w/in useable field outfile = open(filexy1, 'w') for line in infile: #keep only targets w/in 500 pixels of center if line.find('#') > -1: continue t = line.split() out = '%8.4f %8.4f \n' % (float(t[10]), float(t[11])) outfile.write(out) infile.close() outfile.close() print "running sextractor on ", im2 runsextractor(im2, auto) infile = open('test.cat', 'r') #keep only sources w/in useable field outfile = open(filexy2, 'w') for line in infile: #keep only targets w/in 500 pixels of center if line.find('#') > -1: continue t = line.split() out = '%8.4f %8.4f \n' % (float(t[10]), float(t[11])) outfile.write(out) infile.close() outfile.close() match = fieldid + '-match' dbase = fieldid + '-match-geomap' iraf.display(im1, 1, fill='yes') iraf.display(im2, 2, fill='yes') reffile = fieldid + 'refpoints' #make these individually. First line w/3points in gmos image (x1 y1 x2 y2 x3 y3). 2nd line w/same points in ediscs I-band flag = raw_input("Should we create a refpoints file (0=no, 1=yes)?\n") flag = int(flag) if flag > 0.1: s = 'cp cl1018refpoints ' + reffile os.system(s) print "open ", reffile, " in emacs, delete 2 lines" print "Enter x1 y1 x2 y2 x3 y3 for ref image (gmos)" print "Enter x1 y1 x2 y2 x3 y3 for 2nd image (vlt)" iraf.imexam() iraf.xyxymatch(filexy2, filexy1, match, tolerance=15, refpoints=reffile, matching='tolerance', interactive='no') iraf.imgets(image=im1, param='i_naxis1') t = iraf.imgets.value im1xmax = (float(t)) iraf.imgets(image=im1, param='i_naxis2') t = iraf.imgets.value im1ymax = (float(t)) iraf.geomap(input=match, database=dbase, function='polynomial', xmin=1, xmax=im1xmax, ymin=1, ymax=im1ymax, xxorder=4, xyorder=4, yyorder=4, yxorder=4, transform='gmos', interactive='yes') transformim = 1 if transformim > 0: outim2 = 'g' + im2 iraf.geotran(im2, output=outim2, database=dbase, transform='gmos') iraf.display(im2, 1, fill='yes') iraf.display(outim2, 2, fill='yes') iraf.display(im1, 3, fill='yes')