def main(args): log = get_logger() log.info("starting at {}".format(time.asctime())) # Process frame = read_frame(args.infile) fiberflat = compute_fiberflat(frame, nsig_clipping=args.nsig, accuracy=args.acc, smoothing_res=args.smoothing_resolution) # QA if (args.qafile is not None): log.info("performing fiberflat QA") # Load qaframe = load_qa_frame(args.qafile, frame, flavor=frame.meta['FLAVOR']) # Run qaframe.run_qa('FIBERFLAT', (frame, fiberflat)) # Write if args.qafile is not None: write_qa_frame(args.qafile, qaframe) log.info("successfully wrote {:s}".format(args.qafile)) # Figure(s) if args.qafig is not None: qa_plots.frame_fiberflat(args.qafig, qaframe, frame, fiberflat) # Write write_fiberflat(args.outfile, fiberflat, frame.meta) log.info("successfully wrote %s" % args.outfile) log.info("done at {}".format(time.asctime()))
def run_pa(self,input_frame,outputfile): from desispec.fiberflat import compute_fiberflat import desispec.io.fiberflat as ffIO fiberflat=compute_fiberflat(input_frame) ffIO.write_fiberflat(outputfile,fiberflat,header=input_frame.meta) log.info("Fiberflat file wrtten. Exiting Quicklook for this configuration") #- File written no need to go further sys.exit(0)
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument( '--infile', type=str, default=None, required=True, help= 'path of DESI frame fits file corresponding to a continuum lamp exposure' ) parser.add_argument('--outfile', type=str, default=None, required=True, help='path of DESI fiberflat fits file') args = parser.parse_args() log = get_logger() log.info("starting") frame = read_frame(args.infile) fiberflat = compute_fiberflat(frame) write_fiberflat(args.outfile, fiberflat, frame.header) log.info("successfully wrote %s" % args.outfile)
def test_interface(self): """ Basic test that interface works and identical inputs result in identical outputs """ wave, flux, ivar, mask = _get_data() nspec, nwave = flux.shape #- Setup data for a Resolution matrix sigma = 4.0 ndiag = 21 xx = np.linspace(-(ndiag-1)/2.0, +(ndiag-1)/2.0, ndiag) Rdata = np.zeros( (nspec, ndiag, nwave) ) for i in range(nspec): for j in range(nwave): kernel = np.exp(-xx**2/(2*sigma)) kernel /= sum(kernel) Rdata[i,:,j] = kernel #- Run the code frame = Frame(wave, flux, ivar, mask, Rdata) ff = compute_fiberflat(frame) #- Check shape of outputs self.assertEqual(ff.fiberflat.shape, flux.shape) self.assertEqual(ff.ivar.shape, flux.shape) self.assertEqual(ff.mask.shape, flux.shape) self.assertEqual(len(ff.meanspec), nwave) #- Identical inputs should result in identical ouputs for i in range(1, nspec): self.assertTrue(np.all(ff.fiberflat[i] == ff.fiberflat[0])) self.assertTrue(np.all(ff.ivar[i] == ff.ivar[0]))
def test_resolution(self): """ Test that identical spectra convolved with different resolutions results in identical fiberflats """ wave, flux, ivar, mask = _get_data() nspec, nwave = flux.shape #- Setup a Resolution matrix that varies with fiber and wavelength #- Note: this is actually the transpose of the resolution matrix #- I wish I was creating, but as long as we self-consistently #- use it for convolving and solving, that shouldn't matter. sigma = np.linspace(2, 10, nwave*nspec) ndiag = 21 xx = np.linspace(-ndiag/2.0, +ndiag/2.0, ndiag) Rdata = np.zeros( (nspec, len(xx), nwave) ) for i in range(nspec): for j in range(nwave): kernel = np.exp(-xx**2/(2*sigma[i*nwave+j]**2)) kernel /= sum(kernel) Rdata[i,:,j] = kernel #- Convolve the data with the resolution matrix convflux = np.empty_like(flux) for i in range(nspec): convflux[i] = Resolution(Rdata[i]).dot(flux[i]) #- Run the code frame = Frame(wave, convflux, ivar, mask, Rdata) ff = compute_fiberflat(frame) #- These fiber flats should all be ~1 self.assertTrue( np.all(np.abs(ff.fiberflat-1) < 0.001) )
def test_interface(self): """ Basic test that interface works and identical inputs result in identical outputs """ wave, flux, ivar, mask = _get_data() nspec, nwave = flux.shape #- Setup data for a Resolution matrix sigma = 4.0 ndiag = 11 xx = np.linspace(-(ndiag - 1) / 2.0, +(ndiag - 1) / 2.0, ndiag) Rdata = np.zeros((nspec, ndiag, nwave)) kernel = np.exp(-xx**2 / (2 * sigma)) kernel /= sum(kernel) for i in range(nspec): for j in range(nwave): Rdata[i, :, j] = kernel #- Run the code frame = Frame(wave, flux, ivar, mask, Rdata, spectrograph=0) ff = compute_fiberflat(frame) #- Check shape of outputs self.assertEqual(ff.fiberflat.shape, flux.shape) self.assertEqual(ff.ivar.shape, flux.shape) self.assertEqual(ff.mask.shape, flux.shape) self.assertEqual(len(ff.meanspec), nwave) #- Identical inputs should result in identical ouputs for i in range(1, nspec): self.assertTrue(np.all(ff.fiberflat[i] == ff.fiberflat[0])) self.assertTrue(np.all(ff.ivar[i] == ff.ivar[0]))
def test_resolution(self): """ Test that identical spectra convolved with different resolutions results in identical fiberflats """ wave, flux, ivar, mask = _get_data() nspec, nwave = flux.shape #- Setup a Resolution matrix that varies with fiber and wavelength #- Note: this is actually the transpose of the resolution matrix #- I wish I was creating, but as long as we self-consistently #- use it for convolving and solving, that shouldn't matter. sigma = np.linspace(2, 10, nwave * nspec) ndiag = 21 xx = np.linspace(-ndiag / 2.0, +ndiag / 2.0, ndiag) Rdata = np.zeros((nspec, len(xx), nwave)) for i in range(nspec): for j in range(nwave): kernel = np.exp(-xx**2 / (2 * sigma[i * nwave + j]**2)) kernel /= sum(kernel) Rdata[i, :, j] = kernel #- Convolve the data with the resolution matrix convflux = np.empty_like(flux) for i in range(nspec): convflux[i] = Resolution(Rdata[i]).dot(flux[i]) #- Run the code frame = Frame(wave, convflux, ivar, mask, Rdata, spectrograph=0) ff = compute_fiberflat(frame) #- These fiber flats should all be ~1 self.assertTrue(np.all(np.abs(ff.fiberflat - 1) < 0.001))
def main(args) : log=get_logger() log.info("starting") # Process frame = read_frame(args.infile) fiberflat = compute_fiberflat(frame) # QA if (args.qafile is not None): log.info("performing fiberflat QA") # Load qaframe = load_qa_frame(args.qafile, frame, flavor=frame.meta['FLAVOR']) # Run qaframe.run_qa('FIBERFLAT', (frame, fiberflat)) # Write if args.qafile is not None: write_qa_frame(args.qafile, qaframe) log.info("successfully wrote {:s}".format(args.qafile)) # Figure(s) if args.qafig is not None: qa_plots.frame_fiberflat(args.qafig, qaframe, frame, fiberflat) # Write write_fiberflat(args.outfile, fiberflat, frame.meta) log.info("successfully wrote %s"%args.outfile)
def main(args): log = get_logger() log.info("starting") # Process frame = read_frame(args.infile) fiberflat = compute_fiberflat(frame) # QA if (args.qafile is not None): log.info("performing fiberflat QA") # Load qaframe = load_qa_frame(args.qafile, frame, flavor=frame.meta['FLAVOR']) # Run qaframe.run_qa('FIBERFLAT', (frame, fiberflat)) # Write if args.qafile is not None: write_qa_frame(args.qafile, qaframe) log.info("successfully wrote {:s}".format(args.qafile)) # Figure(s) if args.qafig is not None: qa_plots.frame_fiberflat(args.qafig, qaframe, frame, fiberflat) # Write write_fiberflat(args.outfile, fiberflat, frame.meta) log.info("successfully wrote %s" % args.outfile)
def run_pa(self, input_frame, outputfile): from desispec.fiberflat import compute_fiberflat import desispec.io.fiberflat as ffIO fiberflat = compute_fiberflat(input_frame) ffIO.write_fiberflat(outputfile, fiberflat, header=input_frame.meta) log.debug( "Fiberflat file wrtten. Exiting Quicklook for this configuration" ) #- File written no need to go further # !!!!! SAMI to whoever wrote this # PA's or any other components *CANNOT* call sys.exit()!! this needs to be fixed!!!!! sys.exit(0)
def test_throughput_resolution(self): """ Test that spectra with different throughputs and different resolutions result in fiberflat variations that are only due to throughput. """ wave, flux, ivar, mask = _get_data() nspec, nwave = flux.shape #- Setup a Resolution matrix that varies with fiber and wavelength #- Note: this is actually the transpose of the resolution matrix #- I wish I was creating, but as long as we self-consistently #- use it for convolving and solving, that shouldn't matter. sigma = np.linspace(2, 10, nwave * nspec) ndiag = 21 xx = np.linspace(-ndiag / 2.0, +ndiag / 2.0, ndiag) Rdata = np.zeros((nspec, len(xx), nwave)) for i in range(nspec): for j in range(nwave): kernel = np.exp(-xx**2 / (2 * sigma[i * nwave + j]**2)) kernel /= sum(kernel) Rdata[i, :, j] = kernel #- Vary the input flux prior to calculating the fiber flat flux[1] *= 1.1 flux[2] *= 1.2 flux[3] /= 1.1 flux[4] /= 1.2 #- Convolve the data with the varying resolution matrix convflux = np.empty_like(flux) for i in range(nspec): convflux[i] = Resolution(Rdata[i]).dot(flux[i]) #- Run the code frame = Frame(wave, convflux, ivar, mask, Rdata, spectrograph=0) #- Set an accuracy for this accuracy = 1.e-9 ff = compute_fiberflat(frame, accuracy=accuracy) #- Compare variation with middle fiber mid = ff.fiberflat.shape[0] // 2 diff = (ff.fiberflat[1] / 1.1 - ff.fiberflat[mid]) self.assertLess(np.max(np.abs(diff)), accuracy) diff = (ff.fiberflat[2] / 1.2 - ff.fiberflat[mid]) self.assertLess(np.max(np.abs(diff)), accuracy) diff = (ff.fiberflat[3] * 1.1 - ff.fiberflat[mid]) self.assertLess(np.max(np.abs(diff)), accuracy) diff = (ff.fiberflat[4] * 1.2 - ff.fiberflat[mid]) self.assertLess(np.max(np.abs(diff)), accuracy)
def test_throughput_resolution(self): """ Test that spectra with different throughputs and different resolutions result in fiberflat variations that are only due to throughput. """ wave, flux, ivar, mask = _get_data() nspec, nwave = flux.shape #- Setup a Resolution matrix that varies with fiber and wavelength #- Note: this is actually the transpose of the resolution matrix #- I wish I was creating, but as long as we self-consistently #- use it for convolving and solving, that shouldn't matter. sigma = np.linspace(2, 10, nwave*nspec) ndiag = 21 xx = np.linspace(-ndiag/2.0, +ndiag/2.0, ndiag) Rdata = np.zeros( (nspec, len(xx), nwave) ) for i in range(nspec): for j in range(nwave): kernel = np.exp(-xx**2/(2*sigma[i*nwave+j]**2)) kernel /= sum(kernel) Rdata[i,:,j] = kernel #- Vary the input flux prior to calculating the fiber flat flux[1] *= 1.1 flux[2] *= 1.2 flux[3] /= 1.1 flux[4] /= 1.2 #- Convolve the data with the varying resolution matrix convflux = np.empty_like(flux) for i in range(nspec): convflux[i] = Resolution(Rdata[i]).dot(flux[i]) #- Run the code frame = Frame(wave, convflux, ivar, mask, Rdata, spectrograph=0) #- Set an accuracy for this accuracy=1.e-9 ff = compute_fiberflat(frame,accuracy=accuracy) #- Compare variation with middle fiber mid = ff.fiberflat.shape[0] // 2 diff = (ff.fiberflat[1]/1.1 - ff.fiberflat[mid]) self.assertLess(np.max(np.abs(diff)), accuracy) diff = (ff.fiberflat[2]/1.2 - ff.fiberflat[mid]) self.assertLess(np.max(np.abs(diff)), accuracy) diff = (ff.fiberflat[3]*1.1 - ff.fiberflat[mid]) self.assertLess(np.max(np.abs(diff)), accuracy) diff = (ff.fiberflat[4]*1.2 - ff.fiberflat[mid]) self.assertLess(np.max(np.abs(diff)), accuracy)
def main() : parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--infile', type = str, default = None, required=True, help = 'path of DESI frame fits file corresponding to a continuum lamp exposure') parser.add_argument('--outfile', type = str, default = None, required=True, help = 'path of DESI fiberflat fits file') args = parser.parse_args() log=get_logger() log.info("starting") frame = read_frame(args.infile) fiberflat = compute_fiberflat(frame) write_fiberflat(args.outfile, fiberflat, frame.header) log.info("successfully wrote %s"%args.outfile)
def test_throughput(self): """ Test that spectra with different throughputs but the same resolution produce a fiberflat mirroring the variations in throughput """ wave, flux, ivar, mask = _get_data() nspec, nwave = flux.shape #- Setup data for a Resolution matrix sigma = 4.0 ndiag = 21 xx = np.linspace(-(ndiag - 1) / 2.0, +(ndiag - 1) / 2.0, ndiag) Rdata = np.zeros((nspec, ndiag, nwave)) kernel = np.exp(-xx**2 / (2 * sigma)) kernel /= sum(kernel) for i in range(nspec): for j in range(nwave): Rdata[i, :, j] = kernel #- Vary the input flux prior to calculating the fiber flat flux[1] *= 1.1 flux[2] *= 1.2 flux[3] *= 0.8 #- Convolve with the (common) resolution matrix convflux = np.empty_like(flux) for i in range(nspec): convflux[i] = Resolution(Rdata[i]).dot(flux[i]) frame = Frame(wave, convflux, ivar, mask, Rdata, spectrograph=0) ff = compute_fiberflat(frame) #- flux[1] is brighter, so should fiberflat[1]. etc. self.assertTrue(np.allclose(ff.fiberflat[0], ff.fiberflat[1] / 1.1)) self.assertTrue(np.allclose(ff.fiberflat[0], ff.fiberflat[2] / 1.2)) self.assertTrue(np.allclose(ff.fiberflat[0], ff.fiberflat[3] / 0.8))
def test_throughput(self): """ Test that spectra with different throughputs but the same resolution produce a fiberflat mirroring the variations in throughput """ wave, flux, ivar, mask = _get_data() nspec, nwave = flux.shape #- Setup data for a Resolution matrix sigma = 4.0 ndiag = 21 xx = np.linspace(-(ndiag-1)/2.0, +(ndiag-1)/2.0, ndiag) Rdata = np.zeros( (nspec, ndiag, nwave) ) kernel = np.exp(-xx**2/(2*sigma)) kernel /= sum(kernel) for i in range(nspec): for j in range(nwave): Rdata[i,:,j] = kernel #- Vary the input flux prior to calculating the fiber flat flux[1] *= 1.1 flux[2] *= 1.2 flux[3] *= 0.8 #- Convolve with the (common) resolution matrix convflux = np.empty_like(flux) for i in range(nspec): convflux[i] = Resolution(Rdata[i]).dot(flux[i]) frame = Frame(wave, convflux, ivar, mask, Rdata, spectrograph=0) ff = compute_fiberflat(frame) #- flux[1] is brighter, so should fiberflat[1]. etc. self.assertTrue(np.allclose(ff.fiberflat[0], ff.fiberflat[1]/1.1)) self.assertTrue(np.allclose(ff.fiberflat[0], ff.fiberflat[2]/1.2)) self.assertTrue(np.allclose(ff.fiberflat[0], ff.fiberflat[3]/0.8))