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 make_qecorrection(arcfiles): for f in arcfiles: if is_GS: #read in the arcfile name with open(f) as txtfile: arcimage = txtfile.readline() # Strip off the newline character arcimage = 'g' + arcimage.split('\n')[0] if not os.path.exists(f[:-8] +'.qe.fits'): iraf.gqecorr(arcimage, refimages=f[:-4]+'.arc.fits', fl_correct=False, fl_keep=True, corrimages=f[:-8] +'.qe.fits', verbose=True)
def correctQE(self, inIm, **kwargs): print "\nCORRECTING QE IN " + inIm # delete previous correction data and QE-corrected exposure iraf.imdelete("q" + inIm) iraf.imdelete("qecorr" + kwargs["refimages"]) iraf.gqecorr(inIm, **kwargs) return
def make_qecorrection(arcfiles): for f in arcfiles: if do_qecorr: #read in the arcfile name with open(f) as txtfile: arcimage = txtfile.readline() # Strip off the newline character arcimage = 'g' + arcimage.split('\n')[0] if not os.path.exists(f[:-8] +'.qe.fits'): iraf.gqecorr(arcimage, refimages=f[:-4]+'.arc.fits', fl_correct=False, fl_keep=True, corrimages=f[:-8] +'.qe.fits', verbose=True, fl_vardq=dodq)
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.unlearn('gfextract') iraf.unlearn('gfdisplay') # ---------- QE correction and extraction of the science ---------- # flat0 = iraf.type(ic.lst_flat, Stdout=1)[0].strip() response = flat0+'_resp' ref_flat0 = 'eqbrg'+flat0 arc0 = iraf.type(ic.lst_arc, Stdout=1)[0].strip() iraf.imdelete('qxbrg@'+ic.lst_sci) iraf.imdelete('eqxbrg@'+ic.lst_sci) for sci in iraf.type(ic.lst_sci, Stdout=1): sci = sci.strip() iraf.gqecorr('xbrg'+sci, refimage='erg'+arc0, fl_correct='yes', fl_vardq='yes', verbose='yes') iraf.gfextract('qxbrg'+sci, response=response, recenter='no', trace='no', reference=ref_flat0, weights='none', fl_vardq='yes', line=1400) os.system('ds9 &') iraf.sleep(5.0) for sci in iraf.type(ic.lst_sci, Stdout=1): sci = sci.strip() iraf.gfdisplay('eqxbrg'+sci, 1) # Printing the running time print('--- %s seconds ---' %(time.time()-start_time))