def frame_offset(setup, total_sci_ext, fits_number): #The fits_number counter serves to help us select which rows in the .tab file we want to use in our median evaluation. We want to be taking the median value of the XX slit median values for the given frame. Since the .tab file is appended to for all Z number of files we need to determine which rows to use with which file <- the fits_number iterator and knowing the number of science extensions determine which rows to use. end_row = total_sci_ext * fits_number beg_row = (total_sci_ext * fits_number) - (total_sci_ext-1) print 'Taking the median value from rows: %s - %s in the %s file for file #%d of the file list' % (beg_row, end_row, '*_lambdaoff.tab', fits_number) #This is reading the median column of the unrestricted dlambda table. #It determines the number of rows and runs statistics over all the rows selected #The statistics (mean, stddev, median, min, max) will be run on the median values of each slit to give an overall offset value iraf.tstat('%s_lambdaoff.tab' % config,'median',outtable='%s_lambdaoffmed.tab' % config, row='%s - %s' % (beg_row, end_row), Stdout=0) #This is printing out the final offset value (median from *lambdaoffall.tab) which is to be applied to all slits in the same file iraf.tprint('%s_lambdaoffmed.tab' % config, col='median',showr='no',showh='no',row=str(fits_number)) #here I'm printing out the offset value from the table and assigning it to 'offset'; it's a list so I'll change it to a float next offset = iraf.tprint('%s_lambdaoffmed.tab' % config, col='median',showr='no',showh='no',row=str(fits_number), Stdout=1) #offset comes out as redirected output from tprint and needs to be changed to the appropriate form offset_value = [line.strip() for line in offset] if offset_value[0] == 'INDEF': IPython.embed() #INDEF comes from the lines not being found offset_value = float(offset_value[0]) return offset_value
def run_elli(input, xcntr, ycntr, eg, pa, sma):#,radd,background): iraf.stsdas(_doprint=0) iraf.tables(_doprint=0) iraf.stsdas.analysis(_doprint=0) iraf.stsdas.analysis.isophote(_doprint=0) image_exist = 1 if(str(input)[:3] == 'ima'): output = 'elli_' + input[6:-4] + 'txt' if(str(input)[:3] == 'out'): output = 'out_elli_' + str(input)[4:-7] + 'txt' #unlearn geompar controlpar samplepar magpar ellipse iraf.geompar(x0=xcntr, y0=ycntr, ellip0=eg, pa0=pa, sma0=10, minsma=0.1, \ maxsma=sma*5.0, step=0.1,recente="yes") iraf.controlpar(conver=0.05, minit=10, maxit=50, hcenter="no", hellip="no",\ hpa="no", wander="", maxgerr=0.5, olthres=1,soft="no") iraf.samplepar(integrm="bi-linear", usclip=3,lsclip=3, nclip=0, fflag=0.5) iraf.magpar(mag0=0, refer=1, zerolev=0) iraf.ellipse("".join(input), output="test", interac="no",Stdout="ellip", \ Stderr="err") iraf.tprint("test.tab", prparam="no", prdata="yes", pwidth=80, plength=0, \ showrow="no", orig_row="no", showhdr="no", showunits="no", \ columns="SMA, INTENS, INT_ERR, MAG, MAG_LERR, MAG_UERR",\ rows="-", \ option="plain", align="yes", sp_col="", lgroup=0, Stdout=output) for myfile in ['ellip','err','test.tab']: if os.access(myfile,os.F_OK): os.remove(myfile)
def run_elli_full(cutimage, output, xcntr, ycntr, eg, pa, sma, sky): #,radd,background): """The function responsible for fit ellipse""" EllGal = c.outdir + 'GalEllFit.fits' fEl = pyfits.open(os.path.join(c.datadir, cutimage)) GaLaXy = fEl[0].data fEl.close() GaLaXy = GaLaXy - sky hdu = pyfits.PrimaryHDU(GaLaXy.astype(n.float32)) hdu.writeto(EllGal) try: iraf.stsdas(_doprint=0) iraf.tables(_doprint=0) iraf.stsdas.analysis(_doprint=0) iraf.stsdas.analysis.isophote(_doprint=0) except: iraf.stsdas() iraf.tables() iraf.stsdas.analysis() iraf.stsdas.analysis.isophote() image_exist = 1 iraf.unlearn('geompar') iraf.geompar.x0 = xcntr iraf.geompar.y0 = ycntr iraf.geompar.ellip0 = eg iraf.geompar.pa0 = pa iraf.geompar.sma0 = 6.0 iraf.geompar.minsma = 0.1 iraf.geompar.maxsma = sma * 5.0 iraf.geompar.step = 0.1 iraf.geompar.recente = "no" iraf.geompar.xylearn = "no" iraf.unlearn('controlpar') iraf.controlpar.conver = 0.05 iraf.controlpar.minit = 10 iraf.controlpar.maxit = 50 iraf.controlpar.hcenter = "no" iraf.controlpar.hellip = "no" iraf.controlpar.hpa = "no" iraf.controlpar.wander = "INDEF" iraf.controlpar.maxgerr = 0.5 iraf.controlpar.olthres = 1 iraf.controlpar.soft = "no" iraf.samplepar.integrm = "bi-linear" iraf.samplepar.usclip = 3 iraf.samplepar.lsclip = 3 iraf.samplepar.nclip = 0 iraf.samplepar.fflag = 0.5 iraf.unlearn('ellipse') iraf.ellipse("".join(EllGal), output="test", interac="no",Stdout="ellip", \ Stderr="err") iraf.tprint("test.tab", prparam="no", prdata="yes", pwidth=80, plength=0, \ showrow="no", orig_row="no", showhdr="no", showunits="no", \ columns="SMA, INTENS, INT_ERR, ELLIP, ELLIP_ERR, PA, PA_ERR, \ MAG, MAG_LERR, MAG_UERR, TMAG_E, TMAG_C, A3, \ A3_ERR, B3, B3_ERR, A4, A4_ERR, B4_ERR" , rows="-", \ option="plain", align="yes", sp_col="", lgroup=0, Stdout=output) for myfile in ['ellip', 'err', 'test.tab', EllGal]: if os.access(c.outdir + myfile, os.F_OK): os.remove(c.outdir + myfile)
def run_ell(file_in, file_tab, file_dat, mag, **ellipse_par): # prochaine etape : mettre en argument sous une certaine forme les parametres associes epar des taches 1) strict minimum sous forme de dico fixe 2) tout pouvoir changer sous forme de dictionnaire et tester les cles ... # import iraf packages iraf.stsdas() iraf.analysis() iraf.isophote() p = Popen("ds9", shell = True) time.sleep(5) iraf.display(file_in, 1) set_iraf_param(ellipse_par) # iraf.lpar(iraf.geompar) iraf.ellipse(file_in, file_tab, mag0 = str(mag), verbose = "no") # iraf.lpar(iraf.isoimap) iraf.isoimap(file_in, file_tab) iraf.tproject(file_tab, "temp.fits", "SMA,INTENS,INT_ERR,ELLIP,ELLIP_ERR, PA, PA_ERR, X0, Y0, TFLUX_C, TMAG_E,NPIX_E") iraf.tprint("temp.fits", pwidth = 200, Stdout = file_dat) iraf.imdel("temp.fits") p.kill()
def run_elli_full(input, output, xcntr, ycntr, eg, pa, sma, sky):#,radd,background): """The function responsible for fit ellipse""" EllGal = 'GalEllFit.fits' fEl = pyfits.open(input) GaLaXy = fEl[0].data fEl.close() GaLaXy = GaLaXy - sky hdu = pyfits.PrimaryHDU(GaLaXy.astype(n.float32)) hdu.writeto(EllGal) try: iraf.stsdas(_doprint=0) iraf.tables(_doprint=0) iraf.stsdas.analysis(_doprint=0) iraf.stsdas.analysis.isophote(_doprint=0) except: iraf.stsdas() iraf.tables() iraf.stsdas.analysis() iraf.stsdas.analysis.isophote() image_exist = 1 iraf.unlearn('geompar') iraf.geompar.x0=xcntr iraf.geompar.y0=ycntr iraf.geompar.ellip0=eg iraf.geompar.pa0=pa iraf.geompar.sma0=6.0 iraf.geompar.minsma=0.1 iraf.geompar.maxsma=sma*5.0 iraf.geompar.step=0.1 iraf.geompar.recente="no" iraf.geompar.xylearn="no" iraf.unlearn('controlpar') iraf.controlpar.conver=0.05 iraf.controlpar.minit=10 iraf.controlpar.maxit=50 iraf.controlpar.hcenter="no" iraf.controlpar.hellip="no" iraf.controlpar.hpa="no" iraf.controlpar.wander="INDEF" iraf.controlpar.maxgerr=0.5 iraf.controlpar.olthres=1 iraf.controlpar.soft="no" iraf.samplepar.integrm="bi-linear" iraf.samplepar.usclip=3 iraf.samplepar.lsclip=3 iraf.samplepar.nclip=0 iraf.samplepar.fflag=0.5 iraf.unlearn('ellipse') iraf.ellipse("".join(EllGal), output="test", interac="no",Stdout="ellip", \ Stderr="err") iraf.tprint("test.tab", prparam="no", prdata="yes", pwidth=80, plength=0, \ showrow="no", orig_row="no", showhdr="no", showunits="no", \ columns="SMA, INTENS, INT_ERR, ELLIP, ELLIP_ERR, PA, PA_ERR, \ MAG, MAG_LERR, MAG_UERR, TMAG_E, TMAG_C, A3, \ A3_ERR, B3, B3_ERR, A4, A4_ERR, B4_ERR", rows="-", \ option="plain", align="yes", sp_col="", lgroup=0, Stdout=output) for myfile in ['ellip','err','test.tab', EllGal]: if os.access(myfile,os.F_OK): os.remove(myfile)
def run_elli(input, output, xcntr, ycntr, eg, pa, sma):#,radd,background): """The function resposible for fit ellipse""" iraf.stsdas(_doprint=0) iraf.tables(_doprint=0) iraf.stsdas.analysis(_doprint=0) iraf.stsdas.analysis.isophote(_doprint=0) image_exist = 1 # if(str(input)[:3] == 'ima'): # output = 'elli_' + input[6:-4] + 'txt' # if(str(input)[:3] == 'out'): # output = 'out_elli_' + str(input)[4:-7] + 'txt' # else: # output = 'elli_' + input[:-5] + '.txt' #unlearn geompar controlpar samplepar magpar ellipse iraf.unlearn('geompar') iraf.geompar.x0=xcntr iraf.geompar.y0=ycntr iraf.geompar.ellip0=eg iraf.geompar.pa0=pa iraf.geompar.sma0=10 iraf.geompar.minsma=0.1 iraf.geompar.maxsma=sma*5.0 iraf.geompar.step=0.1 iraf.geompar.recente="no" iraf.geompar.xylearn="no" iraf.unlearn('controlpar') iraf.controlpar.conver=0.05 iraf.controlpar.minit=10 iraf.controlpar.maxit=50 iraf.controlpar.hcenter="no" iraf.controlpar.hellip="no" iraf.controlpar.hpa="no" iraf.controlpar.wander="INDEF" iraf.controlpar.maxgerr=0.5 iraf.controlpar.olthres=1 iraf.controlpar.soft="no" iraf.samplepar.integrm="bi-linear" iraf.samplepar.usclip=3 iraf.samplepar.lsclip=3 iraf.samplepar.nclip=0 iraf.samplepar.fflag=0.5 iraf.magpar.mag0=c.mag_zero iraf.magpar.refer=1 iraf.magpar.zerolev=0 iraf.ellipse("".join(input), output="test", interac="no",Stdout="ellip", \ Stderr="err") iraf.tprint("test.tab", prparam="no", prdata="yes", pwidth=80, plength=0, \ showrow="no", orig_row="no", showhdr="no", showunits="no", \ columns="SMA, INTENS, INT_ERR, MAG, MAG_LERR, MAG_UERR, \ TFLUX_E", rows="-", \ option="plain", align="yes", sp_col="", lgroup=0, Stdout=output) for myfile in ['ellip','err','test.tab']: if os.access(myfile,os.F_OK): os.remove(myfile)
except getopt.error as e: print(str(e)) usage() _out_width = 80 _show_row = no _column_names = no _align_cols = no if optlist: for opt, value in optlist: if opt in( "-s", "--showrow"): _show_row = yes elif opt in ("-c", "--colnames"): _column_names = yes elif opt in ("-a", "--align"): _align_cols = yes elif opt in ("-h", "--help"): usage() else: print("Program bug, uninterpreted option", opt) raise SystemExit del getopt iraf.tprint(args[0],prparam=no,prdata=yes,pwidth=_out_width, plength=0,showrow=_show_row,orig_row=yes,showhdr=_column_names, showunits=yes,columns="",rows="-",option="plain",align=_align_cols, sp_col="",lgroup=0,mode="h")
#!/usr/bin/env python print('This version of galTables works for *cutout-24-rot.tab files and *cutout-sdss.tab files. If you are not using rotated 24m files then use galTablesv2.py') from pylab import * import glob from pyraf import iraf import os iraf.stsdas() iraf.analysis() iraf.toolbox() iraf.ttools() flag = str(raw_input('Which files? a=24 b=sdss ')) flag = str(flag) if flag.find('a') > -1: tabfiles = glob.glob('*cutout-24-rot.tab') if flag.find('b') > -1: tabfiles = glob.glob('*cutout-sdss.tab') #tabfiles=glob.glob('*.tab') #print tabfiles for i in range(len(tabfiles)): tfile = tabfiles[i] nfile = tfile.split('.') dfile = nfile[0]+'.dat' print tfile,' -> ',dfile iraf.tprint(table=tfile,pwidth='INDEF',showhdr='no',showunits='no',Stdout=dfile)
def runellipse(files, xcenter, ycenter, minr, ipa, initialr, maxr, iellip, nframe=1, myradius=15): initialradius = myradius for i in range(len(files)): myradius = initialradius mfile = files[i] #mask image outfile1 = 'm' + mfile continueWithProgram, continueWithObject = runimedit( mfile, outfile1, nframe) if not continueWithProgram: print "quitting program" return if not continueWithObject: print "going on to next image" continue #run ellipse t = mfile.split('.') efile = t[0] + '.tab' imprefix = t[0] print mfile, imprefix print 'Running ellipse to fit isophotes to galaxy:' try: os.remove(efile) except OSError: print 'everything is ok' print "First pass, letting PA and e vary" iraf.ellipse(input=outfile1, output=efile, x0=xcenter, y0=ycenter, hcenter='no', sma0=initialr, minsma=minr, maxsma=maxr, pa=ipa, hpa='no', ellip=iellip, hellip='no') print 'Displaying isophotes from first pass. Hit q in DS9 window to quit' iraf.isoexam(table=efile) os.system('rm junk.txt') iraf.tprint(table=efile, pwidth='INDEF', showhdr='no', Stdout='junk.txt') os.system("awk '{print $2, $7, $9, $11, $13}' < junk.txt > junk2.txt") #run ellipse a second time, keeping PA and ellip fixed #allow user to adjust the radius where PA and ellip are measured repeatflag = 1 while (repeatflag > 0.1): infile = open('junk2.txt', 'r') for line in infile: t = line.split() if float(t[0]) > myradius: newellip = float(t[1]) if newellip < .05: #min value that ellipse can handle newellip = .05 newPA = float(t[2]) if newPA < -90: newPA = newPA + 180 elif newPA > 90: newPA = newPA - 180 #11 - X0, 13 - Y0 newxcenter = float(t[3]) newycenter = float(t[4]) break s = 'rm ' + efile os.system(s) iraf.ellipse(input=outfile1, output=efile, x0=newxcenter, y0=newycenter, hcenter='yes', sma0=initialr, minsma=minr, maxsma=maxr, pa=newPA, hpa='yes', ellip=newellip, hellip='yes') print 'Displaying isophotes from second pass using r = ', myradius print 'Hit q in the DS9 window to quit' iraf.isoexam(table=efile) flag = str( raw_input('Are you happy with the fit? y=yes n=no x=quit ')) flag = str(flag) print 'this is what I think you typed ', flag if flag.find('n') > -1: flag2 = str( raw_input( 'What is the problem? c=off-center r=set new radius x=quit ' )) flag2 = str(flag2) if flag2.find('r') > -1: myr = input('Enter new radius to use ') myradius = float(myr) s = 'rm ' + efile os.system(s) repeatflag = 1 elif flag2.find('x') > -1: repeatflag = 0 return elif flag2.find('c') > -1: s = 'mv *' + imprefix + '* OffCenter/' print s os.system(s) repeatflag = 0 print "repeatflag = ", repeatflag elif flag.find('x') > -1: repeatflag = 0 print 'i think repeatflag = 0', repeatflag return else: s = 'mv *' + imprefix + '* Finished/' os.system(s) repeatflag = 0 print 'i think repeatflag = 0 ', repeatflag print 'repeatflag = ', repeatflag
def runellipseold(files,xcenter,ycenter,minr,ipa,initialr,maxr,iellip,nframe=1,myradius=15): initialradius=myradius for i in range(len(files)): myradius=initialradius mfile=files[i] #mask image outfile1='m'+mfile continueWithProgram,continueWithObject=runimedit(mfile,outfile1,nframe) if not continueWithProgram: print "quitting program" return if not continueWithObject: print "going on to next image" continue #run ellipse t=mfile.split('.') efile=t[0]+'.tab' imprefix=t[0] print mfile, imprefix print 'Running ellipse to fit isophotes to galaxy:' try: os.remove(efile) except OSError: print 'everything is ok' print "First pass, letting PA and e vary" iraf.ellipse(input=outfile1,output=efile,x0=xcenter,y0=ycenter,hcenter='no',sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='no',ellip=iellip,hellip='no') print 'Displaying isophotes from first pass. Hit q in DS9 window to quit' iraf.isoexam(table=efile) os.system('rm junk.txt') iraf.tprint(table=efile,pwidth='INDEF',showhdr='no', Stdout='junk.txt') os.system("awk '{print $2, $7, $9, $11, $13}' < junk.txt > junk2.txt") #run ellipse a second time, keeping PA and ellip fixed #allow user to adjust the radius where PA and ellip are measured repeatflag=1 while (repeatflag > 0.1): infile=open('junk2.txt','r') for line in infile: t=line.split() if float(t[0]) > myradius: newellip=float(t[1]) if newellip < .05:#min value that ellipse can handle newellip=.05 newPA=float(t[2]) if newPA < -90: newPA=newPA+180 elif newPA > 90: newPA = newPA-180 #11 - X0, 13 - Y0 newxcenter=float(t[3]) newycenter=float(t[4]) break s='rm '+efile os.system(s) iraf.ellipse(input=outfile1,output=efile,x0=newxcenter,y0=newycenter,hcenter='yes',sma0=initialr,minsma=minr,maxsma=maxr,pa=newPA,hpa='yes',ellip=newellip,hellip='yes') print 'Displaying isophotes from second pass using r = ',myradius print 'Hit q in the DS9 window to quit' iraf.isoexam(table=efile) flag=str(raw_input('Are you happy with the fit? y=yes n=no x=quit ')) flag=str(flag) print 'this is what I think you typed ',flag if flag.find('n') > -1: flag2=str(raw_input('What is the problem? c=off-center r=set new radius x=quit ')) flag2=str(flag2) if flag2.find('r') > -1: myr=input('Enter new radius to use ') myradius=float(myr) s='rm '+efile os.system(s) repeatflag=1 elif flag2.find('x') > -1: repeatflag=0 return elif flag2.find('c') > -1: s='mv *'+imprefix+'* OffCenter/' print s os.system(s) repeatflag=0 print "repeatflag = ",repeatflag elif flag.find('x') > -1: repeatflag=0 print 'i think repeatflag = 0', repeatflag return else: s='mv *'+imprefix+'* Finished/' os.system(s) repeatflag=0 print 'i think repeatflag = 0 ', repeatflag print 'repeatflag = ',repeatflag
def runellipse(files,xcenter,ycenter,minr,ipa,initialr,maxr,iellip,nframe=1,myradius=15): initialradius=myradius #print 'got here' #print files for i in range(len(files)): myradius=initialradius mfile=files[i] #mask image outfile1='m'+mfile if os.path.isfile(outfile1): print "found masked file ",outfile1 print "skipping imedit and running ellipse interactively" continueWithProgram=1 continueWithObject=1 else: print "can't find masked file ",outfile1 print "running imedit" continueWithProgram,continueWithObject=runimedit(mfile,outfile1,nframe) if not continueWithProgram: print "quitting program" return if not continueWithObject: print "going on to next image" continue #run ellipse t=mfile.split('.') efile=t[0]+'.tab' imprefix=t[0] try: os.remove(efile) except OSError: print 'everything is ok' #continue print "First pass through ellipse to find center" iraf.ellipse(input=outfile1,output=efile,x0=xcenter,y0=ycenter,hcenter='no',sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='no',ellip=iellip,hellip='no',interactive='no') #print 'Displaying isophotes from first pass. Hit q in DS9 window to quit' #iraf.isoexam(table=efile) os.system('rm junk.txt') iraf.tprint(table=efile,pwidth='INDEF',showhdr='no', Stdout='junk.txt') os.system("awk '{print $2, $7, $9, $11, $13}' < junk.txt > junk2.txt") #run ellipse a second time, keeping PA and ellip fixed #allow user to adjust the radius where PA and ellip are measured infile=open('junk2.txt','r') for line in infile: t=line.split() if float(t[0]) > myradius: newxcenter=float(t[3]) newycenter=float(t[4]) break s='rm '+efile os.system(s) #draw ellipse with ds9 iraf.display(outfile1,1) (myellip,mypa)=findellipse(outfile1,newxcenter,newycenter) flag2=str(raw_input('Do you want to skip this one? y=skip, any other key to continue ')) if flag2.find('y') > -1: s='mv *'+imprefix+'* ../PeculiarGalaxies/' print s os.system(s) continue #run ellipse interactively #allow user to repeat until satisfied with script repeatflag=1 while repeatflag: s='rm '+efile os.system(s) iraf.ellipse(input=outfile1,output=efile,x0=newxcenter,y0=newycenter,hcenter='yes',sma0=initialr,minsma=minr,maxsma=maxr,pa0=mypa,hpa='yes',ellip0=myellip,hellip='yes',interactive='no') print 'Displaying isophotes from second pass using r = ',myradius print 'Hit q in the DS9 window to quit' iraf.isoexam(table=efile) flag=str(raw_input('Are you happy with the fit? y=yes n=no x=quit ')) flag=str(flag) print 'this is what I think you typed ',flag if flag.find('n') > -1: s='rm '+efile os.system(s) repeatflag=1 elif flag.find('x') > -1: repeatflag=0 print 'i think repeatflag = 0', repeatflag return else: s='mv *'+imprefix+'* ../Finished/' os.system(s) repeatflag=0 print 'i think repeatflag = 0 ', repeatflag print 'repeatflag = ',repeatflag
def measure_disk(input_image, xcenter, ycenter, ipa, iellip, initialr, minr, maxr, zp, band=0, nframe=1, myradius=25, keepfixed=0, einteractive=0, mask_image=None): print 'inside measure disk' print 'mask image = ', mask_image myradius = initialr recentervalue = 'yes' interactivevalue = 'no' print '\n Running ellipse on ', input_image, '\n' mfile = input_image xcenter_cutout = xcenter ycenter_cutout = ycenter t = mfile.split('.') efile = t[0] + '.tab' efile_ascii = t[0] + '.dat' imprefix = t[0] print 'Running ellipse to fit isophotes to galaxy:', mfile if os.path.exists(efile): os.remove(efile) if keepfixed: print input_image, efile, xcenter_cutout, ycenter_cutout, initialr, minr, maxr, ipa iraf.ellipse(input=input_image, output=efile, dqf=mask_image, x0=xcenter_cutout, y0=ycenter_cutout, hcenter='yes', recenter=recentervalue, sma0=initialr, minsma=minr, maxsma=maxr, pa=ipa, hpa='yes', ellip=iellip, hellip='yes', interactive='yes', step=0.1, linear='no') else: print "First pass, letting PA and e vary" print input_image, efile, xcenter_cutout, ycenter_cutout, initialr, minr, maxr, ipa, if mask_image == None: iraf.ellipse(input=input_image, output=efile, x0=xcenter_cutout, y0=ycenter_cutout, hcenter='no', recenter=0, sma0=initialr, minsma=minr, maxsma=maxr, pa=ipa, hpa='no', ellip=iellip, hellip='no', interactive=einteractive, step=0.1, linear='no') else: iraf.ellipse(input=input_image, output=efile, dqf=mask_image, x0=xcenter_cutout, y0=ycenter_cutout, hcenter='no', recenter=0, sma0=initialr, minsma=minr, maxsma=maxr, pa=ipa, hpa='no', ellip=iellip, hellip='no', interactive='yes', step=0.1, linear='no') print 'Displaying isophotes from first pass. Hit q in DS9 window to quit' iraf.isoexam(table=efile) try: os.system('rm tp.00*') except: print 'no tp.00? files to remove' iraf.isoimap(input_image, table=efile) # get final ellipse parameters to return to the user if os.path.exists('junk.txt'): os.remove('junk.txt') iraf.tprint(table=efile, pwidth='INDEF', showhdr='no', Stdout='junk.txt') s = "awk '{print $2, $7, $9, $11, $13}' < " + "junk.txt > " + "junk2.txt" os.system(s) infile = open('junk2.txt', 'r') for line in infile: t = line.split() if float(t[0]) > myradius: newellip = float(t[1]) if newellip < .05: # min value that ellipse can handle newellip = .05 newPA = float(t[2]) if newPA < -90: newPA = newPA + 180 elif newPA > 90: newPA = newPA - 180 newxcenter = float(t[3]) newycenter = float(t[4]) if os.path.exists(efile_ascii): os.remove(efile_ascii) iraf.tprint(table=efile, pwidth='INDEF', showhdr='no', Stdout=efile_ascii) return newxcenter, newycenter, newellip, newPA
def ellipse(image, outname, verbose=False, **kwargs): """run ellipse task image : input image name outname : output filename Keywords: *geompar* x0, y0 -- required ellip0 : initial ellipticity (default=0.2) pa0 : initial PA in degrees ccw from +y (default=20) sma0 : initial semi-major axis (default=10) minsma : minimum sma (default=1) maxsma : maximum sma (default='INDEF') step : sma step size (default=0.1) linear : linear sampling of sma? (default='no') *controlpar* conver : """ # verify input if 'x0' not in kwargs.keys() or 'y0' not in kwargs.keys(): raise KeyError('x0 or y0 is not found') # load packages iraf.stsdas(_doprint=0, motd=False) iraf.analysis(_doprint=0) iraf.isophote(_doprint=0) # reset all parameters iraf.unlearn('ellipse', 'geompar', 'controlpar', 'samplepar') iraf.ellipse.interactive = False iraf.ellipse.xylearn = False # if True, it prompts input upon faling to find center # geompar iraf.ellipse.x0 = kwargs.pop('x0') iraf.ellipse.y0 = kwargs.pop('y0') iraf.ellipse.ellip0 = kwargs.pop('ellip0', 0.2) iraf.ellipse.pa0 = kwargs.pop('pa0', 20.0) iraf.ellipse.sma0 = kwargs.pop('sma0', 10.0) iraf.ellipse.minsma = kwargs.pop('minsma', 1.) iraf.ellipse.maxsma = kwargs.pop('maxsma', 'INDEF') iraf.ellipse.step = kwargs.pop('step', 0.1) iraf.ellipse.linear = kwargs.pop('linear', 0) iraf.ellipse.verbose = verbose # controlpar iraf.ellipse.conver = kwargs.pop('conver', 0.05) iraf.ellipse.minit = kwargs.pop('minit', 10) iraf.ellipse.maxit = kwargs.pop('maxit', 50) iraf.ellipse.hcenter = kwargs.pop('hcenter', 'no') # samplepar iraf.ellipse.tsample = kwargs.pop('tsample', 'none') iraf.ellipse.harmonics = kwargs.pop('harmonics', 'none') if verbose: iraf.lparam('ellipse') iraf.lparam('geompar') iraf.lparam('controlpar') iraf.lparam('samplepar') # run ellipse tempname = shorten_iauname(image) + str(uuid.uuid4()) + '.tab' try: iraf.ellipse(image, tempname) # print ascii table iraf.tprint(tempname, pwidth='INDEF', Stdout=outname) os.remove(tempname) except: print 'ellipse failed'
def runEllipse24UsingSDSS(self): agcnumber=self.agcnumber[self.ellipseflag] #mcutoutpath='/home/rfinn/research/LocalClusters/MaskedCutouts/'+self.prefix+'/' mcutoutpath='/home/rfinn/research/LocalClusters/MaskedCutouts/'+self.prefix+'/' os.chdir(mcutoutpath) s=outpathroot+'research/LocalClusters/Ellipse24UsingSDSS/'+self.prefix try: os.mkdir(s) except OSError: pass for i in range(len(agcnumber)): print agcnumber[i] sdssEllipseTable= '/home/rfinn/research/LocalClusters/EllipseTables/'+self.prefix+'/'+self.prefix+'-'+str(agcnumber[i])+'-cutout-sdss.tab' #mipsImage=mcutoutpath+'m'+self.prefix+'-'+str(agcnumber[i])+'-cutout-24-rot.fits' mipsImage='m'+self.prefix+'-'+str(agcnumber[i])+'-cutout-24-rot.fits' #outim=cutoutpath+self.prefix+'-'+str(agcSpiral[i])+'-cutout-sdss.fits \n' os.system('rm junk.txt') if os.path.isfile(sdssEllipseTable): iraf.tprint(table=sdssEllipseTable,pwidth='INDEF',showhdr='no', Stdout='junk.txt') os.system("awk '{print $2, $7, $9, $11, $13}' < junk.txt > junk2.txt") else: print 'Warning: ',sdssEllipseTable,' does not exist' sdssEllipseTable= '/home/rfinn/research/LocalClusters/EllipseTables/'+self.prefix+'/'+self.prefix+'-'+str(agcnumber[i])+'-cutout-sdss.dat' s="awk '{print $2, $7, $9, $11, $13}' <"+sdssEllipseTable+" > junk2.txt" os.system(s) #run ellipse a second time, keeping PA and ellip fixed infile=open('junk2.txt','r') for line in infile: t=line.split() if float(t[0]) > myradius: newellip=float(t[1]) if newellip < .05:#min value that ellipse can handle newellip=.05 newPA=float(t[2]) if newPA < -90: newPA=newPA+180 elif newPA > 90: newPA = newPA-180 #11 - X0, 13 - Y0 newxcenter=float(t[3]) newycenter=float(t[4]) t=mipsImage.split('.') efile=self.prefix+'-'+str(agcnumber[i])+'.24UsingSDSS.tab' copyefile=outpathroot+'research/LocalClusters/Ellipse24UsingSDSS/'+self.prefix+'/'+self.prefix+'-'+str(agcnumber[i])+'.24UsingSDSS.tab' #iraf.ellipse(input=mipsImage,output=efile,inellip=sdssEllipseTable)#trying to use sdss input if os.path.exists(efile): s=efile+' exists. Rerun? (y=yes, any key to skip)' rerunFlag=raw_input(s) if rerunFlag.find('y') > -1: os.remove(efile) iraf.ellipse(input=mipsImage,output=efile,x0=xcenter,y0=ycenter,hcenter='yes',recenter='no',sma0=initialr,minsma=minr,maxsma=maxr,pa=newPA,hpa='yes',ellip=newellip,hellip='yes') else: continue else: iraf.ellipse(input=mipsImage,output=efile,x0=xcenter,y0=ycenter,hcenter='yes',recenter='no',sma0=initialr,minsma=minr,maxsma=maxr,pa=newPA,hpa='yes',ellip=newellip,hellip='yes') #outfile24=homedir+'research/LocalClusters/EllipseTables/'+self.prefix+'/'+self.prefix+'-'+str(agcSpiral[i])+'-cutout-24-rot.dat \n' print 'Displaying isophotes from ellipse fit. Hit q in DS9 window to quit' iraf.isoexam(table=efile) s='cp '+efile+' '+copyefile print s os.system(s)
def measure_disk(input_image,xcenter,ycenter,ipa,iellip,initialr,minr,maxr,zp,band=0,nframe=1,myradius=20,keepfixed=0,einteractive=0,mask_image=None): print 'inside measure disk' print 'mask image = ',mask_image #myradius=initialr recentervalue='yes' interactivevalue='yes' print '\n Running ellipse on ',input_image,'\n' print ' Enter ? for a list of options \n' print ' Enter c to continue fitting ellipses automatically \n' mfile=input_image xcenter_cutout=xcenter ycenter_cutout=ycenter t=mfile.split('.') efile=t[0]+'.tab' efile_ascii=t[0]+'.dat' imprefix=t[0] print 'Running ellipse to fit isophotes to galaxy:',mfile if os.path.exists(efile): os.remove(efile) if keepfixed: print input_image,efile,xcenter_cutout,ycenter_cutout,initialr,minr,maxr,ipa iraf.ellipse(input=input_image,output=efile,dqf=mask_image,x0=xcenter_cutout,y0=ycenter_cutout,hcenter='yes',recenter=recentervalue,sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='yes',ellip=iellip,hellip='yes',interactive='yes',step=0.1,linear='no') else: print "First pass, letting PA and e vary" print input_image,efile,xcenter_cutout,ycenter_cutout,initialr,minr,maxr,ipa, if mask_image == None: iraf.ellipse(input=input_image,output=efile,x0=xcenter_cutout,y0=ycenter_cutout,hcenter='no',recenter='yes',sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='no',ellip=iellip,hellip='no',interactive='yes',step=0.1,linear='no') else: iraf.ellipse(input=input_image,output=efile,dqf=mask_image,x0=xcenter_cutout,y0=ycenter_cutout,hcenter='no',recenter=0,sma0=initialr,minsma=minr,maxsma=maxr,pa=ipa,hpa='no',ellip=iellip,hellip='no',interactive='yes',step=0.1,linear='no') print 'Displaying isophotes from first pass. Hit q in DS9 window to quit' iraf.isoexam(table=efile) try: os.system('rm tp.00*') except: print 'no tp.00? files to remove' iraf.isoimap(input_image,table=efile) # get final ellipse parameters to return to the user if os.path.exists('junk.txt'): os.remove('junk.txt') iraf.tprint(table=efile,pwidth='INDEF',showhdr='no', Stdout='junk.txt') s="awk '{print $2, $7, $9, $11, $13}' < "+"junk.txt > "+"junk2.txt" os.system(s) redo = 1 while redo: infile=open('junk2.txt','r') print 'within redo loop' for line in infile: t=line.split() if float(t[0]) > myradius: #print 'got here',myradius, t[0] newellip=float(t[1]) if newellip < .05: # min value that ellipse can handle newellip=.05 newPA=float(t[2]) if newPA < -90: newPA=newPA+180 elif newPA > 90: newPA = newPA-180 newxcenter=float(t[3]) newycenter=float(t[4]) break infile.close() print 'ellipse values at r = ',myradius print ' ellip = ',newellip print ' PA = ',newPA t=raw_input('are you happy? (n = no, enter to continue) ') if t.find('n') >-1: newr=raw_input('Enter radius where ellipse best represents galaxy ') myradius=float(newr) else: redo = 0 continue if os.path.exists(efile_ascii): os.remove(efile_ascii) iraf.tprint(table=efile,pwidth='INDEF',showhdr='no', Stdout=efile_ascii) return newxcenter,newycenter,newellip,newPA
import os, sys iraf.stsdas() iraf.analysis() iraf.toolbox() iraf.ttools() matchstring = sys.argv[1] #flag = str(raw_input('Which files? a=24 b=sdss ')) #flag = str(flag) #if flag.find('a') > -1: # tabfiles = glob.glob('*cutout-24-rot.tab') #if flag.find('b') > -1: # tabfiles = glob.glob('*cutout-sdss.tab') tabfiles = glob.glob(matchstring) #tabfiles=glob.glob('*.tab') print matchstring #print tabfiles for i in range(len(tabfiles)): tfile = tabfiles[i] # nfile = tfile.split('.tab') dfile = nfile[0] + '.dat' print tfile, ' -> ', dfile iraf.tprint(table=tfile, pwidth='INDEF', showhdr='no', showunits='no', Stdout=dfile)
def measure_disk(input_image, xcenter, ycenter, ipa, iellip, initialr, minr, maxr, zp, band=0, nframe=1, myradius=20, keepfixed=0, einteractive=0, mask_image=None): print 'inside measure disk' print 'mask image = ', mask_image #myradius=initialr recentervalue = 'yes' interactivevalue = 'yes' print '\n Running ellipse on ', input_image, '\n' print ' Enter ? for a list of options \n' print ' Enter c to continue fitting ellipses automatically \n' mfile = input_image xcenter_cutout = xcenter ycenter_cutout = ycenter t = mfile.split('.') efile = t[0] + '.tab' efile_ascii = t[0] + '.dat' imprefix = t[0] print 'Running ellipse to fit isophotes to galaxy:', mfile if os.path.exists(efile): os.remove(efile) if keepfixed: print input_image, efile, xcenter_cutout, ycenter_cutout, initialr, minr, maxr, ipa iraf.ellipse(input=input_image, output=efile, dqf=mask_image, x0=xcenter_cutout, y0=ycenter_cutout, hcenter='yes', recenter=recentervalue, sma0=initialr, minsma=minr, maxsma=maxr, pa=ipa, hpa='yes', ellip=iellip, hellip='yes', interactive='yes', step=0.1, linear='no') else: print "First pass, letting PA and e vary" print input_image, efile, xcenter_cutout, ycenter_cutout, initialr, minr, maxr, ipa, if mask_image == None: iraf.ellipse(input=input_image, output=efile, x0=xcenter_cutout, y0=ycenter_cutout, hcenter='no', recenter='yes', sma0=initialr, minsma=minr, maxsma=maxr, pa=ipa, hpa='no', ellip=iellip, hellip='no', interactive='yes', step=0.1, linear='no') else: iraf.ellipse(input=input_image, output=efile, dqf=mask_image, x0=xcenter_cutout, y0=ycenter_cutout, hcenter='no', recenter=0, sma0=initialr, minsma=minr, maxsma=maxr, pa=ipa, hpa='no', ellip=iellip, hellip='no', interactive='yes', step=0.1, linear='no') print 'Displaying isophotes from first pass. Hit q in DS9 window to quit' iraf.isoexam(table=efile) try: os.system('rm tp.00*') except: print 'no tp.00? files to remove' iraf.isoimap(input_image, table=efile) # get final ellipse parameters to return to the user if os.path.exists('junk.txt'): os.remove('junk.txt') iraf.tprint(table=efile, pwidth='INDEF', showhdr='no', Stdout='junk.txt') s = "awk '{print $2, $7, $9, $11, $13}' < " + "junk.txt > " + "junk2.txt" os.system(s) redo = 1 while redo: infile = open('junk2.txt', 'r') print 'within redo loop' for line in infile: t = line.split() if float(t[0]) > myradius: #print 'got here',myradius, t[0] newellip = float(t[1]) if newellip < .05: # min value that ellipse can handle newellip = .05 newPA = float(t[2]) if newPA < -90: newPA = newPA + 180 elif newPA > 90: newPA = newPA - 180 newxcenter = float(t[3]) newycenter = float(t[4]) break infile.close() print 'ellipse values at r = ', myradius print ' ellip = ', newellip print ' PA = ', newPA t = raw_input('are you happy? (n = no, enter to continue) ') if t.find('n') > -1: newr = raw_input( 'Enter radius where ellipse best represents galaxy ') myradius = float(newr) else: redo = 0 continue if os.path.exists(efile_ascii): os.remove(efile_ascii) iraf.tprint(table=efile, pwidth='INDEF', showhdr='no', Stdout=efile_ascii) return newxcenter, newycenter, newellip, newPA