def run_darkcombine(images, output): iraf.imred(_doprint=0) iraf.ccdred(_doprint=0) iraf.darkcombine(input=images, output=output, combine="average", reject="minmax", \ ccdtype="none", process="Yes", delete="No", clobber="No", scale="exposure", \ statsec='', nlow=0, nhigh=1, nkeep=1, mclip="Yes", lsigma=3.0, hsigma=3.0, \ rdnoise=0., gain=1., snoise=0., pclip=-0.5, blank=0.0, mode="al")
def make_master(obj, file_type=None): """ This routine takes the name of a file containing the raw calibration images in the **current** directory that are to be combined to form a master calibration image. The type of calibration images (i.e. bias, dark or flat) is specified by the file_type keyword; this is necessary because the type of calibration image determines how the multiple raw calibration images are to be combined (eg. pixel averages vs medians). """ # Get the name of the master calibration file: if file_type=='bias': list_file = obj.bias_list elif file_type=='dark': list_file = obj.dark_list elif file_type=='flat': list_file = obj.flat_list dirpath = os.path.dirname(list_file)+'/' filename = 'master_'+file_type+'.fits' master_filename = dirpath+filename if os.path.exists(master_filename): os.remove(master_filename) # Now make the master calibration file: if file_type=='bias': iraf.zerocombine(input='@'+list_file, output=master_filename, combine='average', ccdtype='', process='no', delete='no') obj.master_bias = master_filename elif file_type=='dark': iraf.darkcombine(input='@'+list_file, output=master_filename, combine='average', ccdtype='', process='no', delete='no') obj.master_dark = master_filename elif file_type=='flat': iraf.flatcombine(input='@'+list_file, output=master_filename, combine='median', ccdtype='', process='no', delete='no') obj.master_flat = master_filename return None
def darkcombine(self, files, output, zero=None, method="median", rejection="minmax", ccdtype="", scale="exposure", overwrite=True): """IRAF darkcombine""" self.logger.info("Darkcombine Started") try: iraf.ccdred.unlearn() iraf.ccdred.ccdproc.unlearn() iraf.ccdred.combine.unlearn() iraf.ccdred.darkcombine.unlearn() iraf.imred.unlearn() ccdred.instrument = self.instrument_path darks = ",".join(files) out_file = "{}/myraf_darks.flist".format(self.fop.tmp_dir) with open(out_file, "w") as f2w: for i in files: f2w.write("{}\n".format(i)) darks = "@{}".format(out_file) if zero is not None: iraf.ccdproc(images=darks, ccdtype='', fixpix='no', oversca="no", trim="no", zerocor='yes', darkcor='no', flatcor='no', zero=zero, Stdout="/dev/null") if self.fop.is_file(output) and overwrite: self.logger.warning("Over Writing file({})".format(output)) self.fop.rm(output) iraf.darkcombine(input=darks, output=output, combine=method, reject=rejection, ccdtype=ccdtype, scale=scale, process="no", Stdout="/dev/null") return True except Exception as e: self.logger.error(e) return False
def createMasterdark(imagelist, output): _file = open('input.tmp', 'w') for image in imagelist: _file.write(image + '\n') _file.close() iraf.darkcombine.setParam('input', '@input.tmp') iraf.darkcombine.setParam('output', output) iraf.darkcombine.setParam('ccdtype', '') iraf.darkcombine.setParam('process', 'no') iraf.darkcombine() os.system('rm input.tmp')
def createMasterdark(imagelist, output): _file = open('input.tmp', 'w') for image in imagelist: _file.write(image+'\n') _file.close() iraf.darkcombine.setParam('input', '@input.tmp') iraf.darkcombine.setParam('output', output) iraf.darkcombine.setParam('ccdtype', '') iraf.darkcombine.setParam('process', 'no') iraf.darkcombine() os.system('rm input.tmp')
def darkcom(input_dark): import glob import os, sys import numpy as np from pyraf import iraf from astropy.io import fits from astropy.io import ascii curdir = os.getcwd() curdate = curdir.split('/')[-1] #dark = ", ".join(input_dark) iraf.noao() iraf.imred() iraf.ccdred() iraf.ccdred.setinst(instrume='camera', directo='/iraf/iraf/noao/imred/ccdred/ccddb/', query='q', review='no') #iraf.chdir('./dark') #dark = glob.glob('cal*dk*.fit') #dark = ascii.read('dark.list', guess=True, data_start=0) ''' allexptime = [] for i in range(len(dark)) : hdr = fits.getheader(dark[i]) allexptime.append(hdr['exptime']) expset = set(allexptime) exptime = list(sorted(expset)) i=0 for i in range(len(exptime)) : print('Find images with exptime of '+str(exptime[i])) imlist = [] for j in range(len(dark)) : hdr = fits.getheader(dark[j]) if hdr['exptime'] == exptime[i] : imlist.append(dark[j]) else : pass print(imlist) input_name = 'dark'+str(int(exptime[i]))+'.list' output_name = curdate+'_dark'+str(int(exptime[i]))+'.fits' #input_name = output_name[:-5]+'.list' f=open(input_name,'w+') for k in range(len(imlist)) : f.write(imlist[k]+'\n') f.close() ''' #output_name = curdate+'_dark'+str(int(exptime[i]))+'.fits' output_name = curdate+'_'+input_dark[:-5]+'.fits' print('Darkcombine is running...') iraf.imstat(images='z@'+input_dark) iraf.darkcombine(input='z@'+input_dark, output=output_name, combine='median', reject='minmax', process='no', scale='none', ccdtype='' ) #os.system('/usr/bin/cp '+output_name+' ../') os.system('/usr/bin/cp '+output_name+' /data1/KHAO/MDFTS/red/masterdark/') #os.system('/usr/bin/rm d*.list') #iraf.chdir('../') iraf.dir('.') print('Output master '+output_name+' is created.')
def create_dark(self): """Creating Combined Dark Frame""" self.log.debug("Running iraf.darkcombine on image list...") iraf.unlearn(iraf.darkcombine) iraf.darkcombine(self.dark.iraf.inatfile(), output=self.dark.iraf.outfile("Dark"), combine=self.config["Dark.Combine"], ccdtype="dark", reject=self.config["Dark.Reject"], process="no", scale="exposure", nlow=0, nhigh=1, nkeep=1, mclip="yes", lsigma=3.0, hsigma=3.0, rdnoise="0.", gain ="1." ) self.dark.iraf.done()
def makeDark(fileList='darks.lst', inputType=INPUT_LISTFNAME, output='Dark.fits', process=iraf.yes, combine='average', ccdtype='dark', reject='minmax'): '''create a master Dark.fits from the darks in fileList''' iraf.darkcombine(_genIRAFString(fileList, inputType), output=output, combine=combine, process=process, ccdtype=ccdtype, reject=reject)
def main(raw_dir): if not os.path.exists("{}/step1.tmp".format(os.getcwd())): print "Setting up directory" list_dict = setup_dir(raw_dir) print "OT'ing" iraf.ccdproc( "@all_raw.lst", output="@all_ot.lst", overscan=True, trim=True, zerocor=False, darkcor=False, flatcor=False, illumco=False, biassec="image", trimsec="image", zero="", interact=True, order=100, ) cull_bias(list_dict["zeros"], "zeros.lst") os.system("touch {}/step1.tmp".format(os.getcwd())) return print "Making master bias" iraf.zerocombine("@zeros.lst", output="Zero.fits", combine="average", reject="crreject") print "Subtracting bias" iraf.ccdproc("@all_otz.lst", overscan=False, trim=False, zerocor=True, zero="Zero.fits") detect_flats(os.getcwd()) flats_to_make = glob("dflat*.lst") for flat in flats_to_make: name = "dFlat_{}.fits".format(flat.split(".lst")[0].split("_")[1]) print "Making flat {}".format(name) iraf.flatcombine("@{}".format(flat), output=name, combine="average", reject="crreject") try: print "Making master dark" iraf.darkcombine("@darks.lst", output="Dark.fits", combine="average", reject="crreject") except Exception as e: print "\t{}".format(e) print "\tNO DARK FOUND" print "Making master comp" iraf.imcombine("@comps.lst", "Comp.fits", combine="average", reject="crreject") return
def darkcom(inim_list, outim_list, combine='median', reject='minmax', scale='none'): import os, sys from pyraf import iraf iraf.noao() iraf.imred() iraf.ccdred() iraf.ccdred.setinst(instrume='camera', directo='/iraf/iraf/noao/imred/ccdred/ccddb/', query='q', review='no') iraf.darkcombine(input=inim_list, output=outim_list, combine=combine, reject=reject, process='no', scale=scale, ccdtype='') print('Output masterdark is created.')
def createAverageFlat(flatImagesList): flatString = getIrafString(flatImagesList) iraf.darkcombine(input=flatString,process="No",output="averagedFlat")
def createAverageFlat(flatImagesList): flatString = getIrafString(flatImagesList) iraf.darkcombine(input=flatString, process="No", output="averagedFlat")
def createAverageDark(darkImagesList): darkString = getIrafString(darkImagesList) iraf.darkcombine(input=darkString, process="No", output="averagedDark")
def the_darkcombine(self, in_file_list, out_file, zero=None, method="median", rejection="minmax", ccdtype="", scale="exposure", overscan="no", trim="no"): self.etc.log( "Darkcombine started for {} files using combine({}), rejection({}) and scale({}) and zero({})" .format(len(in_file_list), method, rejection, scale, zero)) try: if self.fop.is_file(out_file): self.fop.rm(out_file) files = [] for file in in_file_list: if self.fit.is_fit(file): files.append(file) if not len(files) == 0: darks = ",".join(files) # Load packages # Unlearn settings iraf.imred.unlearn() iraf.ccdred.unlearn() iraf.ccdred.ccdproc.unlearn() iraf.ccdred.combine.unlearn() iraf.ccdred.darkcombine.unlearn() ccdred.instrument = "ccddb$kpno/camera.dat" iraf.imred() iraf.ccdred() iraf.darkcombine(input=darks, output=out_file, combine=method, reject=rejection, ccdtype=ccdtype, scale=scale, process="no", Stdout="/dev/null") if zero is not None and self.fop.is_file(zero): iraf.ccdproc(images=darks, ccdtype='', fixpix='no', oversca=overscan, trim=trim, zerocor='yes', darkcor='no', flatcor='no', zero=zero, Stdout="/dev/null") else: self.etc.log("No files to combine") except Exception as e: self.etc.log(e)
def preprocess(path): #, mode='EABA'): """ Pipeline that applies the basic CCD reduction tasks. Asks for the path were all files are present, and performs Bias combination, Dark combination, Flat combination and the inherent substractions Works in TORITOS mode, and EABA mode, the latter using UBVRI filters. Pipeline que aplica una reducción básica a imágenes de tipo CCD Realiza combinación de Bias, de Darks, y Flats. Luego realiza las restas inherentes Funciona en dos modos, TORITOS y EABA, el último usando filtros UBVRI """ bornpath = os.path.abspath('.') workdir = os.path.abspath(path) biasdir = os.path.join(workdir, "bias") flatdir = os.path.join(workdir, "flat") darkdir = os.path.join(workdir, "dark") scidir = os.path.join(workdir, "science") for x in [biasdir, flatdir, darkdir, scidir]: print "creating {} directory".format(str(x)) mkdir(x) cd(workdir) #-------------------------------------------------------------------------# fitslist = [] for root, dirs, files in os.walk(path, topdown=True): for name in fnmatch.filter(files, '*.fit*'): fitslist.append(os.path.join(root, name)) #fitslist = glob.glob('*.fits') + glob.glob('*.fit') #load_ccdred() #-------------------------------------------------------------------------# imagetypes = {} for img in fitslist: imghead = fits.getheader(img) imgty = imghead['IMAGETYP'] imagetypes[str(img)] = imgty #-------------------------------------------------------------------------# # now we get the image types in the dictionary imagetypes # now we make different lists for different image types #-------------------------------------------------------------------------# biaslist = [] sciencelist = [] flatlist = [] darklist = [] #-------------------------------------------------------------------------# for k, v in imagetypes.iteritems(): print k, v if v.upper() == 'LIGHT' or v.upper() == 'OBJECT' or v.upper( ) == 'LIGHT FRAME': # print str(k)+' is a '+str(v)+' file' sciencelist.append(str(k)) elif v.upper() == 'BIAS' or v.upper() == 'ZERO' or v.upper( ) == 'BIAS FRAME': # print str(k)+' is a '+str(v)+' file' biaslist.append(str(k)) elif v.upper() == 'FLAT' or v.upper() == 'FLAT FRAME' or v.upper( ) == 'FLAT FIELD': # print str(k)+' is a '+str(v)+' file' flatlist.append(str(k)) elif v.upper() == 'DARK' or v.upper() == 'DARK FRAME': # print str(k)+' is a '+str(v)+' file' darklist.append(str(k)) #-------------------------------------------------------------------------# insp = raw_input("Inspeccionar imagenes de correccion con ds9? (si/NO)\n") if insp.upper() in ('S', 'Y', 'SI', 'YES'): print('\n') print(u"""Comienza la inspeccion visual de bias ante cualquier anomalia en alguna imagen se la vetará Starting visual inspection of Bias frames. If there exists any anomalies image will be discarded""") for idx, img in enumerate(list(biaslist)): I = raw_input("inspeccionar {} mediante ds9? (si/NO)\n".format( str(img))) if I.upper() in ('S', 'Y', 'SI', 'YES'): print(""" inspeccionando {} mediante ds9""".format(str(img))) print("\n") command = shlex.split('ds9 {}'.format(str(img))) subprocess.call(command) V = raw_input(" Vetar la imagen? (si/NO)") print("\n") if V.upper() in ('S', 'Y', 'SI', 'YES'): S = raw_input('Es una imagen de ciencia? (LIGHT) (SI/no)') print("\n") if S.upper() in ('S', 'Y', 'SI', 'YES'): hdu = fits.open(img, mode='update') hdr = hdu[0].header hdr.set('IMAGETYP', 'LIGHT') hdu.close() sciencelist.append(img) elif S.upper() in ('N', 'NO'): os.rename(img, img + '.vet') biaslist.remove(img) #-------------------------------------------------------------------------# print('\n') print(u"""Comienza la inspeccion visual de flats ante cualquier anomalia en alguna imagen se la vetará \n""") for idx, img in enumerate(list(flatlist)): I = raw_input("inspeccionar {} mediante ds9? (si/NO)\n".format( str(img))) if I.upper() in ('S', 'Y', 'SI', 'YES'): print(""" inspeccionando {} mediante ds9""".format(str(img))) print("\n") command = shlex.split('ds9 {}'.format(str(img))) subprocess.call(command) V = raw_input(" Vetar la imagen? (si/NO) ") print("\n") if V.upper() in ('S', 'Y', 'SI', 'YES'): S = raw_input( 'Es una imagen de ciencia? (LIGHT) (SI/no) ') print("\n") if S.upper() in ('S', 'Y', 'SI', 'YES'): hdu = fits.open(img, mode='update') hdr = hdu[0].header hdr.set('IMAGETYP', 'LIGHT') hdu.close() sciencelist.append(img) elif S.upper() in ('N', 'NO'): os.rename(img, img + '.vet') flatlist.remove(img) #-------------------------------------------------------------------------# print("\n") print(u"""Comienza la inspeccion visual de darks ante cualquier anomalia en alguna imagen se la vetará \n""") for idx, img in enumerate(list(darklist)): I = raw_input("inspeccionar {} mediante ds9? (si/NO)\n".format( str(img))) if I.upper() in ('S', 'Y', 'SI', 'YES'): print(""" inspeccionando {} mediante ds9""".format(str(img))) print("\n") command = shlex.split('ds9 {}'.format(str(img))) subprocess.call(command) V = raw_input(" Vetar la imagen? (si/NO)") print("\n") if V.upper() in ('S', 'Y', 'SI', 'YES'): S = raw_input('Es una imagen de ciencia? (LIGHT) (SI/no)') print("\n") if S.upper() in ('S', 'Y', 'SI', 'YES'): hdu = fits.open(img, mode='update') hdr = hdu[0].header hdr.set('IMAGETYP', 'LIGHT') hdu.close() sciencelist.append(img) elif S.upper() in ('N', 'NO'): os.rename(img, img + '.vet') darklist.remove(img) #-------------------------------------------------------------------------# #posee listas de todos los files. #comienzo por los bias: #primero creo una lista (file) para darle a zerocombine write_tolist(biaslist, 'lbias', biasdir) #, workdir) #-------------------------------------------------------------------------# iraf.ccdhedit('@lbias', parameter='imagetype', value='zero') iraf.zerocombine.unlearn() iraf.zerocombine('@lbias', output='Zero.fits') #baseflat = [os.path.basename(x) for x in flatlist] #basesci = [os.path.basename(x) for x in sciencelist] #basedark = [os.path.basename(x) for x in darklist] #-------------------------------------------------------------------------# #ahora corrijo las imagenes de flat, dark y objetos por bias. load_ccdproc() iraf.ccdproc.zero = 'Zero.fits' for names in flatlist: iraf.ccdproc(names, output=os.path.join(flatdir, 'fz' + os.path.basename(names))) for names in darklist: iraf.ccdproc(names, output=os.path.join(darkdir, 'dz' + os.path.basename(names))) #-------------------------------------------------------------------------# #recreate lists of new corrected objects flatlist = [] darklist = [] for root, dirs, files in os.walk(path, topdown=True): for name in fnmatch.filter(files, 'fz*'): flatlist.append(os.path.join(flatdir, name)) for root, dirs, files in os.walk(path, topdown=True): for name in fnmatch.filter(files, 'dz*'): darklist.append(os.path.join(darkdir, name)) #-------------------------------------------------------------------------# #combino darks tal como hice con los bias #-------------------------------------------------------------------------# write_tolist(darklist, 'ldark') #write_tolist(sciencelist, 'lsci') iraf.darkcombine.unlearn() iraf.ccdhedit('@ldark', parameter='imagetype', value='dark') iraf.darkcombine('@ldark', output='Dark.fits') #-------------------------------------------------------------------------# # discrimino por filtro los datos. es importante esta parte! #.------------------------------------------------------------------------# #SE USARON FILTROS? filteruse = True for v in flatlist: try: hdr = fits.getheader(v) FILTER = hdr['FILTER'] print 'FILTROS HALLADOS' except KeyError: filteruse = False print 'NO SE USARON FILTROS' #---------------------------IF FILTERS USED ------------------------------# if filteruse: FD = {'U': [], 'B': [], 'V': [], 'R': [], 'I': []} for idx, img in enumerate(list(flatlist)): hdr = fits.getheader(img) FR = hdr['FILTER'] #creo un diccionario de filtros FD[str(FR)].append(img) print(FD) #-------------------------------------------------------------------------# #combino los flats #-------------------------------------------------------------------------# for k, v in FD.iteritems(): if not v == []: print('writing to list for {} filter'.format(k)) print(v) lname = str(k) + 'flat' #print(lname) write_tolist(v, lname) iraf.flatcombine.unlearn() iraf.flatcombine.combine = 'median' iraf.ccdhedit('@' + lname, parameter='imagetype', value='flat') iraf.flatcombine('@' + lname, output='Flat' + k + '.fits') #-------------------------------------------------------------------------# SD = {'U': [], 'B': [], 'V': [], 'R': [], 'I': []} for idx, img in enumerate(list(sciencelist)): hdr = fits.getheader(img) FR = hdr['FILTER'] #creo un diccionario de filtros SD[str(FR)].append(img) print(SD) #-------------------------------------------------------------------------# for k, v in SD.iteritems(): iraf.ccdproc.flatcor = 'yes' iraf.ccdproc.darkcor = 'yes' iraf.ccdproc.dark = 'Dark.fits' for img in v: if os.path.isfile('Flat' + k + '.fits'): iraf.ccdproc.flat = 'Flat' + k + '.fits' iraf.ccdproc(img, output='reduced_' + img) #----------------------IF NO FILTERS--------------------------------------# else: lname = 'flist' write_tolist(flatlist, lname) iraf.flatcombine.unlearn() iraf.flatcombine.combine = 'median' iraf.ccdhedit('@' + lname, parameter='imagetype', value='flat') iraf.flatcombine('@' + lname, output='Flat.fits') iraf.ccdproc.flatcor = 'yes' iraf.ccdproc.darkcor = 'yes' iraf.ccdproc.dark = 'Dark.fits' iraf.ccdproc.flat = 'Flat.fits' iraf.ccdproc.ccdtype = '' for sciname in sciencelist: print 'ccdproc of ', sciname, '\n', os.path.join( scidir, 'reduced_' + os.path.basename(sciname)) iraf.ccdproc(sciname, output=os.path.join(scidir,\ 'reduced_'+os.path.basename(sciname))) #[os.remove(x) for x in fitslist] aux = glob.glob('sz*.fits') + glob.glob('dz*.fits') + glob.glob('fz*.fits') [os.remove(x) for x in aux] aux = glob.glob('reduced*.fits') [os.rename(x, x[10:-4].upper() + x[-4:].lower()) for x in aux] #-------------------------------------------------------------------------# print(u""" Imágenes reducidas exitosamente APARENTEMENTE, chequea todo obsesivamente, porque ni el desarrollador de esto confia en que ande bien \n """) #-------------------------------------------------------------------------# cd(bornpath) #print sys.argv[:] return ()
fields="darktime", value=iraf.imgets.value, add="no", addonly="yes", delete="no", verify="no", show="no", update="yes") # creating master dark unlearn(iraf.darkcombine) print "> creating master dark image" iraf.darkcombine("Dark*.fit", output="master_dark.fits", combine="average", reject="none", ccdtype="dark", scale="none", process="no") # creating master flat unlearn(iraf.flatcombine) print "> creating master flat image" iraf.flatcombine("Flat*.fit", output="master_flat_temp.fits", combine="median", reject="crreject", ccdtype="flat", process="no", delete="no", scale="median")
def makeDark(fileList='darks.lst',inputType=INPUT_LISTFNAME,output='Dark.fits',process=iraf.yes,combine='average',ccdtype='dark',reject='minmax'): '''create a master Dark.fits from the darks in fileList''' iraf.darkcombine(_genIRAFString(fileList,inputType), output=output, combine=combine, process=process,ccdtype=ccdtype,reject=reject)
def darkcom(imlist_name, camera='KL4040'): """ 1. Description : This function makes a master dark image of KCT using Pyraf. Put dark images to 201X-XX-XX/dark/ directory. Run this code on 201XXXXX directory, then pyraf chdir task enter dark directory and makes process. Output image is darkXXX.fits (XXX is exposure time. This function will classify each exposure of dark frames!) and it will be copied on upper directory. Due to iraf.chdir task, you should reset python when this code is finished in order to make confusion of current directory between iraf and python! 2. Usage : Start on 2018-XX-XX directory. Make dark directory which contains each dark frame. Naming of each dark image should be dark*.fit. Then just use darkcom(). >>> darkcom() 3. History 2018.03 Created by G.Lim. 2018.12.20 Edited by G.Lim. Define SAO_darkcom function. 2019.02.07 Assign archive of masterdark in each date by G. Lim 2020.03.01 Modified for KL4040 process 2020.03.06 Modified for KCT STX16803 process """ import glob import os, sys import numpy as np from pyraf import iraf from astropy.io import fits savedir = '/data1/KCT/' curdir = os.getcwd() ''' yy = curdir.split('/')[-1].split('-')[0] mm = curdir.split('/')[-1].split('-')[1] dd = curdir.split('/')[-1].split('-')[2] curdate = yy+mm+dd ''' curdate = curdir.split('/')[-1] iraf.noao() iraf.imred() iraf.ccdred() iraf.ccdred.setinst(instrume='camera', directo='/iraf/iraf/noao/imred/ccdred/ccddb/', query='q', review='no') iraf.chdir('./dark') print('zero subtraction...') os.system('ls dark*.fit > dark.list') iraf.imarith(operand1='@dark.list', op='-', operand2='../*_zero.fits', result='*****@*****.**') zdark = glob.glob('zdark*.fit') allexptime = [] for i in range(len(zdark)): hdr = fits.getheader(zdark[i]) allexptime.append(hdr['exptime']) expset = set(allexptime) exptime = list(sorted(expset)) i = 0 for i in range(len(exptime)): print('Find images with exptime of ' + str(exptime[i])) imlist = [] for j in range(len(zdark)): hdr = fits.getheader(zdark[j]) if hdr['exptime'] == exptime[i]: imlist.append(zdark[j]) else: pass print(imlist) output_name = curdate + '_dark' + str(int(exptime[i])) + '.fits' input_name = output_name[:-5] + '.list' f = open(input_name, 'w+') for k in range(len(imlist)): f.write(imlist[k] + '\n') f.close() print('Darkcombine is running...') iraf.imstat('@' + input_name) iraf.darkcombine(input='@' + input_name, output=output_name, combine='median', reject='minmax', process='no', scale='none', ccdtype='') os.system('/usr/bin/cp ' + output_name + ' ../') os.system('mkdir ' + savedir + 'masterdark') os.system('/usr/bin/cp ' + output_name + ' ' + savedir + 'masterdark/') os.system('/usr/bin/rm d*.list') iraf.chdir('../') iraf.dir('.') print('Output master ' + output_name + ' is created.')
def createAverageDark(darkImagesList): darkString = getIrafString(darkImagesList) iraf.darkcombine(input=darkString,process="No",output="averagedDark")
def createAverageDark(self): iraf.darkcombine(input=self.inputFolder,process="No",output=self.avaragedDark)
def main(argv): import getopt, os import param as p try: # accept options -h, -m, -t, -b, -d, -f, -r opts, argv = getopt.getopt(argv, 'hm:t:b:d:f:r', ['help', 'master=', 'telescope=', 'bias=', 'dark=', 'flat=', 'reduce']) except getopt.GetoptError: usage() sys.exit(2) for opt, arg in opts: if opt in ('-h', '--help'): usage() sys.exit(2) # need to select the telescope, see param.py if opt in ('-r', '--reduce') or opt in ('-m', '--master'): for opt2, arg2 in opts: if opt2 in ('-t', '--telescope'): telescope = p.telescopes[arg2] try: telescope except: usage() sys.exit(2) # option -r, reduce frames if opt in ('-r', '--reduce'): from pyraf import iraf import pyfits # inizialise variables p = {} framelist = [] filters = [] if arg: # one can specify a list of frames, divided by a space # @todo not tested! framelist.append(arg.split(' ')) else: # get list of frames, using function list_frames frameType = 'Light Frame' frames = list_frames('.')[0] for date in frames[frameType]: # select just frameType for temperature in frames[frameType][date]: for bin in frames[frameType][date][temperature]: framesProc = frames[frameType][date][temperature][bin] for frameProc in framesProc: # exclude master frames (shouldn't be necessary!) if not os.path.basename(frameProc['path'])[0:6] == 'Master': # add frame path to framelist if not frameProc['filter'] in filters: filters.append(frameProc['filter']) f = {} f['path'] = os.path.abspath(frameProc['path']) f['filter'] = frameProc['filter'] framelist.append(f) # set bias, dark and flats. # if nothing is specified, use default Master*.fits for opt1, arg1 in opts: if opt1 in ('-b', '--bias'): if arg1: p['bias'] = arg1 if opt1 in ('-d', '--dark'): if arg1: p['dark'] = arg1 if opt1 in ('-f', '--flat'): if arg1: p['flat'] = arg1 if not 'bias' in p: p['bias'] = 'MasterBias.fits' if not 'dark' in p: p['dark'] = 'MasterDark.fits' # set flat fields, divided by filter flatfiles = [] if not 'flats' in p: import glob for file in glob.glob('./MasterFlat*'): f = {} f['path'] = os.path.abspath(file) header=pyfits.getheader(file) f['filter'] = header['FILTER'] flatfiles.append(f) # check that files exist try: with open(p['dark']): pass except IOError: print '%s not found' % p['dark'] try: with open(p['bias']): pass except IOError: print '%s not found' % p['bias'] # create copies of original files, with prefix CORR_ import shutil for f in framelist: shutil.copy(f['path'], os.path.splitext(f['path'])[0]+'_reduced.fits') # reduce images by filter for filter in filters: # create text list of files for iraf tmplistcorr = open('tmplistcorr', 'w') for frame in framelist: if frame['filter'] == filter: tmplistcorr.write("%s_reduced.fits\n" % (os.path.splitext(frame['path'])[0])) tmplistcorr.close() # select flat field for flat in flatfiles: if flat['filter'] == filter: p['flat'] = flat['path'] # reduce frames print 'Calibrate images with %s filter' % filter iraf.ccdproc(images='@tmplistcorr',output='', ccdtype='', fixpix='no', \ overscan='no', trim='No', zerocor='yes', zero=p['bias'], \ darkcor='Yes', dark=p['dark'], flatcor='yes', flat=p['flat'], readaxi='column', \ biassec='', trimsec='') # option -m type: create master frames elif opt in ('-m', '--master'): from pyraf import iraf import pyfits p = {} framelist = [] # select frame type if arg == 'bias' or arg == 'dark' or arg == 'flat': if arg == 'bias': frameType = 'Bias Frame' # we need 'Bias Frame', not just 'bias'! elif arg == 'dark': frameType = 'Dark Frame' # same elif arg == 'flat': frameType = 'Flat Field' # same frameflat = [] # frameflat is used to divide files by filter filters = [] # use function list_frames from reduceall, to list all the frames # divided by frametype, date, temperature, bin # and add them to a single list frames = list_frames('.')[0] for date in frames[frameType]: # select just frameType for temperature in frames[frameType][date]: for bin in frames[frameType][date][temperature]: framesProc = frames[frameType][date][temperature][bin] for frameProc in framesProc: # exclude master frames if not os.path.basename(frameProc['path'])[0:6] == 'Master': # add frame path to framelist framelist.append(os.path.abspath(frameProc['path'])) # for flat fields, create a second list (frameflat) # that specifies the filter name if arg == 'flat': if not frameProc['filter'] in filters: filters.append(frameProc['filter']) flat = {} flat['path'] = os.path.abspath(frameProc['path']) flat['filter'] = frameProc['filter'] frameflat.append(flat) # set bias frame and/or dark frame. # if nothing is specified, use default Master*.fits # check that files actually exist if arg == 'dark' or arg == 'flat': for opt1, arg1 in opts: if opt1 in ('-b', '--bias'): if arg1: p['bias'] = arg1 if opt1 in ('-d', '--dark') and arg == 'flat': if arg1: p['dark'] = arg1 if not 'bias' in p: p['bias'] = 'MasterBias.fits' if not 'dark' in p and arg == 'flat': p['dark'] = 'MasterDark.fits' if 'dark' in p: try: with open(p['dark']): pass except IOError: print '%s not found' % p['dark'] if 'bias' in p: try: with open(p['bias']): pass except IOError: print '%s not found' % p['bias'] # create copies of original files, with prefix CORR_ import shutil for f in framelist: shutil.copy(f, os.path.join(os.path.dirname(f), 'CORR_'+os.path.basename(f))) # create text lists of original and copied files tmplistcorr = open('tmplistcorr', 'w') tmplist = open('tmplist', 'w') for f in framelist: tmplistcorr.write("%s/CORR_%s\n" % (os.path.dirname(f), os.path.basename(f))) tmplist.write("%s\n" % f) tmplistcorr.close() tmplist.close() # create MasterBias if arg == 'bias': print 'Trim bias frames' iraf.ccdproc (images='@tmplistcorr',output ='', ccdtype = '', fixpix='no', \ oversca = 'no', trim = 'yes', zerocor = 'no', zero = '', \ flatcor = 'no', darkcor = 'no', readaxi = 'column', \ biassec = '', trimsec=telescope.trimsection) print 'Creating MasterBias.fits' iraf.zerocombine (PYinput='@tmplistcorr', output='MasterBias.fits', ccdtype='', \ combine='median', reject='none', rdnoise=telescope.rdnoise, gain=telescope.egain) # create MasterDark if arg == 'dark': print 'Bias subtract dark frames' iraf.ccdproc(images='@tmplistcorr',output='', ccdtype='', fixpix='no', \ overscan='no', trim='yes', zerocor='yes', zero=p['bias'], \ darkcor='No', flatcor='no', readaxi='column', \ biassec='', trimsec=telescope.trimsection) print 'Creating MasterDark.fits' iraf.darkcombine (PYinput='@tmplistcorr', output='MasterDark.fits', ccdtype='', \ combine='median', reject='none', process='no', delete='no', \ clobber='no', scale='exposure', statsec='', nlow='0', nhigh='1', \ nkeep='1', mclip='yes', lsigma='5.', hsigma='4.',rdnoise=telescope.rdnoise,\ gain=telescope.egain, snoise='0.', pclip='-0.5', blank='0.') # create FlatFields, divided by filter if arg == 'flat': print 'Bias and dark subtract flat fields' iraf.ccdproc(images='@tmplistcorr',output='', ccdtype='', fixpix='no', \ overscan='no', trim='yes', zerocor='yes', zero=p['bias'], \ darkcor='Yes', dark=p['dark'], flatcor='no', readaxi='column', \ biassec='', trimsec=telescope.trimsection) # divide images by filter and flat combine for filter in filters: print 'Combine flat fields - Filter %s' % filter # create text list for iraf flatlist = open('flatlist', 'w') for frame in frameflat: if frame['filter'] == filter: flatlist.write("%s\n" % frame['path']) flatlist.close() iraf.flatcombine(PYinput = '@flatlist', output='MasterFlat-%s.fits' % filter, ccdtype='', \ combine='median', reject='none', process='no', subsets='no', \ delete='no', clobber='no', scale='mode', statsec=' ', nlow='1', \ nhigh='1', nkeep='1', mclip='yes', lsigma='5.', hsigma='5.', \ rdnoise=telescope.rdnoise, gain=telescope.egain, snoise='0.', pclip='-0.5',blank='1.') os.remove('flatlist') # remove working files & temp lists for f in framelist: os.remove(os.path.join(os.path.dirname(f), 'CORR_'+os.path.basename(f))) os.remove('tmplist') os.remove('tmplistcorr')