def wavesol(arcfiles, rawpath): for f in arcfiles: binning = get_binning(f, rawpath) iraf.unlearn(iraf.gsreduce) if dobias: bias_filename = "bias{binning}".format(binning=binning) else: bias_filename = '' iraf.gsreduce('@' + f, outimages=f[:-4], rawpath=rawpath, fl_flat=False, bias=bias_filename, fl_bias=dobias, fl_fixpix=False, fl_over=dooverscan, fl_cut=False, fl_gmosaic=True, fl_gsappwave=True, fl_oversize=False, fl_vardq=dodq) # determine wavelength calibration -- 1d and 2d iraf.unlearn(iraf.gswavelength) iraf.gswavelength(f[:-4], fl_inter='yes', fl_addfeat=False, fwidth=15.0, low_reject=2.0, high_reject=2.0, step=10, nsum=10, gsigma=2.0, cradius=16.0, match=-6, order=7, fitcxord=7, fitcyord=7) if do_qecorr: # Make an extra random copy so that gqecorr works. Stupid Gemini. iraf.cp(f[:-4]+'.fits', f[:-4]+'.arc.fits') # transform the CuAr spectrum, for checking that the transformation is OK # output spectrum has prefix t iraf.unlearn(iraf.gstransform) iraf.gstransform(f[:-4], wavtran=f[:-4])
def calWave(self, arcList, **kwargs): iraf.gswavelength(arcList, **kwargs) # TODO: include call to gftransform to rectify arcs? return
def wavesol(arcfiles, rawpath): for f in arcfiles: iraf.unlearn(iraf.gsreduce) iraf.gsreduce('@' + f, outimages=f[:-4], rawpath=rawpath, fl_flat=False, bias="bias", fl_fixpix=False, fl_over=dooverscan, fl_cut=False, fl_gmosaic=True, fl_gsappwave=True, fl_oversize=False) # determine wavelength calibration -- 1d and 2d iraf.unlearn(iraf.gswavelength) iraf.gswavelength(f[:-4], fl_inter='yes', fwidth=15.0, low_reject=2.0, high_reject=2.0, step=10, nsum=10, gsigma=2.0, cradius=16.0, match=-6, order=7, fitcxord=7, fitcyord=7) if is_GS: # Make an extra random copy so that gqecorr works. Stupid Gemini. shutil.copy(f[:-4]+'.fits', f[:-4]+'.arc.fits') # transform the CuAr spectrum, for checking that the transformation is OK # output spectrum has prefix t iraf.unlearn(iraf.gstransform) iraf.gstransform(f[:-4], wavtran=f[:-4])
scidir= '/Users/bkirk/Documents/A851/Science/' proc_logs='/Users/bkirk/Documents/A851/proc_logs/' calibdir='/Users/bkirk/Documents/A851/bias_frame/' flatdir='/Users/bkirk/Documents/A851/Flat/' gmos.logfile="A851_cuar.log" #At the moment it'll be easier to pick the flats by hand rather than scripting a way through to find a flat that matches the arc frame specs. These are the flats whose dimensions I'll use to cut the arc frames. flat_mask1_660 = '%sdc_mN20011221S139_norm_flat.fits' % scidir flat_mask1_670 = '%sdc_mN20011220S156_norm_flat.fits' % scidir flat_mask2_660 = '%sdc_mN20011224S127_norm_flat.fits' % scidir flat_mask2_670 = '%sdc_mN20011222S112_norm_flat.fits' % scidir ''' #Run GSREDUCE on the arc frames, separated by different central wavelength files, and match the arc files with their respective proc_log and reference files (the reference files here are the stich & slitted flat frames that are paired to them (same mask and central wavelength). Should the x and y offsets have the same settings as the flat frames? <- There aren't any internal emisson lines to mask out in the arc. Inger's settings have different values for the different arc frames, so I may as well put them in. #GSREDUCE calls GSAPPWAVE at the end so it's already done. GSREDUCE has options which include mosaic'ing and cutting; the mosaic'ing does so with interpolation on. This produces arc frames that are in MEF format and are transformed and have a prefix 't' to them #### mask 1 #### #central wavelength of 660nm: arc_mask1_660 = [line.strip() for line in open('arc_mask1_660')] for i in arc_mask1_660: current_arc = i iraf.gsreduce(inimages=rawdir+current_arc, fl_bias = 'no', fl_flat = 'no', mdfdir=proc_logs, refimage=flat_mask1_660) #central wavelength of 670nm: arc_mask1_670 = [line.strip() for line in open('arc_mask1_670')] for i in arc_mask1_670:
iraf.gsreduce(inimages='@CuAr_b600_520_1.txt', flatim='b600_520_norm_flat_1.fits', fl_bias=no, fl_crspec=no) iraf.gsreduce(inimages='@CuAr_b600_525_1.txt', flatim='b600_525_norm_flat_1.fits', fl_bias=no, fl_crspec=no) #log? l.write('reduced=yes') #Wavelength calibrate ARCs in 2d iraf.gswavelength(inimages='gs//@CuAr_b600_520_1.txt') iraf.gswavelength(inimages='gs//@CuAr_b600_525_1.txt') #log? l.write('arcs=yes') #Applying Wavelength Calibration to Science Images iraf.gstransform(inimages='gs//@object_b600_520_1.txt', wavtran='gs//@CuAr_b600_520_1.txt') iraf.gstransform(inimages='gs//@object_b600_520_2.txt', wavtran='gs//@CuAr_b600_520_1.txt') iraf.gstransform(inimages='gs//@object_b600_520_3.txt', wavtran='gs//@CuAr_b600_520_1.txt') iraf.gstransform(inimages='gs//@object_b600_525_1.txt',
# Reduce the arc image iraf.gsreduce(rawdir + arc, rawpath=rawdir, bias=rawdir + bias, fl_fixpix='yes', flat='flat.fits', fl_over='no') iraf.gsreduce(rawdir + arc_star, rawpath=rawdir, bias=rawdir + bias_star, fl_fixpix='yes', flat='flat_star.fits', fl_over='no') # Fit wavelength solution iraf.gswavelength('gs' + arc, fl_inter='no') iraf.gswavelength('gs' + arc_star, fl_inter='no') # Reduce standard star iraf.gsreduce(rawdir + star, rawpath=rawdir, bias=rawdir + bias_star, fl_fixpix='yes', flat='flat_star.fits', fl_over='no', fl_gscrrej='yes', fl_vardq='yes') iraf.gstransform('gs' + star, wavtraname='gs' + arc_star.replace('.fits', '')) iraf.gsskysub('tgs' + star, long_sample='150:200') iraf.gsextract('stgs' + star)
# Reduce the arc frames logger.info("Reducing arc frames..") for filename in arc_filenames: reduce_arc_result = iraf.gsreduce("g{0}".format(filename), fl_over=False, fl_trim=True, fl_bias=False, fl_dark=False, fl_flat=False, fl_cut=True, fl_gsappwave=True, yoffset=5.0, Stdout=1) log_iraf_result(reduce_arc_result) logger.info("Running gswavelength..") #gswavelength_result = iraf.gswavelength("gsg{0}".format(filename), # fl_inter="NO", nsum=5, step=5, function='chebyshev', order=6, # fitcxord=5, fitcyord=4, Stdout=1) gswavelength_result = iraf.gswavelength("gsg{0}".format(filename), fl_inter="NO", nsum=5, step=5, function="chebyshev", order="6", fitcxord=5, fitcyord=4, Stdout=1, niterate=10, low_reject=1.5, high_reject=1.5, fl_dbwrite="YES", fl_overwrite="yes") log_iraf_result(gswavelength_result) # Apply transformations logger.info("Applying wavelength transformations to arc..") gstransform_arc_result = iraf.gstransform("gsg{0}".format(filename), wavtraname="gsg{0}".format(filename), Stdout=1) log_iraf_result(gstransform_arc_result) logger.info("Doing wavelength transformations, sky and extraction:") for object_filename in object_filenames: logger.info("Working on filename {}".format(object_filename)) logger.info("Applying wavelength transformations to object..")
fl_bias=no) iraf.gsreduce(inimages='@object_b600_2.txt', flatim='b600_norm_flat_2.fits', fl_bias=no) iraf.gsreduce(inimages='@CuAr_r400_2.txt', flatim='r400_norm_flat_2.fits', fl_bias=no) iraf.gsreduce(inimages='@CuAr_b600_2.txt', flatim='b600_norm_flat_2.fits', fl_bias=no) #log? l.write('reduced=yes') #Wavelength calibrate ARCs in 2d iraf.gswavelength(inimages='gs//@CuAr_r400_1.txt') iraf.gswavelength(inimages='gs//@CuAr_b600_1.txt') iraf.gswavelength(inimages='gs//@CuAr_r400_2.txt') iraf.gswavelength(inimages='gs//@CuAr_b600_2.txt') #log? l.write('arcs=yes') #Applying Wavelength Calibration to Science Images iraf.gstransform(inimages='gs//@object_r400_1.txt', wavtran='gs//@CuAr_r400_1.txt') iraf.gstransform(inimages='gs//@object_b600_1.txt', wavtran='gs//@CuAr_b600_1.txt') iraf.gstransform(inimages='gs//@object_b600_2.txt', wavtran='gs//@CuAr_b600_2.txt') iraf.gstransform(inimages='gs//@object_r400_2.txt',
# ---------- Wavelength solution ---------- # # Extract the arc flatref = iraf.type(ic.lst_flat, Stdout=1)[0].strip() iraf.imdelete('g@'+ic.lst_arc) iraf.imdelete('rg@'+ic.lst_arc) iraf.imdelete('erg@'+ic.lst_arc) for arc in iraf.type(ic.lst_arc, Stdout=1): arc = arc.strip() iraf.gfreduce(arc, rawpath=ic.rawdir, fl_extract='yes', recenter='no', trace='no', reference='erg'+flatref, fl_bias='no', fl_over='yes', fl_trim='yes', mdffile=ic.nmdf, mdfdir='./', slits='both', fl_fluxcal='no', fl_gscrrej='no', fl_wavtran='no', fl_skysub='no', fl_inter='no') iraf.sleep(10.0) # ----- Measure the wavelength solution ----- # for arc in iraf.type(ic.lst_arc, Stdout=1): arc = arc.strip() iraf.gswavelength('erg'+arc, fl_inter='yes', nlost=20, ntarget=15, threshold=25, coordlis='gmos$data/GCALcuar.dat') # Printing the running time print('--- %s seconds ---' %(time.time()-start_time))
path = os.path.basename(arc["path"]) iraf.unlearn("gireduce") iraf.unlearn("gsflat") iraf.unlearn("gemextn") iraf.gsreduce(path, bias="master_bias.fits", fl_fixpix=False, fl_flat=False, fl_oversize=False) # Do wavelength calibration on arc frames. iraf.unlearn("gswavelength") iraf.gswavelength("gs{}".format(path), **gswavelength_kwds) # Reduce all science frames. science_frames = association[(association["obsclass"] == "science") \ + ((association["obstype"] == "OBJECT") * (association["obsclass"] == "partnerCal"))] # Load template spectrum. template_disp, template_flux, _ = np.loadtxt("Atlas.Arcturus.372_926nm.txt", skiprows=1).T template_disp *= 10.0 for frame in science_frames: path = os.path.basename(frame["path"]) iraf.unlearn("gireduce")
def reduce_stdstar(rawdir, rundir, caldir, starobj, stdstar, flat, arc, twilight, starimg, bias, overscan, vardq): """ Reduction pipeline for standard star. Parameters ---------- rawdir: string Directory containing raw images. rundi: string Directory where processed files are saved. caldir: string Directory containing standard star calibration files. starobj: string Object keyword for the star image. stdstar: string Star name in calibration file. flat: list Names of the files containing flat field images. arc: list Arc images. twilight: list Twilight flat images. starimg: string Name of the file containing the image to be reduced. bias: list Bias images. """ iraf.set(stdimage='imtgmos') iraf.gemini() iraf.gemtools() iraf.gmos() #iraf.unlearn('gemini') #iraf.unlearn('gmos') iraf.task(lacos_spec='/storage/work/gemini_pairs/lacos_spec.cl') tstart = time.time() #set directories iraf.set(caldir=rawdir) # iraf.set(rawdir=rawdir) # raw files iraf.set(procdir=rundir) # processed files iraf.gmos.logfile='logfile.log' iraf.cd('procdir') # building lists def range_string(l): return (len(l)*'{:4s},').format(*[i[-9:-5] for i in l]) iraf.gemlist(range=range_string(flat), root=flat[0][:-9], Stdout='flat.list') iraf.gemlist(range=range_string(arc), root=arc[0][:-9], Stdout='arc.list') #iraf.gemlist(range=range_string(star), root=star[0][:-4], # Stdout='star.list') iraf.gemlist(range=range_string(twilight), root=twilight[0][:-9], Stdout='twilight.list') iraf.gfreduce.bias = 'caldir$'+bias[0] ####################################################################### ####################################################################### ### Star reduction # ####################################################################### ####################################################################### # # Flat reduction # iraf.gfreduce( '@flat.list', slits='header', rawpath='rawdir$', fl_inter='no', fl_addmdf='yes', key_mdf='MDF', mdffile='default', weights='no', fl_over=overscan, fl_trim='yes', fl_bias='yes', trace='yes', t_order=4, fl_flux='no', fl_gscrrej='no', fl_extract='yes', fl_gsappwave='no', fl_wavtran='no', fl_novl='no', fl_skysub='no', reference='', recenter='yes', fl_vardq=vardq) iraf.gfreduce('@twilight.list', slits='header', rawpath='rawdir$', fl_inter='no', fl_addmdf='yes', key_mdf='MDF', mdffile='default', weights='no', fl_over=overscan, fl_trim='yes', fl_bias='yes', trace='yes', recenter='no', fl_flux='no', fl_gscrrej='no', fl_extract='yes', fl_gsappwave='no', fl_wavtran='no', fl_novl='no', fl_skysub='no', reference='erg'+flat[0], fl_vardq=vardq) # # Response function # for i, j in enumerate(flat): j = j[:-5] iraf.imdelete(j+'_response') iraf.gfresponse('erg'+j+'.fits', out='erg'+j+'_response', skyimage='erg'+twilight[i], order=95, fl_inter='no', func='spline3', sample='*', verbose='yes') # Arc reduction # iraf.gfreduce( '@arc.list', slits='header', rawpath='rawdir$', fl_inter='no', fl_addmdf='yes', key_mdf='MDF', mdffile='default', weights='no', fl_over=overscan, fl_trim='yes', fl_bias='yes', trace='no', recenter='no', fl_flux='no', fl_gscrrej='no', fl_extract='yes', fl_gsappwave='no', fl_wavtran='no', fl_novl='no', fl_skysub='no', reference='erg'+flat[0], fl_vardq=vardq) # Finding wavelength solution # Note: the automatic identification is very good # for i in arc: iraf.gswavelength('erg'+i, function='chebyshev', nsum=15, order=4, fl_inter='no', nlost=5, ntarget=20, aiddebug='s', threshold=5, section='middle line') # # Apply wavelength solution to the lamp 2D spectra # iraf.gftransform('erg'+i, wavtran='erg'+i, outpref='t', fl_vardq=vardq) ## ## Actually reduce star ## iraf.gfreduce( starimg, slits='header', rawpath='rawdir$', fl_inter='no', fl_addmdf='yes', key_mdf='MDF', mdffile='default', weights='no', fl_over=overscan, fl_trim='yes', fl_bias='yes', trace='no', recenter='no', fl_flux='no', fl_gscrrej='no', fl_extract='no', fl_gsappwave='no', fl_wavtran='no', fl_novl='yes', fl_skysub='no', fl_vardq=vardq) iraf.gemcrspec('rg{:s}'.format(starimg), out='lrg'+starimg, sigfrac=0.32, niter=4, fl_vardq=vardq) iraf.gfreduce( 'lrg'+starimg, slits='header', rawpath='./', fl_inter='no', fl_addmdf='no', key_mdf='MDF', mdffile='default', fl_over='no', fl_trim='no', fl_bias='no', trace='no', recenter='no', fl_flux='no', fl_gscrrej='no', fl_extract='yes', fl_gsappwave='yes', fl_wavtran='yes', fl_novl='no', fl_skysub='yes', reference='erg'+flat[0][:-5], weights='no', wavtraname='erg'+arc[0][:-5], response='erg'+flat[0][:-5]+'_response.fits', fl_vardq=vardq) # # Apsumming the stellar spectra # iraf.gfapsum( 'stexlrg'+starimg, fl_inter='no', lthreshold=400., reject='avsigclip') # # Building sensibility function # iraf.gsstandard( ('astexlrg{:s}').format(starimg), starname=stdstar, observatory='Gemini-South', sfile='std', sfunction='sens', caldir=caldir) # # Apply flux calibration to galaxy # # ##iraf.imdelete('*****@*****.**') # ##iraf.gscalibrate('*****@*****.**',sfunction='sens.fits',fl_ext='yes',extinct='onedstds$ctioextinct.dat',observatory='Gemini-South',fluxsca=1) # ## ## Create data cubes ## # # ##for i in objs: ## iraf.imdelete('d0.1cstexlrg'+i+'.fits') ## iraf.gfcube('cstexlrg'+i+'.fits',outpref='d0.1',ssample=0.1,fl_atmd='yes',fl_flux='yes') # ## ## Combine cubes ## # # ##iraf.imdelete('am2306-721r4_wcsoffsets.fits') ##iraf.imcombine('d0.1cstexlrgS20141113S00??.fits[1]',output='am2306-721r4_wcsoffsets.fits',combine='average',reject='sigclip',masktype='badvalue',lsigma=2,hsigma=2,offset='wcs',outlimits='2 67 2 48 100 1795') # tend = time.time() print('Elapsed time in reduction: {:.2f}'.format(tend - tstart))
iraf.gfreduce('@arc'+str(m)+'.list', slits='header', rawpath='rawdir$', fl_inter='no', fl_addmdf='yes', key_mdf='MDF', mdffile='default', weights='no', fl_over='yes', fl_trim='yes', fl_bias='no', trace='no', recenter='no', fl_flux='no', fl_gscrrej='no', fl_extract='yes', fl_gsappwave='no', fl_wavtran='no', fl_novl='no', fl_skysub='no', reference='erg'+flat[m][0], fl_vardq='no', bias='caldir$'+bias[m][0]) # # Finding wavelength solution # Note: the automatic identification is very good # for m in range(len(star)): for i in arc[m]: iraf.gswavelength('erg'+i, function='chebyshev', nsum=15, order=4, fl_inter='no', nlost=5, ntarget=20, aiddebug='s', threshold=5, section='middle line') # # Apply wavelength solution to the lamp 2D spectra # for m in range(len(star)): for i in arc[m]: # (B) Fiz fl_vardq-, pois mudei acima tambem -------- iraf.imdelete('terg'+i+'.fits') iraf.gftransform('erg'+i, wavtran='erg'+i, outpref='t', fl_vardq='no') ## ## Actually reduce star ##