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 reduce(self): """ Prepare, reduce, mosaic FITS File - currently using IRAF, to be replaced by our own constructs """ reduce_dir = os.path.join(self.fits.work_dir, 'reduced') if not os.path.exists(reduce_dir): os.mkdir(reduce_dir) reduce_fname = os.path.join(reduce_dir, 'red-{0}'.format(self.fits.fname)) if os.path.exists(reduce_fname): logger.warn('{0} exists - deleting') os.system('rm {0}'.format(reduce_fname)) from pyraf import iraf prepare_temp_fname = tempfile.NamedTemporaryFile().name reduce_temp_fname = tempfile.NamedTemporaryFile().name iraf.gemini() iraf.gmos() iraf.gprepare(self.fits.full_path, rawpath='', outimag=prepare_temp_fname) iraf.gireduce(inimages=prepare_temp_fname, outimag=reduce_temp_fname, fl_over=True, fl_trim=True, fl_bias=False, fl_dark=False, fl_qeco=False, fl_flat=False) iraf.gmosaic(inimages=reduce_temp_fname, outimages=reduce_fname) return reduce_fname
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)
"cg{0}".format(filename), Stdout=1) log_iraf_result(cosmic_ray_result) # Create a master flat logger.info("Creating master flat..") flat_result = iraf.gsflat(inflats="g{0}".format(flat_filename), specflat="master_flat.fits", fl_over=False, fl_trim=True, fl_dark=False, fl_fixpix=False, fl_inter=False, function="chebyshev", order=15, 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