#! /usr/bin/env python #=======================================# # PAW-Pipeline version: 0.6 # # Written by: Paul Anthony Wilson # # paw@astro.ex.ac.uk # #=======================================# import pyfits import sys, time, shutil, subprocess, commands import pyraf.iraf as iraf import os.path from os import getcwd, chdir, remove, path, environ, getenv, makedirs, listdir, system, unlink from numpy import * from pyfits import getheader from pyraf import iraf # Definitions def cd(target): chdir(target) iraf.cd(target) def copy_to_dir(orig, target): filename = path.basename(orig) shutil.copyfile(orig, path.join(target, filename)) def mkdir(dirname): "Creates a directory if it didn't exist before" if not os.path.isdir(dirname): os.mkdir(dirname) def load_phot(): iraf.noao(_doprint=0) iraf.digiphot(_doprint=0) iraf.daophot(_doprint=0) iraf.tables(_doprint=0) #Formatting options bold_code = "\033[1m" underline_code = "\033[4m" reset_code = "\033[0;0m" def bold(text): return bold_code + text + reset_code def underline(text): return underline_code + text + reset_code # Define directories currentdir = getcwd() rootdir =currentdir biasdir=currentdir+"/bias/" flatdir=currentdir+"/flat/" objectdir=currentdir+"/object/" #Folder names originals = "originals" tmp = "tmp" # Start Program print '\n' print bold('__________________ __ ______________ _____') print bold('___ __ \__ |_ | / / ___ __ \__ /_________ /_') print bold('__ /_/ /_ /| |_ | /| / / __ /_/ /_ __ \ __ \ __/') print bold('_ ____/_ ___ |_ |/ |/ / _ ____/_ / / / /_/ / /_') print bold('/_/ /_/ |_|___/|__/ /_/ /_/ /_/\____/\__/\n') print '\n Version: 0.6' starttime=time.ctime() print ' Program started on '+starttime print '____________________________________________________' # Load the photometry package daophot load_phot() # Chaning to the object directory cd(objectdir) # SETTING ALL THE DIFFERENT PARAMETERS #=================================================================================================== # Set centerpars iraf.centerpars.setParam('calgori','centroid') iraf.centerpars.setParam('cbox',15) iraf.centerpars.setParam('maxshift',10) # Set datapars. Edit to fit your data. iraf.datapars.setParam('fwhmpsf',3.0) # Full witdth half max of the brightest star iraf.datapars.setParam('sigma',3.0) #iraf.datapars.setParam('datamin',500) #iraf.datapars.setParam('datamax',45000) #iraf.datapars.setParam('epadu',1.46) #iraf.datapars.setParam('readnoi',8) iraf.datapars.setParam('exposure','EXPTIME') #iraf.datapars.setParam('airmass','AIRMASS') iraf.datapars.setParam('filter','CCDFLTID') #iraf.datapars.setParam('obstime','READTIME') # Set findpars iraf.findpars.setParam('thresho',4) # Threshold in sigma for feature detection iraf.findpars.setParam('nsigma',1.5) # Width of convolution kernel in sigma - whatever that means... # Set fitskypars iraf.fitskypars.setParam('salgorithm','mode') iraf.fitskypars.setParam('annulus',150) # Inner radius of sky annulus in scale units iraf.fitskypars.setParam('dannulus',10) # Width of sky annulus in scale units # Saving parameters in files iraf.centerpars.saveParList(filename='center.par') #iraf.datapars.saveParList(filename='data.par') iraf.fitskypars.saveParList(filename='fitsky.par') iraf.photpars.saveParList(filename='phot.par') # Set some IRAF settings iraf.set(imtype="fits") #=================================================================================================== print "\n Setting initial parameter files Done" if os.path.isfile("output.tab"): os.system( 'rm output.tab' ) #Check if the images have been reduced dir_contents = listdir('.') ''' reduction_performed = len([fn for fn in dir_contents if fn.endswith('e.fits') and fn.startswith('bfi')]) > 0 if reduction_performed: print "\n Image reductions Done" else: print "No reduced images found. You have to reduce the images first. To do this run reduce.py\n" sys.exit() ''' if os.path.isfile("pix.coo.1"): print "\n Stars automatically detected in images Done" else: iraf.daofind( #### OBJ parameters #### # 'dev$pix', # output='default', # datapar="data.par", # findpar="find.par", # interac="no") # # ################################# # Making a list of image files to be used: c = [fn for fn in dir_contents if fn.endswith('.fits') and fn.startswith('shift') ] f = open('object.list', 'w+') for fn in c: print >> f, fn f.close() objects_list = '@object.list' # PERFORMNIG THE PHOTOMETRY #=================================================================================================== cbox=10 skyrad=10 anwidth=5 currentdir=os.getcwd() photometry_performed = len([fn for fn in dir_contents if 'lloop.par' in fn]) > 0 if photometry_performed: print "\n Photometry Done" print '____________________________________________________\n\n' else: # First aperture radius print "First Inner Aperture Radius (pixels)?" Ap1 = raw_input("(e.g. 10.0): ") # Last aperture radius print "Last Inner Aperture Radius (pixels)?" Ap2 = raw_input("(e.g. 40.0): ") # First aperture radius print "First Outer Aperture Radius (pixels)?" Ap3 = raw_input("(e.g. 120.): ") # Last aperture radius print "Last Outer Aperture Radius (pixels)?" Ap4 = raw_input("(e.g. 160.0): ") # First aperture radius print "Starting Width of Outer Aperture Radius (pixels)?" Ap5 = raw_input("(e.g. 5.0): ") # Last aperture radius print "End With of Last Outer Aperture Radius (pixels)?" Ap6 = raw_input("(e.g. 15.0): ") # step apertures in 0.5 pixel steps NumAps=arange(float(Ap1),float(Ap2)+1.0,1.0) skyrad=arange(float(Ap3),float(Ap4)+5.0,5.0) anwidth=arange(float(Ap5),float(Ap6)+5.0,5.0) # MULTIPLE APERTURE PHOTOMETRY for j in range(0,len(NumAps)): for k in range(0,len(skyrad)): for l in range(0,len(anwidth)): #make the new directory for the phot files #A(aperture_size)S(sky_anulus_size)D(sky_anulus_width)C(center_box_size) e.g. A4.0S10D5C10 newsubdir = "/A" + str(NumAps[j]) + "S" + str(skyrad[k]) + "D" + str(anwidth[l]) + "C" + str(cbox) newdir=str(currentdir)+str(newsubdir) os.mkdir(newdir) # Set photpars iraf.photpars.setParam('apertur',NumAps[j]) # List of aperture radii in scale units iraf.fitskypars.setParam('annulus',skyrad[k]) # Inner radius of sky annulus in scale units iraf.fitskypars.setParam('dannulus',anwidth[l]) # Width of sky annulus in scale units print '\n Aperture: ' + str(NumAps[j]) + '\tOuter radius: ' + str(skyrad[k]) print ' x y MSKY MAG' print '____________________________________________________________________' iraf.photpars.saveParList(filename="phot-loop.par") iraf.phot.setParam('interactive','no') iraf.phot.setParam('verify','no') iraf.phot.setParam('verbose','yes') iraf.phot.saveParList(filename="photpars.pars") iraf.daophot.phot( #### OBJ parameters #### # objects_list, # coords="ds9.reg", # output="default", # datapar="data.par", # centerp="center.par", # fitskyp="fitsky.par", # photpar="phot-loop.par", # interac="no", # verify="no", # update="no", # verbose="yes") # # ################################# print '\n Aperture: ' + str(NumAps[j]) + '\tOuter radius: ' + str(skyrad[k]) print '____________________________________________________________________\n' # Dumping data from the .mag.1 files into text files iraf.daophot.pdump( # Getting the position and flux of stars #### OBJ parameters #### # "*.mag.1", # fields="XCEN,YCEN,FLUX", # expr="yes", # headers="no", # Stdout="xyf.list") # # ################################# # Creating an IRAF table iraf.tables.tcreate( # Creating and IRAF table #### OBJ parameters #### # "output.tab", # cdfile="output.cd", # datafile="xyf.list", # nlines=9) # # ################################# # Creating Standard star 2 flux iraf.ttools.tcalc( # Calculating the relative flux using Std 1 star. #### OBJ parameters #### # "output.tab", # outcol="RATIO12", # equals="F1/F2", # datatyp="real", # Stdout="Ratio-Target-Std1") # # ################################# iraf.ttools.tcalc( # Calculating the relative flux using Std 2 star. #### OBJ parameters #### # "output.tab", # outcol="RATIO13", # equals="F1/F3", # datatyp="real", # Stdout="Ratio-Target-Std2") # # ################################# iraf.ttools.tcalc( # Calculating the relative flux using Std 2 star. #### OBJ parameters #### # "output.tab", # outcol="RATIO14", # equals="F1/F4", # datatyp="real", # Stdout="Ratio-Target-Std3") # # ################################# iraf.ttools.tcalc( # Calculating the relative flux using Std 2 star. #### OBJ parameters #### # "output.tab", # outcol="RATIO15", # equals="F1/F5", # datatyp="real", # Stdout="Ratio-Target-Std4") # # ################################# iraf.ttools.tcalc( # Calculating the relative flux using Std 2 star. #### OBJ parameters #### # "output.tab", # outcol="RATIO16", # equals="F1/F6", # datatyp="real", # Stdout="Ratio-Target-Std5") # # ################################# iraf.ttools.tcalc( # Calculating the relative flux using Std 2 star. #### OBJ parameters #### # "output.tab", # outcol="RATIO17", # equals="F1/F7", # datatyp="real", # Stdout="Ratio-Target-Std6") # # ################################# iraf.ttools.tcalc( # Calculating the relative flux using Std 2 star. #### OBJ parameters #### # "output.tab", # outcol="RATIO18", # equals="F1/F8", # datatyp="real", # Stdout="Ratio-Target-Std7") # # ################################# iraf.ttools.tcalc( # Calculating the relative flux using Std 2 star. #### OBJ parameters #### # "output.tab", # outcol="RATIO19", # equals="F1/F9", # datatyp="real", # Stdout="Ratio-Target-Std8") # # ################################# ################################# iraf.ttools.tcalc( # Calculating the relative flux using Std 1 and Std 2 star. #### OBJ parameters #### # "output.tab", # outcol="RATIO1-23", # equals="F1/(F2+F3)", # datatyp="real", # Stdout="Ratio-Target-Std12") # # ################################# iraf.ttools.tcalc( #### OBJ parameters #### # "output.tab", # outcol="RATIO1-23", # equals="F1/(F2+F3)", # datatyp="real", # Stdout="Ratio-Target-Std1-23") # # ################################# iraf.ttools.tcalc( #### OBJ parameters #### # "output.tab", # outcol="RATIO4_", # equals="F1/(F2+F3+F4)", # datatyp="real", # Stdout="Ratio-Target-Std4_") # # ################################# iraf.ttools.tcalc( #### OBJ parameters #### # "output.tab", # outcol="RATIO5_", # equals="F1/(F2+F3+F4+F5)", # datatyp="real", # Stdout="Ratio-Target-Std5_") # # ################################# iraf.ttools.tcalc( #### OBJ parameters #### # "output.tab", # outcol="RATIO6", # equals="F1/(F2+F3+F4+F5+F6)", # datatyp="real", # Stdout="Ratio-Target-Std6_") # # ################################# iraf.ttools.tcalc( #### OBJ parameters #### # "output.tab", # outcol="RATIO7_", # equals="F1/(F2+F3+F4+F5+F6+F7)",# datatyp="real", # Stdout="Ratio-Target-Std7_") # # ################################# iraf.ttools.tcalc( #### OBJ parameters #### # "output.tab", # outcol="RATIO8_", # equals="F1/(F2+F4+F5+F6+F9)", # datatyp="real", # Stdout="Ratio-Target-Std8_") # # ################################# iraf.ttools.tcalc( #### OBJ parameters #### # "output.tab", # outcol="RATIO9_", # equals="F1/(F2+F3+F4+F5+F6+F7+F8+F9)", # datatyp="real", # Stdout="Ratio-Target-Std9_") # # ################################# # Creating Target Star Flux iraf.ttools.tdump( # Converts the IRAF table into a text file #### OBJ parameters #################### # "output.tab", # columns="F1, F2, F3, RATIO12, RATIO13, RATIO14, RATIO15, RATIO16, RATIO17, RATIO18, RATIO19, RATIO1-23, RATIO4_, RATIO5_, RATIO6_, RATIO7_, RATIO8_, RATIO9_",# cdfile="", # pfile="", # rows="-", # Stdout="Target-Star-Flux") # # ################################################# # Creating Target Star Flux iraf.ttools.tdelete( # Removes the IRAF table #### OBJ parameters #### # "output.tab", # verify="no") # # ################################# # Getting the time of observation from the FITS header files = [x for x in listdir('.') if x.endswith('.fits') and x.startswith('shift')] files.sort() f = open('time.list', 'w+') i = 0 ''' for x in files: readtime = getheader(files[i])['READTIME'] i += 1 print >> f, readtime f.close() ''' f = open('date.list', 'w+') date = getheader(files[0])['DATE'] date = date.split('T') date = date[0] date = date.split('-') year = date[0] month = date[1] day = date[2] print >> f, year, month, day f.close() # Creating directories data = "data" cd(newdir) mkdir(data) mag = "mag" mkdir(mag) tmp = "tmp" mkdir(tmp) cd(rootdir) os.system( 'cp login.cl ' + newdir ) os.system( 'cp -r uparm ' + newdir ) cd(objectdir) # Moves the files created into their respective folders os.system( 'mv *.mag.1 ' + newdir+'/'+mag ) os.system( 'mv xyf.list ' + newdir+'/'+tmp ) os.system( 'mv date.list ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std1 ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std2 ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std12 ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std1-23 ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std4 ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std5 ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std6 ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std7 ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std8 ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std4_ ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std5_ ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std6_ ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std7_ ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std8_ ' + newdir+'/'+tmp ) os.system( 'mv Ratio-Target-Std9_ ' + newdir+'/'+tmp ) #os.system( 'cp Target-Star-Flux ' + newdir ) os.system( 'cp time.list ' + newdir+'/'+data ) os.system( 'mv Target-Star-Flux ' + newdir+'/'+data ) os.system( 'cp ../plot.py ' + newdir ) #os.system( 'cp ../plotty.py ' + newdir ) #=================================================================================================== endtime=time.ctime() print 'Program started at '+starttime print 'Program ended at '+endtime+'\n'