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
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
def fitsn(_recenter, img, imgpsf, fwhm0, apco0, z22, z11, midpt, size, nor, _values, DM): from pyraf import iraf import string, os, sys from numpy import log10 a1 = int(fwhm0 + .5) a2 = int(2. * fwhm0 + .5) a3 = int(3. * fwhm0 + .5) a4 = int(4. * fwhm0 + .5) a5 = int(5. * fwhm0 + .5) ap = str(a1) + "," + str(a2) + "," + str(a3) iraf.digiphot(_doprint=0) iraf.daophot(_doprint=0) from iraf import digiphot from iraf import daophot from iraf import ptools zmag = 0 iraf.noao.digiphot.daophot.photpars.zmag = zmag iraf.delete("apori", verify='no') iraf.delete(img + ".sn.mag", verify='no') iraf.noao.digiphot.daophot.phot("original", img + ".sn.coo", "apori", veri='no') iraf.noao.digiphot.daophot.phot("sn", img + ".sn.coo", img + ".sn.mag", veri='no') iraf.noao.digiphot.daophot.daopars.psfrad = a4 iraf.noao.digiphot.daophot.daopars.fitrad = fwhm0 iraf.noao.digiphot.daophot.daopars.fitsky = 'no' iraf.noao.digiphot.daophot.daopars.sannulus = int(a4) if _recenter: answ = raw_input(">>> recentering for targets [yes/no] ? [yes] ") if not answ: answ = 'yes' else: answ = 'yes' iraf.noao.digiphot.daophot.daopars.recenter = answ iraf.noao.digiphot.daophot.daopars.fitsky = 'yes' iraf.delete(img + ".sn.als", verify='no') iraf.allstar("sn", img + ".sn.mag", imgpsf, img + ".sn.als", "", "residual", veri='no', verb='no') iraf.delete("snfit.fits", verify='no') iraf.imarith("sn", "-", "residual", "snfit") iraf.delete("skyfit.fits", verify='no') iraf.imarith("original", "-", "snfit", "skyfit") 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(nor)) except: fitmag.append('INDEF') try: magerr.append(float(string.split(i)[1])) except: magerr.append('INDEF') 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]) - float(_values) - float(DM)) #+2.5*log10(nor) except: apori1.append('INDEF') try: apori2.append( float(string.split(i)[1]) - float(_values) - float(DM)) #+2.5*log10(nor) except: apori2.append('INDEF') try: apori3.append( float(string.split(i)[2]) - float(_values) - float(DM)) #+2.5*log10(nor) except: apori3.append('INDEF') iraf.txsort(img + ".sn.mag", "YCENTER") tmptbl = iraf.txdump(img + ".sn.mag", "mag,magerr", expr='yes', Stdout=1) 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]) - float(_values) - float(DM)) #+2.5*log10(nor) except: apmag1.append('INDEF') try: apmag2.append( float(string.split(tmptbl[i])[1]) - float(_values) - float(DM)) #+2.5*log10(nor) except: apmag2.append('INDEF') try: apmag3.append( float(string.split(tmptbl[i])[2]) - float(_values) - float(DM)) #+2.5*log10(no) except: apmag3.append('INDEF') try: truemag.append( float(fitmag[i]) + float(apco0) + 2.5 * log10(nor) - float(_values) - float(DM)) except: truemag.append('INDEF') print i, apori1[i], apori2[i], apori3[i], apmag1[i], apmag2[i], apmag3[ i], fitmag[i], truemag[i], magerr[i] print "********************************************************************" iraf.display("original", 1, fill='yes', xcen=.25, ycen=.25, xsize=.3, ysize=.3, zscal='no', zrang='no', z2=z22, z1=z11) z01 = z11 - midpt z02 = z22 - midpt s1 = 1 s2 = -int(fwhm0) iraf.delete("tmptbl", ve='no') 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) iraf.display("snfit", 1, erase='no', fill='yes', xcen=.25, ycen=.75, xsize=.3, ysize=.3, zscal='no', zrang='no', z2=z02, z1=z01) iraf.delete("tmptbl", ve='no') 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) iraf.delete("tmptbl", ve='no') 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) iraf.display("skyfit", 1, erase='no', fill='yes', xcen=.75, ycen=.25, xsize=.3, ysize=.3, zscal='no', zrang='no', z2=z22, z1=z11) s1 = 1 s2 = -1 * int(fwhm0) iraf.delete("tmptbl", ve='no') 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) print '###' print '### magnitude scaled to target exposure time using: ' + str( 2.5 * log10(nor)) print '### fit magnitude corrected with aperture correction: ' + str( float(apco0)) print '### magnitude scaled to target using DM: ' + str(DM) print '###' return apori1, apori2, apori3, apmag1, apmag2, apmag3, fitmag, truemag, magerr, centx, centy