def scireduce(scifiles, rawpath): for f in scifiles: setupname = getsetupname(f) # gsreduce subtracts bias and mosaics detectors iraf.unlearn(iraf.gsreduce) iraf.gsreduce('@' + f, outimages=f[:-4]+'.mef', rawpath=rawpath, bias="bias", fl_over=dooverscan, fl_fixpix='no', fl_flat=False, fl_gmosaic=False, fl_cut=False, fl_gsappwave=False, fl_oversize=False) if is_GS: # Renormalize the chips to remove the discrete jump in the # sensitivity due to differences in the QE for different chips iraf.unlearn(iraf.gqecorr) iraf.gqecorr(f[:-4]+'.mef', outimages=f[:-4]+'.qe.fits', fl_keep=True, fl_correct=True, refimages=setupname + '.arc.arc.fits', corrimages=setupname +'.qe.fits', verbose=True) iraf.unlearn(iraf.gmosaic) iraf.gmosaic(f[:-4]+'.qe.fits', outimages=f[:-4] +'.fits') else: iraf.unlearn(iraf.gmosaic) iraf.gmosaic(f[:-4]+'.mef.fits', outimages=f[:-4] +'.fits') # Flat field the image hdu = pyfits.open(f[:-4]+'.fits', mode='update') hdu['SCI'].data /= pyfits.getdata(setupname+'.flat.fits', extname='SCI') hdu.flush() hdu.close() # Transform the data based on the arc wavelength solution iraf.unlearn(iraf.gstransform) iraf.gstransform(f[:-4], wavtran=setupname + '.arc')
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 transform(self, image, lamRef, pref="t", vardq="no", logPath="", \ verbose="yes", frameNo=2): print "RUNNING GSTRANSFORM" # stash task settings self.stashSettings('gstransform', outpref=pref, wavtraname=lamRef, \ fl_vardq=vardq, logfile=logPath) # next delete previous copy of the output (should it exist) iraf.imdel(pref + image) # run gstransform and view output iraf.gstransform(image, outpref=pref, wavtraname=lamRef, \ fl_vardq=vardq, logfile=logPath, verbose=verbose) image = pref + image self.viewIm(image, frameNo=frameNo) 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])
def scireduce(scifiles, rawpath): for f in scifiles: binning = get_binning(f, rawpath) setupname = getsetupname(f) if dobias: bias_filename = "bias{binning}".format(binning=binning) else: bias_filename = '' # gsreduce subtracts bias and mosaics detectors iraf.unlearn(iraf.gsreduce) iraf.gsreduce('@' + f, outimages=f[:-4]+'.mef', rawpath=rawpath, bias=bias_filename, fl_bias=dobias, fl_over=dooverscan, fl_fixpix='no', fl_flat=False, fl_gmosaic=False, fl_cut=False, fl_gsappwave=False, fl_oversize=False, fl_vardq=dodq) if do_qecorr: # Renormalize the chips to remove the discrete jump in the # sensitivity due to differences in the QE for different chips iraf.unlearn(iraf.gqecorr) iraf.gqecorr(f[:-4]+'.mef', outimages=f[:-4]+'.qe.fits', fl_keep=True, fl_correct=True, fl_vardq=dodq, refimages=setupname + '.arc.arc.fits', corrimages=setupname +'.qe.fits', verbose=True) iraf.unlearn(iraf.gmosaic) iraf.gmosaic(f[:-4]+'.qe.fits', outimages=f[:-4] +'.fits', fl_vardq=dodq, fl_clean=False) else: iraf.unlearn(iraf.gmosaic) iraf.gmosaic(f[:-4]+'.mef.fits', outimages=f[:-4] +'.fits', fl_vardq=dodq, fl_clean=False) # Flat field the image hdu = fits.open(f[:-4]+'.fits', mode='update') hdu['SCI'].data /= fits.getdata(setupname+'.flat.fits', extname='SCI') hdu.flush() hdu.close() # Transform the data based on the arc wavelength solution iraf.unlearn(iraf.gstransform) iraf.gstransform(f[:-4], wavtran=setupname + '.arc', fl_vardq=dodq)
current_sci = prefix_sci + i current_sky = prefix_sky + i header = pyfits.getheader(current_sci) flat = 'dc_m%s' % header['FLATIM'] arc = 'gsN20011222S013.fits' #this is hardcoded bc I picked the best one by hand for this instrument setup (mask1 cw660nm) #this is also the name of the wavelength calibrated arc frame. #mosaicing the sky frames (the arc was mosaiced in cuar_reducion's gsreduce and the sci in the cosmic ray cleaning) #then cutting the mosaic-processed sky based on the flat field listed in the science header; (arc done in cuar_reduction) gmos.gmosaic(inimages=current_sky, fl_paste='no', fl_fixpix='yes', geointer='linear') #it complains about fl_clean but goes on anyway mosaic_sky = 'm'+prefix_sky+i gmos.gscut(mosaic_sky, refimage=flat, outimage='c'+mosaic_sky, fl_update='yes') cut_sky = 'c'+mosaic_sky #transforming the science and sky frame based on the wavelength information from the arc frame iraf.gstransform(inimage=current_sci, wavtraname=arc[:-5], database=database) iraf.gstransform(inimage=cut_sky, wavtraname=arc[:-5], database=database) sci_mask1_670 = [line.strip() for line in open('sci_mask1_670')] for i in sci_mask1_670: current_sci = prefix_sci + i current_sky = prefix_sky + i header = pyfits.getheader(current_sci) flat = 'dc_m%s' % header['FLATIM'] arc = 'gsN20011218S045.fits' #this is hardcoded bc I picked the best one by hand for this instrument setup (mask1 cw660nm) #this is also the name of the wavelength calibrated arc frame. #mosaicing the sky frames (the arc was mosaiced in cuar_reducion's gsreduce and the sci in the cosmic ray cleaning) #then cutting the mosaic-processed sky based on the flat field listed in the science header; (arc done in cuar_reduction) gmos.gmosaic(inimages=current_sky, fl_paste='no', fl_fixpix='yes', geointer='linear') #it complains about fl_clean but goes on anyway
#central wavelength of 660nm: arc_mask2_660 = [line.strip() for line in open('arc_mask2_660')] for i in arc_mask2_660: current_arc = i iraf.gsreduce(inimages=rawdir+current_arc, fl_bias = 'no', fl_flat = 'no', mdfdir=proc_logs, refimage=flat_mask2_660) #central wavelength of 670nm: arc_mask2_670 = [line.strip() for line in open('arc_mask2_670')] for i in arc_mask2_670: current_arc = i iraf.gsreduce(inimages=rawdir+current_arc, fl_bias = 'no', fl_flat = 'no', mdfdir=proc_logs, refimage=flat_mask2_670) #Run gswavelength on the arc frames; this is the part that requires interaction. This interaction is needed to remove any crazy (wrong) lines that may have been fitted. Typically very obvious. You delete them in the window by mousing over a point, pressing 'd' for delete and then 'y' for the entire row. iraf.gswavelength(inimages='gsN*.fits', order=6, fitcxord=6, nsum=5, step=5) ''' #Run gtransform on the arc frames after gswavelength is done, to wavelength calibrate them (pixel space to wavelength space) iraf.gstransform(inimages='gsN20011218S045.fits', wavtraname='gsN20011218S045') iraf.gstransform(inimages='gsN20011222S013.fits', wavtraname='gsN20011222S013') iraf.gstransform(inimages='gsN20011222S016.fits', wavtraname='gsN20011222S016') iraf.gstransform(inimages='gsN20011222S017.fits', wavtraname='gsN20011222S017') #Running transform actually extends the y-dimension of the image by a few pixels; this may create issues later? end = time.strftime("%H:%M:%S") print "Start time: ", start print "End time: ", end
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', wavtran='gs//@CuAr_b600_525_1.txt') iraf.gstransform(inimages='gs//@object_b600_525_2.txt', wavtran='gs//@CuAr_b600_525_1.txt') iraf.gstransform(inimages='gs//@object_b600_525_3.txt', wavtran='gs//@CuAr_b600_525_1.txt') #log? l.write('wavelength=yes')
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) iraf.gsstandard('estgs' + star, sfile='std', sfunction='sens', caldir='onedstds$ctionewcal/', starname='l3218') vardq = 'yes' for i in gal: iraf.gsreduce(rawdir + i, rawpath=rawdir, bias=rawdir + bias, fl_fixpix='yes', flat='flat.fits',
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..") # Get nearest arc by time. arc_times = [] for arc_filename in arc_filenames: image = fits.open(arc_filename) time_string = "{0}T{1}".format( image[0].header["DATE"], image[0].header["UT"]) \
# Reduce. iraf.gsreduce(path, bias="master_bias.fits", flatim="master_flat.fits", fl_fixpix=False, fl_oversize=False, fl_vardq=True, fl_fulldq=True) #fl_gscrrej=True) # Get the closest arc. arc = _get_closest(frame, arcs, match_keys=("grating", )) arc_path = "gs{}".format(os.path.basename(arc["path"])) iraf.unlearn("gstransform") iraf.gstransform("gs{}".format(path), wavtraname=arc_path, fl_vardq=True) # Sky subtraction. iraf.unlearn("gsskysub") iraf.gsskysub("tgs{}".format(path), fl_vardq=True, fl_inter=False) # Extraction. iraf.unlearn("gsextract") iraf.gsextract("stgs{}".format(path), **extract_kwds) # Load and perform continuum normalisation. disp, flux, ivar, dq, meta = load_gemini_spectrum("estgs{}".format(path)) # split into channels and normalize. split_points = [4460, 5520] split_indices = np.hstack(