def reduce(self, image, pref="gs", bias="no", gscrrej="no", crspec="no", \ qecorr="no", flat="no", fixpix="yes", vardq="no", biasPath="", \ flatPath="", refimPath="", imPath="", bpmPath="gmos$data/chipgaps.dat", \ logPath="", verbose="yes", frameNo=1): print "RUNNING GSREDUCE" # stash task settings self.stashSettings('gsreduce', outpref=pref, fl_bias=bias, \ bias=biasPath, fl_flat=flat, flatim=flatPath, fl_qecorr=qecorr, \ qe_refim=refimPath, fl_gscrrej=gscrrej, fl_crspec=crspec, \ fl_fixpix=fixpix, fl_vardq=vardq, bpm=bpmPath, logfile=logPath) # next delete previous copies of the output (should they exist) iraf.imdel("g" + image) iraf.imdel(pref + image) # run gsreduce and view output iraf.gsreduce(image, outpref=pref, fl_bias=bias, fl_gscrrej=gscrrej, \ fl_crspec=crspec, fl_qecorr=qecorr, fl_flat=flat, fl_fixpix=fixpix, \ fl_vardq=vardq, bias=biasPath, flatim=flatPath, qe_refim=refimPath, \ rawpath=imPath, bpm=bpmPath, logfile=logPath, verbose=verbose) image = pref + image self.viewIm(image, frameNo=frameNo) return
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 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 makemasterflat(flatfiles, rawpath, plot=True): # normalize the flat fields for f in flatfiles: binning = get_binning(f, rawpath) # Use IRAF to get put the data in the right format and subtract the # bias # This will currently break if multiple flats are used for a single setting iraf.unlearn(iraf.gsreduce) if dobias: biasfile = "bias{binning}".format(binning=binning) else: biasfile = '' iraf.gsreduce('@' + f, outimages = f[:-4]+'.mef.fits',rawpath=rawpath, fl_bias=dobias, bias=biasfile, fl_over=dooverscan, fl_flat=False, fl_gmosaic=False, fl_fixpix=False, fl_gsappwave=False, fl_cut=False, fl_title=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, refimages=f[:-4].replace('flat', 'arc.arc.fits'), corrimages=f[:-9] +'.qe.fits', verbose=True, fl_vardq=dodq) iraf.unlearn(iraf.gmosaic) iraf.gmosaic(f[:-4]+'.qe.fits', outimages=f[:-4]+'.mos.fits', fl_vardq=dodq, fl_clean=False) else: iraf.unlearn(iraf.gmosaic) iraf.gmosaic(f[:-4]+'.mef.fits', outimages=f[:-4]+'.mos.fits', fl_vardq=dodq, fl_clean=False) flat_hdu = fits.open(f[:-4] + '.mos.fits') data = np.median(flat_hdu['SCI'].data, axis=0) chip_edges = get_chipedges(data) x = np.arange(len(data), dtype=np.float) x /= x.max() y = data / np.median(data) fitme_x = x[chip_edges[0][0]:chip_edges[0][1]] fitme_x = np.append(fitme_x, x[chip_edges[1][0]:chip_edges[1][1]]) fitme_x = np.append(fitme_x, x[chip_edges[2][0]:chip_edges[2][1]]) fitme_y = y[chip_edges[0][0]:chip_edges[0][1]] fitme_y = np.append(fitme_y, y[chip_edges[1][0]:chip_edges[1][1]]) fitme_y = np.append(fitme_y, y[chip_edges[2][0]:chip_edges[2][1]]) fit = pfm.pffit(fitme_x, fitme_y, 21, 7, robust=True, M=sm.robust.norms.AndrewWave()) if plot: pyplot.ion() pyplot.clf() pyplot.plot(x, y) pyplot.plot(x, pfm.pfcalc(fit, x)) _junk = raw_input('Press enter to continue') flat_hdu['SCI'].data /= pfm.pfcalc(fit, x) * np.median(data) flat_hdu.writeto(f[:-4] + '.fits')
def makemasterflat(flatfiles, rawpath, plot=True): # normalize the flat fields for f in flatfiles: # Use IRAF to get put the data in the right format and subtract the # bias # This will currently break if multiple flats are used for a single setting iraf.unlearn(iraf.gsreduce) iraf.gsreduce('@' + f, outimages = f[:-4]+'.mef.fits',rawpath=rawpath, bias="bias", fl_over=dooverscan, fl_flat=False, fl_gmosaic=False, fl_fixpix=False, fl_gsappwave=False, fl_cut=False, fl_title=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=f[:-4].replace('flat', 'arc.arc.fits'), corrimages=f[:-9] +'.qe.fits', verbose=True) iraf.unlearn(iraf.gmosaic) iraf.gmosaic(f[:-4]+'.qe.fits', outimages=f[:-4]+'.mos.fits') else: iraf.unlearn(iraf.gmosaic) iraf.gmosaic(f[:-4]+'.mef.fits', outimages=f[:-4]+'.mos.fits') flat_hdu = pyfits.open(f[:-4] + '.mos.fits') data = np.median(flat_hdu['SCI'].data, axis=0) chip_edges = get_chipedges(data) x = np.arange(len(data), dtype=np.float) x /= x.max() y = data / np.median(data) fitme_x = x[chip_edges[0][0]:chip_edges[0][1]] fitme_x = np.append(fitme_x, x[chip_edges[1][0]:chip_edges[1][1]]) fitme_x = np.append(fitme_x, x[chip_edges[2][0]:chip_edges[2][1]]) fitme_y = y[chip_edges[0][0]:chip_edges[0][1]] fitme_y = np.append(fitme_y, y[chip_edges[1][0]:chip_edges[1][1]]) fitme_y = np.append(fitme_y, y[chip_edges[2][0]:chip_edges[2][1]]) fit = pfm.pffit(fitme_x, fitme_y, 15, 7, robust=True, M=sm.robust.norms.AndrewWave()) if plot: from matplotlib import pyplot pyplot.ion() pyplot.clf() pyplot.plot(x, y) pyplot.plot(x, pfm.pfcalc(fit, x)) _junk = raw_input('Press enter to continue') flat_hdu['SCI'].data /= pfm.pfcalc(fit, x) * np.median(data) flat_hdu.writeto(f[:-4] + '.fits')
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)
iraf.gsflat(inflats='@flatb600_525_3.txt', specflat='b600_525_norm_flat_3.fits', order=20, fl_over=yes, fl_bias=no, fl_inter=no, fl_detec=yes, fl_seprows=no) #log? l.write('flats=yes') #Reduce Science Arc and Standard Star Images iraf.gsreduce(inimages='@object_b600_520_1.txt', flatim='b600_520_norm_flat_1.fits', fl_bias=no, fl_crspec=yes) iraf.gsreduce(inimages='@object_b600_520_2.txt', flatim='b600_520_norm_flat_2.fits', fl_bias=no, fl_crspec=yes) iraf.gsreduce(inimages='@object_b600_520_3.txt', flatim='b600_520_norm_flat_3.fits', fl_bias=no, fl_crspec=no) iraf.gsreduce(inimages='@object_b600_525_1.txt', flatim='b600_525_norm_flat_1.fits', fl_bias=no, fl_crspec=yes) iraf.gsreduce(inimages='@object_b600_525_2.txt',
bias=rawdir + bias, fl_over='no', fl_vardq=vardq, fl_fulldq=vardq) iraf.gsflat(rawdir + flat_star, specflat='flat_star.fits', rawpath=rawdir, bias=rawdir + bias_star, fl_over='no', fl_vardq=vardq, fl_fulldq=vardq) # 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,
fl_detec=True, ovs_flinter=False, fl_vardq=False, fl_bias=False, Stdout=1) log_iraf_result(flat_result) # Create a mosaic of the master flat logger.info("Creating master flat mosaic..") mosaic_result = iraf.gmosaic("master_flat.fits", outpref="mosaic_", Stdout=1) log_iraf_result(mosaic_result) # Reduce the science frame logger.info("Reducing science frame(s)..") for object_filename in object_filenames: logger.info("Reducing {}".format(object_filename)) reduce_science_result = iraf.gsreduce("cg{0}".format(object_filename), fl_inter=False, fl_over=False, fl_trim=True, fl_dark=False, fl_flat=True, flatim="mosaic_master_flat.fits", fl_gmosaic=True, fl_fixpix=True, fl_bias=False, fl_cut=True, fl_gsappwave=True, ovs_flinter=False, fl_vardq=False, yoffset=5.0, Stdout=1) log_iraf_result(reduce_science_result) # 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_seprows=no) iraf.gsflat(inflats='@flatr400_2.txt', specflat='r400_norm_flat_2.fits', fl_bias=no, fl_inter=no, fl_detec=yes, fl_seprows=no) #log? l.write('flats=yes') #Reduce Science Arc and Standard Star Images iraf.gsreduce(inimages='@object_r400_1.txt', flatim='r400_norm_flat_1.fits', fl_bias=no) iraf.gsreduce(inimages='@CuAr_r400_1.txt', flatim='r400_norm_flat_1.fits', fl_bias=no) iraf.gsreduce(inimages='@object_b600_1.txt', flatim='b600_norm_flat_1.fits', fl_bias=no) iraf.gsreduce(inimages='@CuAr_b600_1.txt', flatim='b600_norm_flat_1.fits', fl_bias=no) iraf.gsreduce(inimages='@object_r400_2.txt', flatim='r400_norm_flat_2.fits', fl_bias=no) iraf.gsreduce(inimages='@object_b600_2.txt', flatim='b600_norm_flat_2.fits',
**flat_kwds) # Reduce arcs. arcs = association[association["obstype"] == "ARC"] for arc in arcs: 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