def saveset_peakcoords(basename, threshold=100, hwhm=3): """ Attempts to find the peak of each saveset in an already tprepared image. Parameters: ----------- basename : string Everything before the .fits threshold : number Detection threshold for images.imcoords.starfind in counts Returns: -------- c : numpy.array Row stacked coordinates for each of the savesets """ #deleting files from previous runs iraf.delete('*fits*obj*') iraf.delete('images_ext.lst') iraf.images() iraf.imcoords() exts = len(pf.open(basename + '.fits')) - 1 f = open('images_ext.lst', 'w') for i in range(exts): f.write(basename + '.fits[' + str(i + 1) + '][*,*,3]\n') f.close() iraf.starfind(r'@images_ext.lst', 'default', hwhm, threshold) a = [basename + '.fits' + str(i + 1) + '.obj.1' for i in range(exts)] b = [loadtxt(a[i]) for i in range(exts) if len(loadtxt(a[i])) != 0] c = row_stack(b) f = open(a[0], 'r') d = f.readlines() f.close() header = [i for i in d if i[0] == '#'] f = open(basename + '_coords.dat', 'w') for i in header: f.write(i) f.write('\n') savetxt(f, c, fmt='%.3f') f.close() iraf.delete('*fits*obj*') iraf.delete('images_ext.lst') return c
def marksn2(img,fitstab,frame=1,fitstab2='',verbose=False): from pyraf import iraf from numpy import array #,log10 import lsc iraf.noao(_doprint=0) iraf.digiphot(_doprint=0) iraf.daophot(_doprint=0) iraf.images(_doprint=0) iraf.imcoords(_doprint=0) iraf.proto(_doprint=0) iraf.set(stdimage='imt1024') hdr=lsc.util.readhdr(fitstab) _filter=lsc.util.readkey3(hdr,'filter') column=lsc.lscabsphotdef.makecatalogue([fitstab])[_filter][fitstab] rasex=array(column['ra0'],float) decsex=array(column['dec0'],float) if fitstab2: hdr=lsc.util.readhdr(fitstab2) _filter=lsc.util.readkey3(hdr,'filter') _exptime=lsc.util.readkey3(hdr,'exptime') column=lsc.lscabsphotdef.makecatalogue([fitstab2])[_filter][fitstab2] rasex2=array(column['ra0'],float) decsex2=array(column['dec0'],float) iraf.set(stdimage='imt1024') iraf.display(img + '[0]',frame,fill=True,Stdout=1) vector=[] for i in range(0,len(rasex)): vector.append(str(rasex[i])+' '+str(decsex[i])) xy = iraf.wcsctran('STDIN',output="STDOUT",Stdin=vector,Stdout=1,image=img+'[0]',inwcs='world',units='degrees degrees',outwcs='logical',\ formats='%10.1f %10.1f',verbose='yes')[3:] iraf.tvmark(frame,'STDIN',Stdin=list(xy),mark="circle",number='yes',label='no',radii=10,nxoffse=5,nyoffse=5,color=207,txsize=2) if verbose: # print 2.5*log10(_exptime) for i in range(0,len(column['ra0'])): print xy[i],column['ra0'][i],column['dec0'][i],column['magp3'][i],column['magp4'][i],column['smagf'][i],column['magp2'][i] if fitstab2: vector2=[] for i in range(0,len(rasex2)): vector2.append(str(rasex2[i])+' '+str(decsex2[i])) xy1 = iraf.wcsctran('STDIN',output="STDOUT",Stdin=vector2,Stdout=1,image=img+'[0]',inwcs='world',units='degrees degrees',outwcs='logical',\ formats='%10.1f %10.1f',verbose='yes')[3:] iraf.tvmark(frame,'STDIN',Stdin=list(xy1),mark="cross",number='yes',label='no',radii=10,nxoffse=5,nyoffse=5,color=205,txsize=2)
def absphot(img,_field,_catalogue,_fix,_color,rejection,_interactive,_type='fit',redo=False,show=False,cutmag=-1,database='dataredulco',_calib='sloan'): from astropy.io import fits import lsc import math import sys,re,string,os from lsc.util import readkey3, readhdr from numpy import array, compress, zeros, median, std, asarray, isfinite,mean from pyraf import iraf if show: from pylab import ion,plot,draw,clf import time iraf.noao(_doprint=0) iraf.digiphot(_doprint=0) iraf.daophot(_doprint=0) iraf.images(_doprint=0) iraf.imcoords(_doprint=0) iraf.proto(_doprint=0) t = fits.open(img) tbdata = t[1].data hdr2=t[1].header hdr=lsc.util.readhdr(img) _cat=readkey3(hdr,'catalog') _telescope=lsc.util.readkey3(hdr,'telescop') _instrume=lsc.util.readkey3(hdr,'instrume') _filter=lsc.util.readkey3(hdr,'filter') _airmass=lsc.util.readkey3(hdr,'airmass') _exptime=lsc.util.readkey3(hdr,'exptime') _date=lsc.util.readkey3(hdr,'date-obs') _object=lsc.util.readkey3(hdr,'object') _ra=lsc.util.readkey3(hdr,'RA') _dec=lsc.util.readkey3(hdr,'DEC') print _filter if _telescope in ['lsc','1m0-04','1m0-05','1m0-09']: kk=lsc.sites.extintion('ctio') elif _telescope in ['elp','1m0-08']: kk=lsc.sites.extintion('mcdonald') elif _telescope in ['cpt','1m0-12','1m0-10','1m0-13']: kk=lsc.sites.extintion('southafrica') elif _telescope in ['ftn','Faulkes Telescope North']: kk=lsc.sites.extintion('mauna') elif _telescope in ['1m0-03','1m0-11','coj','fts','Faulkes Telescope South']: kk=lsc.sites.extintion('siding') if _calib not in ['sloan','sloanprime','natural','apass','']: colorefisso=lsc.sites.colfix(_instrume) else: colorefisso=lsc.sites.colfix(_instrume,_calib) print redo print _cat if _cat and not redo: print 'already calibrated' else: try: lsc.mysqldef.updatevalue(database,'zcat','X',string.split(re.sub('.sn2.fits','.fits',img),'/')[-1]) if os.path.isfile(string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]): lsc.mysqldef.updatevalue(database,'zcat','X',string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]) except: print 'module mysqldef not found' column=makecatalogue([img])[_filter][img] rasex=array(column['ra0'],float) decsex=array(column['dec0'],float) if _type=='fit': magsex=array(column['smagf'],float) magerrsex=array(column['smagerrf'],float) elif _type=='ph': magsex=array(column['magp3'],float) magerrsex=array(column['merrp3'],float) else: sys.exit(_type+' not valid (ph or fit)') print len(rasex) if not cutmag: cutmag=99 #else: cutmag= cutmag-2.5*math.log10(float(_exptime)) if len(compress( array(magsex) < float(cutmag) , magsex)) < 5 : cutmag=99 # not cut if only few object rasex = compress(array(magsex,float)<=cutmag,rasex) decsex = compress(array(magsex,float)<=cutmag,decsex) magerrsex = compress(array(magsex,float)<=cutmag,magerrsex) magsex = compress(array(magsex,float)<=cutmag,array(magsex)) print len(rasex) if _interactive: iraf.set(stdimage='imt1024') iraf.display(re.sub('.sn2','',img),1,fill=True,Stdout=1) vector=[] for i in range(0,len(rasex)): vector.append(str(rasex[i])+' '+str(decsex[i])) xy = iraf.wcsctran('STDIN',output="STDOUT",Stdin=vector,Stdout=1,image=img,inwcs='world',units='degrees degrees',outwcs='logical',\ formats='%10.1f %10.1f',verbose='yes')[3:] iraf.tvmark(1,'STDIN',Stdin=list(xy),mark="circle",number='yes',label='no',radii=10,nxoffse=5,nyoffse=5,color=207,txsize=2) # raw_input('here') if _catalogue: ######## use external catalogue if _catalogue[0]=='/': stdcooC=lsc.lscastrodef.readtxt(_catalogue) else: stdcooC=lsc.lscastrodef.readtxt(lsc.__path__[0]+'/standard/cat/'+_catalogue) rastdC,decstdL=array(stdcooC['ra'],float),array(stdcooC['dec'],float) lsc.util.delete('tmp.stdL.pix') colonne=str(stdcooC['rapos'])+' '+str(stdcooC['decpos']) if _catalogue[0]=='/': iraf.wcsctran(_catalogue,'tmp.stdL.pix',img,inwcs='world',units='degrees degrees',outwcs='logical',\ columns=colonne,formats='%10.1f %10.1f',verbose='no') else: iraf.wcsctran(lsc.__path__[0]+'/standard/cat/'+_catalogue,'tmp.stdL.pix',img,inwcs='world',units='degrees degrees',outwcs='logical',\ columns=colonne,formats='%10.1f %10.1f',verbose='no') standardpixC=lsc.lscastrodef.readtxt('tmp.stdL.pix') if _interactive: iraf.tvmark(1,'tmp.stdL.pix',mark="circle",number='yes',label='no',radii=8,nxoffse=5,nyoffse=5,color=204,txsize=2) xstdC=standardpixC['ra'] ystdC=standardpixC['dec'] idstdC=standardpixC['id'] xstdC=compress((array(xstdC,float)<readkey3(hdr,'XDIM'))&(array(xstdC,float)>0)&(array(ystdC,float)>0)&(array(ystdC,float)<readkey3(hdr,'YDIM')),xstdC) xstdL=xstdLL=xstdS=xstdC standardpixL=standardpixLL=standardpixS=standardpixC stdcooL=stdcooLL=stdcooS=stdcooC else: ######## check if it is landolt field stdcooL=lsc.lscastrodef.readtxt(lsc.__path__[0]+'/standard/cat/landolt.cat') rastdL,decstdL=array(stdcooL['ra'],float),array(stdcooL['dec'],float) lsc.util.delete('tmp.stdL.pix') iraf.wcsctran(lsc.__path__[0]+'/standard/cat/landolt.cat','tmp.stdL.pix',img,inwcs='world',units='degrees degrees',outwcs='logical',\ columns='1 2',formats='%10.1f %10.1f',verbose='no') standardpixL=lsc.lscastrodef.readtxt('tmp.stdL.pix') if _interactive: iraf.tvmark(1,'tmp.stdL.pix',mark="circle",number='yes',label='no',radii=8,nxoffse=5,nyoffse=5,color=204,txsize=2) print 'yelow circles sextractor' xstdL=standardpixL['ra'] ystdL=standardpixL['dec'] idstdL=standardpixL['id'] xstdL=compress((array(xstdL,float)<readkey3(hdr,'XDIM'))&(array(xstdL,float)>0)&(array(ystdL,float)>0)&(array(ystdL,float)<readkey3(hdr,'YDIM')),xstdL) ######## check if it is Stetson field stdcooLL=lsc.lscastrodef.readtxt(lsc.__path__[0]+'/standard/cat/StetsonCat.dat') ww=asarray([i for i in range(len(stdcooLL['ra'])) if ( abs(float(stdcooLL['ra'][i])-float(_ra))<.2 and abs(float(stdcooLL['dec'][i])-_dec)<.2 )]) if len(ww)>0: for hh in stdcooLL.keys(): if type(stdcooLL[hh])!=int: if hh not in ['id','ra','dec']: stdcooLL[hh]=array(array(stdcooLL[hh])[ww],float) else: stdcooLL[hh]=array(stdcooLL[hh])[ww] lll=[] for i in range(0,len(stdcooLL['ra'])): lll.append(stdcooLL['ra'][i]+' '+stdcooLL['dec'][i]) rastdLL,decstdLL=array(stdcooLL['ra'],float),array(stdcooLL['dec'],float) lsc.util.delete('tmp.stdLL.pix') iraf.wcsctran('STDIN','tmp.stdLL.pix',img,inwcs='world',Stdin=lll,units='degrees degrees',outwcs='logical',\ columns='1 2',formats='%10.1f %10.1f',verbose='no') if _interactive: iraf.tvmark(1,'tmp.stdLL.pix',mark="cross",number='yes',label='no',radii=8,nxoffse=5,nyoffse=5,color=204,txsize=2) print 'red crosses Stetson' standardpixLL={} for ii in stdcooLL.keys(): standardpixLL[ii]=stdcooLL[ii] standardpixLL['ra']=array(iraf.proto.fields('tmp.stdLL.pix',fields='1',Stdout=1),float) #standardpixLL['ra'] standardpixLL['dec']=array(iraf.proto.fields('tmp.stdLL.pix',fields='2',Stdout=1),float) #standardpixLL['dec'] xstdLL=array(iraf.proto.fields('tmp.stdLL.pix',fields='1',Stdout=1),float) #standardpixLL['ra'] ystdLL=array(iraf.proto.fields('tmp.stdLL.pix',fields='2',Stdout=1),float) #standardpixLL['dec'] idstdLL=standardpixLL['id'] xstdLL=compress((array(xstdLL,float)<readkey3(hdr,'XDIM'))&(array(xstdLL,float)>0)&(array(ystdLL,float)>0)&(array(ystdLL,float)<readkey3(hdr,'YDIM')),xstdLL) ######## check if it is sloan field magsel0,magsel1=12,18 _ids=lsc.lscastrodef.sloan2file(_ra,_dec,20,float(magsel0),float(magsel1),'_tmpsloan.cat') ascifile='_tmpsloan.cat' stdcooS=lsc.lscastrodef.readtxt(ascifile) rastdS,decstdS=array(stdcooS['ra'],float),array(stdcooS['dec'],float) lsc.util.delete('tmp.stdS.pix') iraf.wcsctran(ascifile,'tmp.stdS.pix',img,inwcs='world',units='degrees degrees',outwcs='logical',columns='1 2',formats='%10.1f %10.1f',verbose='no') standardpixS=lsc.lscastrodef.readtxt('tmp.stdS.pix') if _interactive: iraf.tvmark(1,'tmp.stdS.pix',mark="cross",number='yes',label='no',radii=8,nxoffse=5,nyoffse=5,color=205,txsize=2) print 'green cross sloan' xstdS=standardpixS['ra'] ystdS=standardpixS['dec'] idstdS=standardpixS['id'] xstdS=compress((array(xstdS,float)<readkey3(hdr,'XDIM'))&(array(xstdS,float)>0)&(array(ystdS,float)>0)&(array(ystdS,float)<readkey3(hdr,'YDIM')),xstdS) ##############################################3 if not _catalogue and len(xstdLL)>0: xstdL=xstdLL standardpixL=standardpixLL stdcooL=stdcooLL if _filter in ['U', 'B', 'V', 'R','I','Bessell-B','Bessell-V','Bessell-R','Bessell-I']: filters={'U':'U', 'B':'B', 'V':'V', 'R':'R', 'I':'I','Bessell-B':'B','Bessell-V':'V','Bessell-R':'R','Bessell-I':'I'} if _color: colors=lsc.myloopdef.chosecolor(_color,False) if not colors: colors={'U':['UB'],'B':['UB','BV'],'V':['BV','VR'],'R':['VR','RI'],'I':['RI']} else: colors={'U':['UB'],'B':['UB','BV'],'V':['BV','VR'],'R':['VR','RI'],'I':['RI']} if _field=='sloan': standardpix,stdcoo={'ra':[9999],'dec':[9999],'id':[1]},{'ra':[9999],'dec':[9999]} print 'filters and field selected do not match' else: _field='landolt' if len(xstdL)>=1: standardpix=standardpixL stdcoo=stdcooL if not _catalogue: if len(xstdLL)>0: _catalogue='StetsonCat.dat' else: _catalogue='landolt.dat' elif len(xstdS)>=1: if not _catalogue: _catalogue='sdss8' standardpix=standardpixS stdcoo=stdcooS stdcoo=lsc.lscastrodef.transformsloanlandolt(stdcoo) if not _catalogue: _catalogue='sdss8' print '\n### transform sloan in landolt' else: print 'landolt, but catalogue not found' standardpix,stdcoo={'ra':[9999],'dec':[9999],'id':[1]},{'ra':[9999],'dec':[9999]} elif _filter in ['up','gp','rp','ip','zs','SDSS-G','SDSS-R','SDSS-I','Pan-Starrs-Z']: filters={'up':'u','ip':'i','gp':'g','rp':'r','zs':'z','SDSS-G':'g','SDSS-R':'r','SDSS-I':'i','Pan-Starrs-Z':'z'} if _color: colors=lsc.myloopdef.chosecolor(_color,False) if not colors: colors={'i':['ri','iz'],'r':['gr','ri'],'g':['ug','gr'],'z':['iz'],'u':['ug']} else: colors={'i':['ri','iz'],'r':['gr','ri'],'g':['ug','gr'],'z':['iz'],'u':['ug']} if _field=='landolt': standardpix,stdcoo={'ra':[9999],'dec':[9999],'id':[1]},{'ra':[9999],'dec':[9999]} print 'filters and field selected do not match' else: _field='sloan' if len(xstdS)>=1: if not _catalogue: _catalogue='sdss8' standardpix=standardpixS stdcoo=stdcooS elif len(xstdL)>=1: standardpix=standardpixL stdcoo=stdcooL stdcoo=lsc.lscastrodef.transformlandoltsloan(stdcoo) if not _catalogue: _catalogue='landolt.dat' print '\n### transform landolt to sloan' else: print 'sloan, but not in the sdss footprint' standardpix,stdcoo={'ra':[9999],'dec':[9999],'id':[1]},{'ra':[9999],'dec':[9999]} xstd=standardpix['ra'] ystd=standardpix['dec'] idstd=standardpix['id'] rastd,decstd=array(stdcoo['ra'],float),array(stdcoo['dec'],float) xstd0=compress((array(xstd,float)<readkey3(hdr,'XDIM'))&(array(xstd,float)>0)&(array(ystd,float)>0)&(array(ystd,float)<readkey3(hdr,'YDIM')),xstd) if len(xstd0)>1: ######## go only if standard stars are in the field ########## magstd0={} airmass0={} result={} fileph={} print '\n### standard field: '+str(_field) ystd0=compress((array(xstd,float)<readkey3(hdr,'XDIM'))&(array(xstd,float)>0)&(array(ystd,float)>0)\ &(array(ystd,float)<readkey3(hdr,'YDIM')),ystd) rastd0=compress((array(xstd,float)<readkey3(hdr,'XDIM'))&(array(xstd,float)>0)&(array(ystd,float)>0)\ &(array(ystd,float)<readkey3(hdr,'YDIM')),rastd) decstd0=compress((array(xstd,float)<readkey3(hdr,'XDIM'))&(array(xstd,float)>0)&(array(ystd,float)>0)\ &(array(ystd,float)<readkey3(hdr,'YDIM')),decstd) idstd0=compress((array(xstd,float)<readkey3(hdr,'XDIM'))&(array(xstd,float)>0)&(array(ystd,float)>0)\ &(array(ystd,float)<readkey3(hdr,'YDIM')),idstd) stdcoo0={} for key in stdcoo.keys(): if key in 'ugrizUBVRI': stdcoo0[key]=compress((array(xstd,float)<readkey3(hdr,'XDIM'))&(array(xstd,float)>0)&(array(ystd,float)>0)\ &(array(ystd,float)<readkey3(hdr,'YDIM')),stdcoo[key]) ############################################################### # pos0 = standard pos1 = sextractor distvec,pos0,pos1=lsc.lscastrodef.crossmatch(array(rastd0),array(decstd0),array(rasex),array(decsex),10) for key in stdcoo0.keys(): stdcoo0[key]=stdcoo0[key][pos0] rastd0=rastd0[pos0] decstd0=decstd0[pos0] idstd0=idstd0[pos0] rasex=rasex[pos1] decsex=decsex[pos1] # after change in may 2013 mag in sn2.fits file are already at 1s magsex=magsex[pos1]-kk[filters[_filter]]*float(_airmass) # - K x airmass # magsex=magsex[pos1]+2.5*math.log10(float(_exptime))-kk[filters[_filter]]*float(_airmass) # mag exptime - K x airmass ################################################################################# if _field=='landolt': print '\n### landolt system' for _filtlandolt in 'UBVRI': if _filtlandolt==filters[_filter]: airmass0[_filtlandolt]= 0 #_airmass else: airmass0[_filtlandolt]= 0 magstd0[_filtlandolt]=stdcoo0[_filtlandolt] fileph['mU']=zeros(len(rastd0))+999 fileph['mB']=zeros(len(rastd0))+999 fileph['mV']=zeros(len(rastd0))+999 fileph['mR']=zeros(len(rastd0))+999 fileph['mI']=zeros(len(rastd0))+999 fileph['V']=magstd0['V'] fileph['BV']=array(array(magstd0['B'],float)-array(magstd0['V'],float),str) fileph['UB']=array(array(magstd0['U'],float)-array(magstd0['B'],float),str) fileph['VR']=array(array(magstd0['V'],float)-array(magstd0['R'],float),str) fileph['RI']=array(array(magstd0['R'],float)-array(magstd0['I'],float),str) elif _field=='sloan': for _filtsloan in 'ugriz': if _filtsloan==filters[_filter]: airmass0[_filtsloan]= 0 # _airmass else: airmass0[_filtsloan]=0 magstd0[_filtsloan]=stdcoo0[_filtsloan] fileph['mu']=zeros(len(rastd0))+999 fileph['mg']=zeros(len(rastd0))+999 fileph['mr']=zeros(len(rastd0))+999 fileph['mi']=zeros(len(rastd0))+999 fileph['mz']=zeros(len(rastd0))+999 fileph['r']=magstd0['r'] fileph['gr']=array(array(magstd0['g'],float)-array(magstd0['r'],float),str) fileph['ri']=array(array(magstd0['r'],float)-array(magstd0['i'],float),str) fileph['ug']=array(array(magstd0['u'],float)-array(magstd0['g'],float),str) fileph['iz']=array(array(magstd0['i'],float)-array(magstd0['z'],float),str) ######################################################################################## zero=[] magcor=[] fil = open(re.sub('.fits','.ph',img),'w') fil.write(str(_instrume)+' '+str(_date)+'\n') fil.write('*** '+_object+' '+str(len(magsex))+'\n') if _field=='landolt': fil.write('%6.6s\t%6.6s\t%6.6s\t%6.6s\t%6.6s\n' % (str(1),str(1),str(1),str(1),str(1))) # exptime fil.write('%6.6s\t%6.6s\t%6.6s\t%6.6s\t%6.6s\n' % (str(airmass0['U']),str(airmass0['B']),str(airmass0['V']),str(airmass0['R']),str(airmass0['I']))) elif _field=='sloan': fil.write('%6.6s\t%6.6s\t%6.6s\t%6.6s\t%6.6s\n' % (str(1),str(1),str(1),str(1),str(1))) # exptime fil.write('%6.6s\t%6.6s\t%6.6s\t%6.6s\t%6.6s\n' % (str(airmass0['u']),str(airmass0['g']),str(airmass0['r']),str(airmass0['i']),str(airmass0['z']))) for i in range(0,len(magsex)): fileph['m'+filters[_filter]][i]=magsex[i] # instrumental mangitude of std in pos0[i] if _field=='landolt': stringastandard='%12.12s\t%7.7s\t%7.7s\t%7.7s\t%7.7s\t%7.7s' % (idstd0[i],fileph['V'][i],fileph['BV'][i],fileph['UB'][i],\ fileph['VR'][i],fileph['RI'][i]) fil.write('%7.7s\t%7.7s\t%7.7s\t%7.7s\t%7.7s\t%60.60s\n' \ % (str(fileph['mU'][i]),str(fileph['mB'][i]),str(fileph['mV'][i]),str(fileph['mR'][i]),str(fileph['mI'][i]),str(stringastandard))) elif _field=='sloan': stringastandard='%12.12s\t%7.7s\t%7.7s\t%7.7s\t%7.7s\t%7.7s' % (idstd0[i],fileph['r'][i],fileph['gr'][i],fileph['ug'][i],\ fileph['ri'][i],fileph['iz'][i]) fil.write('%7.7s\t%7.7s\t%7.7s\t%7.7s\t%7.7s\t%60.60s\n' \ % (str(fileph['mu'][i]),str(fileph['mg'][i]),str(fileph['mr'][i]),str(fileph['mi'][i]),str(fileph['mz'][i]),str(stringastandard))) zero.append(float(float(magstd0[filters[_filter]][i]))-float(magsex[i])) magcor.append(magsex[i]) fil.close() if show: import time from pylab import ion,plot,draw ion() aa=mean(compress(abs(array(zero))<99,zero)) xxx=compress((abs(array(magcor))<99)&(abs(array(zero))<99),magcor) yyy=compress((abs(array(zero))<99)&(abs(array(magcor))<99),zero) plot(xxx,yyy,'or') plot([min(compress(abs(array(magcor))<99,magcor)),max(compress(abs(array(magcor))<99,magcor))],[aa,aa],'-b') draw() print std(compress(abs(array(zero))<99,zero)) time.sleep(5) colorvec=colors[filters[_filter]] for col in colorvec: col0=magstd0[col[0]] col1=magstd0[col[1]] colstd0=array(col0,float)-array(col1,float) ################## sex ###################### colore=[] for i in range(0,len(pos1)): colore.append(colstd0[i]) colore1=compress(abs(array(zero))<50,array(colore)) zero1=compress(abs(array(zero))<50,array(zero)) zero2=compress(abs(array(colore1))<2,array(zero1)) colore2=compress(abs(array(colore1))<2,array(colore1)) if _fix: fisso=colorefisso[filters[_filter]+col] else: fisso='' if len(colore2)==0: print 'no calibration, '+_filter+' '+_field b,a,sa,sb=9999,9999,0,0 else: if _interactive: a,sa,b,sb=fitcol(colore2,zero2,_filter,col,fisso) else: a,sa,b,sb=fitcol2(colore2,zero2,_filter,col,fisso,show,rejection) print a,sa,b,sb result[filters[_filter]+col]=[a,sa,b,sb] if result: print '\n### zeropoint ..... done at airmass 0' if _catalogue: lsc.util.updateheader(img,0,{'CATALOG':[str(string.split(_catalogue,'/')[-1]),'catalogue source']}) stringa='' for ll in result: for kk in range(0,len(result[ll])): if not isfinite(result[ll][kk]): result[ll][kk]=0.0 valore='%3.3s %6.6s %6.6s %6.6s %6.6s' % (str(ll),str(result[ll][0]),str(result[ll][2]),str(result[ll][1]),str(result[ll][3])) print '### ',valore lsc.util.updateheader(img,0,{'zp'+ll:[str(valore),'a b sa sb in y=a+bx']}) if ll[0]==ll[2]: num=2 elif ll[0]==ll[1]: num=1 else: sys.exit('somthing wrong with color '+ll) print ll,num try: print 'zcol'+str(num),ll[1:],string.split(re.sub('.sn2.fits','.fits',img),'/')[-1] lsc.mysqldef.updatevalue(database,'zcol'+str(num),ll[1:],string.split(re.sub('.sn2.fits','.fits',img),'/')[-1]) lsc.mysqldef.updatevalue(database,'z'+str(num),result[ll][0],string.split(re.sub('.sn2.fits','.fits',img),'/')[-1]) lsc.mysqldef.updatevalue(database,'c'+str(num),result[ll][2],string.split(re.sub('.sn2.fits','.fits',img),'/')[-1]) lsc.mysqldef.updatevalue(database,'dz'+str(num),result[ll][1],string.split(re.sub('.sn2.fits','.fits',img),'/')[-1]) lsc.mysqldef.updatevalue(database,'dc'+str(num),result[ll][3],string.split(re.sub('.sn2.fits','.fits',img),'/')[-1]) if os.path.isfile(string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]): lsc.mysqldef.updatevalue(database,'zcol'+str(num),ll[1:],string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]) lsc.mysqldef.updatevalue(database,'z'+str(num),result[ll][0],string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]) lsc.mysqldef.updatevalue(database,'c'+str(num),result[ll][2],string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]) lsc.mysqldef.updatevalue(database,'dz'+str(num),result[ll][1],string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]) lsc.mysqldef.updatevalue(database,'dc'+str(num),result[ll][3],string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]) if result[ll][0]!=9999: print _catalogue lsc.mysqldef.updatevalue(database,'zcat',string.split(_catalogue,'/')[-1],string.split(re.sub('.sn2.fits','.fits',img),'/')[-1]) if os.path.isfile(string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]): lsc.mysqldef.updatevalue(database,'zcat',string.split(_catalogue,'/')[-1],string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]) else: lsc.mysqldef.updatevalue(database,'zcat','X',string.split(re.sub('.sn2.fits','.fits',img),'/')[-1]) if os.path.isfile(string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]): lsc.mysqldef.updatevalue(database,'zcat','X',string.split(re.sub('.diff.sn2.fits','.fits',img),'/')[-1]) except: print 'module mysqldef not found'
_show = False else: _show = True if option.redo == False: redo = False else: redo = True arterr = '' if _interactive: _show = True print _show, _interactive # ####################### SET IRAF PARAMETERS ####################### from pyraf import iraf iraf.astcat(_doprint=0) iraf.imcoords(_doprint=0) iraf.digiphot(_doprint=0) iraf.daophot(_doprint=0) zmag = 0 iraf.digiphot.daophot.photpars.zmag = zmag ################################# CHECK HEADER ###################################### warn = '##################################\n' for imglong in imglist: if imglong: if imglong[-5:] == '.fits': img = imglong[:-5] else: img = imglong ###### try: print string.split(img, '/')[-1] + '.fits'
def findWorldPosition(self, write=False): # Convert the GRB pixel position to WCS # Make the input file for the IRAF task if self._pixelx == "" or self._pixely == "": print "You did not set an pixel x or pixel y" return 1 coordfilenamein = "%s" % (self._parentimage.replace(".fits", "_skyctran_pixel_in.coo")) coordfilenameout = "%s" % (self._parentimage.replace(".fits", "_skyctran_pixel_out.coo")) try: self.cleanOutputFiles(coordfilenameout) except: print "Error cleaning files" print sys.exc_info()[0] try: coordout = open(coordfilenamein, "w") coordout.write("%10.7f %10.7f" % (self._pixelx, self._pixely)) coordout.close() except: print "File opening failed:" print sys.exc_info()[0] # This subroutine lies in imcoords on IRAF iraf.image() iraf.imcoords() # Set the parameters of skyctran # # input # output # insystem: input coordinate system # outsystem: output coordinate system # lngcolu: RA column no. # latcolu: DEC column no. # ilnguni: RA input coord type # ilnlatuni: DEC input coord type # olnguni: RA output coord type # olatuni: DEC output coord type # ilngfor: RA input float format # ilatfor: DEC input float format # olngfor: RA output float format # olatfor: DEC output float format iraf.skyctran.setParam('input', coordfilenamein) iraf.skyctran.setParam('output', coordfilenameout) iraf.skyctran.setParam('insystem', '%s logical' % self._parentimage) iraf.skyctran.setParam('outsystem', '%s world' % self._parentimage) iraf.skyctran.setParam('lngcolu', '1') iraf.skyctran.setParam('latcolu', '2') iraf.skyctran.setParam('ilnguni', 'logical') iraf.skyctran.setParam('ilatuni', 'logical') iraf.skyctran.setParam('olnguni', 'degrees') iraf.skyctran.setParam('olatuni', 'degrees') iraf.skyctran.setParam('ilngfor', '%10.7f') iraf.skyctran.setParam('ilatfor', '%10.7f') iraf.skyctran.setParam('olngfor', '%10.3f') iraf.skyctran.setParam('olatfor', '%10.3f') iraf.skyctran.setParam('verbose', 'yes') # savepars skyctran = "skyctranpars.par" #iraf.skyctran.saveParList(skyctran) # run skyctran tmp = iraf.skyctran(mode='h', Stdout=1) # Set properties of this object from the output try: coordfile = open(coordfilenameout, "r") # parse the input file coords = coordfile.readlines() coordfile.close() for coord in coords: if coord[0] != "#" and coord[0] != "\n": coordinates = [i for i in coord.replace("\n","").split(" ") if i != ""] # Set the object parameters self._ra = float(coordinates[2]) self._dec = float(coordinates[3]) except: print "File opening failed" print sys.exc_info()[0] # region file for object of interest if write: try: regionout = open("%s" % (self._parentimage.replace(".fits", "_skyctran_object.reg")), "w") if self._MEDFWHM == "": circ = 4.0 else: circ = self._MEDFWHM*1.5 regionout.write("image; circle(%f,%f,%f) # color = red\n" % (self._pixelx, self._pixely, circ)) regionout.close() except: print "Unexpected error:" print sys.exc_info()[0]
def marksn2(img, fitstab, frame=1, fitstab2='', verbose=False): from pyraf import iraf from numpy import array #,log10 import lsc iraf.noao(_doprint=0) iraf.digiphot(_doprint=0) iraf.daophot(_doprint=0) iraf.images(_doprint=0) iraf.imcoords(_doprint=0) iraf.proto(_doprint=0) iraf.set(stdimage='imt1024') hdr = lsc.util.readhdr(fitstab) _filter = lsc.util.readkey3(hdr, 'filter') column = lsc.lscabsphotdef.makecatalogue([fitstab])[_filter][fitstab] rasex = array(column['ra0'], float) decsex = array(column['dec0'], float) if fitstab2: hdr = lsc.util.readhdr(fitstab2) _filter = lsc.util.readkey3(hdr, 'filter') _exptime = lsc.util.readkey3(hdr, 'exptime') column = lsc.lscabsphotdef.makecatalogue([fitstab2])[_filter][fitstab2] rasex2 = array(column['ra0'], float) decsex2 = array(column['dec0'], float) iraf.set(stdimage='imt1024') iraf.display(img + '[0]', frame, fill=True, Stdout=1) vector = [] for i in range(0, len(rasex)): vector.append(str(rasex[i]) + ' ' + str(decsex[i])) xy = iraf.wcsctran('STDIN',output="STDOUT",Stdin=vector,Stdout=1,image=img+'[0]',inwcs='world',units='degrees degrees',outwcs='logical',\ formats='%10.1f %10.1f',verbose='yes')[3:] iraf.tvmark(frame, 'STDIN', Stdin=list(xy), mark="circle", number='yes', label='no', radii=10, nxoffse=5, nyoffse=5, color=207, txsize=2) if verbose: # print 2.5*log10(_exptime) for i in range(0, len(column['ra0'])): print xy[i], column['ra0'][i], column['dec0'][i], column['magp3'][ i], column['magp4'][i], column['smagf'][i], column['magp2'][i] if fitstab2: vector2 = [] for i in range(0, len(rasex2)): vector2.append(str(rasex2[i]) + ' ' + str(decsex2[i])) xy1 = iraf.wcsctran('STDIN',output="STDOUT",Stdin=vector2,Stdout=1,image=img+'[0]',inwcs='world',units='degrees degrees',outwcs='logical',\ formats='%10.1f %10.1f',verbose='yes')[3:] iraf.tvmark(frame, 'STDIN', Stdin=list(xy1), mark="cross", number='yes', label='no', radii=10, nxoffse=5, nyoffse=5, color=205, txsize=2)
def fitsn(img, imgpsf, coordlist, _recenter, fwhm0, original, sn, residual, _show, _interactive, z11='', z22='', midpt='', size=7, apco0=0, dmax=51000, dmin=-500): import lsc lsc.util.delete("apori") lsc.util.delete(img + ".sn.mag") ################################# from pyraf import iraf import string iraf.imcoords(_doprint=0) iraf.digiphot(_doprint=0) iraf.daophot(_doprint=0) from iraf import digiphot from iraf import daophot from iraf import ptools a1 = int(fwhm0) a2 = int(2. * fwhm0 + .5) a3 = int(3. * fwhm0 + .5) a4 = int(4. * fwhm0 + .5) ap = str(a1) + "," + str(a2) + "," + str(a3) ######################################## if _recenter: answ = 'yes' else: answ = 'no' ######################################### hdr = lsc.util.readhdr(img + '.fits') _gain = lsc.util.readkey3(hdr, 'gain') _ron = lsc.util.readkey3(hdr, 'ron') _exptime = lsc.util.readkey3(hdr, 'exptime') _datamin = dmin _datamax = dmax iraf.noao.digiphot.daophot.photpars.zmag = 0 iraf.noao.digiphot.daophot.datapars.readnoi = _gain #1.4 #_ron iraf.noao.digiphot.daophot.datapars.epadu = _ron # 13 #_gain iraf.noao.digiphot.daophot.datapars.datamin = _datamin # -100 #_datamin iraf.noao.digiphot.daophot.datapars.datamax = _datamax iraf.noao.daophot.fitskypars.annulus = a3 iraf.noao.daophot.photpars.apertures = ap iraf.noao.digiphot.daophot.datapars.exposure = 'exptime' iraf.noao.digiphot.daophot.datapars.airmass = 'airmass' iraf.noao.digiphot.daophot.datapars.filter = 'filter2' iraf.noao.digiphot.daophot.daopars.psfrad = a4 # modify fitrad to 3 fwhm to see if works better iraf.noao.digiphot.daophot.daopars.fitrad = fwhm0 #* 3 iraf.noao.digiphot.daophot.daopars.sannulus = int(a4) iraf.noao.digiphot.daophot.daopars.recenter = answ iraf.noao.digiphot.daophot.daopars.fitsky = 'yes' # iraf.noao.digiphot.daophot.centerpars.cbox = 0 iraf.noao.digiphot.daophot.centerpars.cbox = 4 iraf.noao.digiphot.daophot.centerpars.calgori = 'gauss' # fitskypars.salgorithm = "constant" # fitskypars.skyvalue = 0 print '\n### recentering: ' + str(answ) if _show: iraf.noao.digiphot.daophot.phot(original, coordlist, "apori", veri='no') iraf.noao.digiphot.daophot.phot(sn, coordlist, img + ".sn.mag", veri='no') else: iraf.noao.digiphot.daophot.phot(original, coordlist, "apori", veri='no', verb='no') iraf.noao.digiphot.daophot.phot(sn, coordlist, img + ".sn.mag", veri='no', verb='no') lsc.util.delete(img + ".sn.als") print sn, imgpsf, img iraf.allstar(sn, img + ".sn.mag", imgpsf, img + ".sn.als", "", residual, veri='no', verb='no') lsc.util.delete("snfit.fits") iraf.imarith(sn + '.fits', "-", residual + '.fits', "snfit.fits") lsc.util.delete("skyfit.fits") iraf.imarith(original + '.fits', "-", "snfit.fits", "skyfit.fits") iraf.txsort(img + ".sn.als", "ID") tmptbl = iraf.txdump(img + ".sn.als", "mag,merr,xcenter,ycenter", expr='yes', Stdout=1) magerr, fitmag, centx, centy = [], [], [], [] for i in tmptbl: try: fitmag.append(float(string.split(i)[0])) #-2.5*log10(_exptime)) except: fitmag.append(string.split(i)[0]) try: magerr.append(float(string.split(i)[1])) except: magerr.append(string.split(i)[1]) centx.append(float(string.split(i)[2])) centy.append(float(string.split(i)[3])) tmptbl = iraf.txdump("apori", "mag", expr='yes', Stdout=1) apori1, apori2, apori3 = [], [], [] for i in tmptbl: try: apori1.append(float(string.split(i)[0])) #-2.5*log10(_exptime)) except: apori1.append(string.split(i)[0]) try: apori2.append(float(string.split(i)[1])) #-2.5*log10(_exptime)) except: apori2.append(string.split(i)[1]) try: apori3.append(float(string.split(i)[2])) #-2.5*log10(_exptime)) except: apori3.append(string.split(i)[2]) iraf.txsort(img + ".sn.mag", "YCENTER") tmptbl = iraf.txdump(img + ".sn.mag", "mag,magerr", expr='yes', Stdout=1) if _show: print "********************************************************************" print "ID <apmag on original> <apmag on bgsubt> fitmag truemag err_fit" print " ", a1, " ", a2, " ", a3, " ", a1, " ", a2, " ", a3 apmag1, apmag2, apmag3, truemag = [], [], [], [] for i in range(len(tmptbl)): try: apmag1.append(float(string.split( tmptbl[i])[0])) #-2.5*log10(_exptime)) except: apmag1.append(9999) try: apmag2.append(float(string.split( tmptbl[i])[1])) #-2.5*log10(_exptime)) except: apmag2.append(9999) try: apmag3.append(float(string.split( tmptbl[i])[2])) #-2.5*log10(_exptime)) except: apmag3.append(9999) try: truemag.append(fitmag[i] + float(apco0)) except: truemag.append('INDEF') if _show: print i, apori1[i], apori2[i], apori3[i], apmag1[i], apmag2[ i], apmag3[i], fitmag[i], truemag[i], magerr[i] if _show: print "********************************************************************" if _show: print midpt, z11, z22 _tmp1, _tmp2, goon = lsc.util.display_image(original + '.fits', 1, z11, z22, False, _xcen=.25, _ycen=.25, _xsize=.3, _ysize=.3) z01 = float(z11) - float(midpt) z02 = float(z22) - float(midpt) s1 = 1 s2 = -int(fwhm0) lsc.util.delete("tmptbl") ff = open('tmptbl', 'w') ff.write(str(s1) + ' ' + str(s2) + " ORIGINAL") ff.close() iraf.tvmark(1, "tmptbl", autol='no', mark="none", inter='no', label='yes', txsize=2) _tmp1, _tmp2, goon = lsc.util.display_image('snfit.fits', 1, z01, z02, False, _xcen=.25, _ycen=.75, _xsize=.3, _ysize=.3, _erase='no') lsc.util.delete("tmptbl") tmptbl0 = iraf.txdump(img + ".sn.als", "xcen,ycen", expr='yes', Stdout=1) ff = open('tmptbl', 'w') for i in tmptbl0: ff.write(i + '\n') ff.close() lra = int((2 * float(size) * float(fwhm0)) * 2) iraf.tvmark(1, "tmptbl", autol='no', mark="circle", number='yes', nyoffset=lra, radi=a2, txsize=2, inter='no') s1 = 1 s2 = -1 * int(fwhm0) lsc.util.delete("tmptbl") ff = open('tmptbl', 'w') ff.write(str(s1) + ' ' + str(s2) + " FITTED") ff.close() iraf.tvmark(1, "tmptbl", autol='no', mark="none", inter='no', label='yes', txsize=2) _tmp1, _tmp2, goon = lsc.util.display_image('skyfit.fits', 1, z11, z22, False, _xcen=.75, _ycen=.25, _xsize=.3, _ysize=.3, _erase='no') s1 = 1 s2 = -1 * int(fwhm0) lsc.util.delete("tmptbl") ff = open('tmptbl', 'w') ff.write(str(s1) + ' ' + str(s2) + " RESIDUAL") ff.close() iraf.tvmark(1, "tmptbl", autol='no', mark="none", inter='no', label='yes', txsize=2) return apori1, apori2, apori3, apmag1, apmag2, apmag3, fitmag, truemag, magerr, centx, centy
# Access to the iqutils from iqutils import * import iqpkg # Necessary packages iraf.images() iraf.immatch() iraf.noao() iraf.imred() iraf.ccdred() iraf.digiphot() iraf.daophot() iraf.photcal() iraf.images() iraf.imcoords() yes=iraf.yes no=iraf.no INDEF=iraf.INDEF hedit=iraf.hedit imgets=iraf.imgets imcombine=iraf.imcombine pyrafdir="python/pyraf/" pyrafdir_key='PYRAFPARS' if os.environ.has_key(pyrafdir_key): pardir=os.environ[pyrafdir_key] else: pardir=os.environ['HOME']+'/'+pyrafdir
def fitsn(img,imgpsf,coordlist,_recenter,fwhm0,original,sn,residual,_show,_interactive,dmax,dmin,z11='',z22='',midpt='',size=7,apco0=0): import lsc lsc.util.delete("apori") lsc.util.delete(img+".sn.mag") ################################# from pyraf import iraf import string iraf.imcoords(_doprint=0) iraf.digiphot(_doprint=0) iraf.daophot(_doprint=0) from iraf import digiphot from iraf import daophot from iraf import ptools a1 = int(fwhm0) a2 = int(2.*fwhm0+.5) a3 = int(3.*fwhm0+.5) a4 = int(4.*fwhm0+.5) ap = str(a1)+","+str(a2)+","+str(a3) ######################################## if _recenter: answ='yes' else: answ='no' ######################################### hdr=lsc.util.readhdr(img+'.fits') _gain=lsc.util.readkey3(hdr,'gain') _ron=lsc.util.readkey3(hdr,'ron') _exptime=lsc.util.readkey3(hdr,'exptime') iraf.noao.digiphot.daophot.photpars.zmag = 0 iraf.noao.digiphot.daophot.datapars.readnoi = _gain iraf.noao.digiphot.daophot.datapars.epadu = _ron iraf.noao.digiphot.daophot.datapars.datamin = dmin iraf.noao.digiphot.daophot.datapars.datamax = dmax iraf.noao.daophot.fitskypars.annulus=a3 iraf.noao.daophot.photpars.apertures = ap iraf.noao.digiphot.daophot.datapars.exposure = 'exptime' iraf.noao.digiphot.daophot.datapars.airmass = 'airmass' iraf.noao.digiphot.daophot.datapars.filter = 'filter2' iraf.noao.digiphot.daophot.daopars.psfrad = a4 # modify fitrad to 3 fwhm to see if works better iraf.noao.digiphot.daophot.daopars.fitrad = fwhm0 #* 3 iraf.noao.digiphot.daophot.daopars.sannulus = int(a4) iraf.noao.digiphot.daophot.daopars.recenter = answ iraf.noao.digiphot.daophot.daopars.fitsky = 'yes' # iraf.noao.digiphot.daophot.centerpars.cbox = 0 iraf.noao.digiphot.daophot.centerpars.cbox = 4 iraf.noao.digiphot.daophot.centerpars.calgori = 'gauss' # fitskypars.salgorithm = "constant" # fitskypars.skyvalue = 0 print '\n### recentering: '+str(answ) if _show: iraf.noao.digiphot.daophot.phot(original,coordlist,"apori",veri='no') iraf.noao.digiphot.daophot.phot(sn,coordlist,img+".sn.mag",veri='no') else: iraf.noao.digiphot.daophot.phot(original,coordlist,"apori",veri='no',verb='no') iraf.noao.digiphot.daophot.phot(sn,coordlist,img+".sn.mag",veri='no',verb='no') lsc.util.delete(img+".sn.als") print sn,imgpsf,img iraf.allstar(sn,img+".sn.mag",imgpsf,img+".sn.als","",residual,veri='no',verb='no') lsc.util.delete("snfit.fits") iraf.imarith(sn+'.fits',"-",residual+'.fits',"snfit.fits") lsc.util.delete("skyfit.fits") iraf.imarith(original+'.fits',"-","snfit.fits","skyfit.fits") iraf.txsort(img+".sn.als","ID") tmptbl = iraf.txdump(img+".sn.als","mag,merr,xcenter,ycenter",expr='yes', Stdout=1) magerr,fitmag,centx,centy=[],[],[],[] for i in tmptbl: try: fitmag.append(float(string.split(i)[0]))#-2.5*log10(_exptime)) except: fitmag.append(string.split(i)[0]) try: magerr.append(float(string.split(i)[1])) except: magerr.append(string.split(i)[1]) centx.append(float(string.split(i)[2])) centy.append(float(string.split(i)[3])) tmptbl=iraf.txdump("apori","mag",expr='yes', Stdout=1) apori1,apori2,apori3=[],[],[] for i in tmptbl: try: apori1.append(float(string.split(i)[0]))#-2.5*log10(_exptime)) except: apori1.append(string.split(i)[0]) try: apori2.append(float(string.split(i)[1]))#-2.5*log10(_exptime)) except: apori2.append(string.split(i)[1]) try: apori3.append(float(string.split(i)[2]))#-2.5*log10(_exptime)) except: apori3.append(string.split(i)[2]) iraf.txsort(img+".sn.mag","YCENTER") tmptbl=iraf.txdump(img+".sn.mag","mag,magerr",expr='yes', Stdout=1) if _show: print "********************************************************************" print "ID <apmag on original> <apmag on bgsubt> fitmag truemag err_fit" print " ",a1," ",a2," ",a3," ",a1," ",a2," ",a3 apmag1,apmag2,apmag3,truemag=[],[],[],[] for i in range(len(tmptbl)): try: apmag1.append(float(string.split(tmptbl[i])[0]))#-2.5*log10(_exptime)) except: apmag1.append(9999) try: apmag2.append(float(string.split(tmptbl[i])[1]))#-2.5*log10(_exptime)) except: apmag2.append(9999) try: apmag3.append(float(string.split(tmptbl[i])[2]))#-2.5*log10(_exptime)) except: apmag3.append(9999) try: truemag.append(fitmag[i]+float(apco0)) except: truemag.append('INDEF') if _show: print i,apori1[i],apori2[i],apori3[i],apmag1[i],apmag2[i],apmag3[i],fitmag[i],truemag[i],magerr[i] if _show: print "********************************************************************" if _show: print midpt,z11,z22 _tmp1,_tmp2,goon=lsc.util.display_image(original+'.fits',1, z11, z22, False, _xcen=.25, _ycen=.25, _xsize=.3, _ysize=.3) z01 = float(z11)-float(midpt) z02 = float(z22)-float(midpt) s1 = 1 s2 = -int(fwhm0) lsc.util.delete("tmptbl") ff=open('tmptbl','w') ff.write(str(s1)+' '+str(s2)+" ORIGINAL") ff.close() iraf.tvmark(1,"tmptbl",autol='no',mark="none",inter='no',label='yes',txsize=2) _tmp1,_tmp2,goon=lsc.util.display_image('snfit.fits',1, z01, z02, False, _xcen=.25, _ycen=.75, _xsize=.3, _ysize=.3, _erase='no') lsc.util.delete("tmptbl") tmptbl0=iraf.txdump(img+".sn.als","xcen,ycen",expr='yes',Stdout=1) ff=open('tmptbl','w') for i in tmptbl0: ff.write(i+'\n') ff.close() lra = int((2*float(size)*float(fwhm0))*2) iraf.tvmark(1,"tmptbl",autol='no',mark="circle", number='yes',nyoffset=lra,radi=a2,txsize=2,inter='no') s1 = 1 s2 = -1*int(fwhm0) lsc.util.delete("tmptbl") ff=open('tmptbl','w') ff.write(str(s1)+' '+str(s2)+" FITTED") ff.close() iraf.tvmark(1,"tmptbl",autol='no',mark="none",inter='no',label='yes',txsize=2) _tmp1,_tmp2,goon=lsc.util.display_image('skyfit.fits',1, z11, z22, False, _xcen=.75, _ycen=.25, _xsize=.3, _ysize=.3, _erase='no') s1 = 1 s2 = -1*int(fwhm0) lsc.util.delete("tmptbl") ff=open('tmptbl','w') ff.write(str(s1)+' '+str(s2)+" RESIDUAL") ff.close() iraf.tvmark(1,"tmptbl",autol='no',mark="none",inter='no',label='yes',txsize=2) return apori1,apori2,apori3,apmag1,apmag2,apmag3,fitmag,truemag,magerr,centx,centy
# Access to the iqutils from iqutils import * import iqpkg # Necessary packages iraf.images() iraf.immatch() iraf.noao() iraf.imred() iraf.ccdred() iraf.digiphot() iraf.daophot() iraf.photcal() iraf.images() iraf.imcoords() yes = iraf.yes no = iraf.no INDEF = iraf.INDEF hedit = iraf.hedit imgets = iraf.imgets imcombine = iraf.imcombine pyrafdir = "python/pyraf/" pyrafdir_key = 'PYRAFPARS' if os.environ.has_key(pyrafdir_key): pardir = os.environ[pyrafdir_key] else: pardir = os.environ['HOME'] + '/' + pyrafdir
distvec, pos0, pos1 = crossmatch(_rasex, _decsex, [_ra], [_dec], 5) else: targ = agnkey.agnsqldef.targimg(img) aa = agnkey.agnsqldef.query(['select ra_sn,dec_sn from lsc_sn_pos where id="' + str(targ) + '"']) if len(aa) > 0: rasn = aa[0]['ra_sn'] decsn = aa[0]['dec_sn'] else: rasn = '' decsn = '' if rasn and decsn: from pyraf import iraf iraf.astcat(_doprint=0) iraf.imcoords(_doprint=0) iraf.digiphot(_doprint=0) iraf.daophot(_doprint=0) lll = [str(rasn) + ' ' + str(decsn)] sss = iraf.wcsctran('STDIN', 'STDOUT', re.sub('sn2.','',img)+'[0]', Stdin=lll, inwcs='world', units='degrees degrees', outwcs='logical', columns='1 2', formats='%10.1f %10.1f', Stdout=1) if _verbose: iraf.display(re.sub('sn2.','',img)+'[0]',fill='yes',frame=1) iraf.tvmark(1, 'STDIN', Stdin = list(sss) ,mark = "circle" , number = 'yes' ,label = 'no' , radii = 10, nxoffse = 5, nyoffse = 5, color = 204, txsize = 2) if 'diff' in img: diffimg = re.sub('diff.sn2.','',img) iraf.display(diffimg+'[0]',fill='yes',frame=2) iraf.tvmark(2, 'STDIN', Stdin = list(sss) ,mark = "circle" , number = 'yes' ,label = 'no' ,
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'