def test_quickgen_moonzenith_simspec(self): night = self.night camera = 'r0' expid0 = 100 expid1 = 101 # generate exposures obs.new_exposure('bgs', night=night, expid=expid0, nspec=1, seed=1) simspec0 = io.findfile('simspec', night, expid0) fibermap0 = lvmspec.io.findfile('fibermap', night, expid0) obs.new_exposure('bgs', night=night, expid=expid1, nspec=1, seed=1) simspec1 = io.findfile('simspec', night, expid1) fibermap1 = lvmspec.io.findfile('fibermap', night, expid1) # generate quickgen output for each moon phase cmd = "quickgen --simspec {} --fibermap {} --moon-zenith 0".format( simspec0, fibermap0) quickgen.main(quickgen.parse(cmd.split()[1:])) cmd = "quickgen --simspec {} --fibermap {} --moon-zenith 90".format( simspec1, fibermap1) quickgen.main(quickgen.parse(cmd.split()[1:])) cframe0 = lvmspec.io.findfile("cframe", night, expid0, camera) cframe1 = lvmspec.io.findfile("cframe", night, expid1, camera) cf0 = lvmspec.io.read_frame(cframe0) cf1 = lvmspec.io.read_frame(cframe1) self.assertLess(np.median(cf0.ivar), np.median(cf1.ivar))
def test_quickgen_airmass_simspec(self): night = self.night camera = 'r0' expid0 = 100 expid1 = 101 # generate exposures of varying airmass obscond = simexp.reference_conditions['DARK'] obscond['AIRMASS'] = 1.5 obs.new_exposure('dark', night=night, expid=expid0, nspec=1, seed=1, obsconditions=obscond) simspec0 = io.findfile('simspec', night, expid0) fibermap0 = lvmspec.io.findfile('fibermap', night, expid0) obscond['AIRMASS'] = 1.0 obs.new_exposure('dark', night=night, expid=expid1, nspec=1, seed=1, obsconditions=obscond) simspec1 = io.findfile('simspec', night, expid1) fibermap1 = lvmspec.io.findfile('fibermap', night, expid1) # generate quickgen output for each airmass cmd = "quickgen --simspec {} --fibermap {}".format(simspec0, fibermap0) quickgen.main(quickgen.parse(cmd.split()[1:])) cmd = "quickgen --simspec {} --fibermap {}".format(simspec1, fibermap1) quickgen.main(quickgen.parse(cmd.split()[1:])) cframe0 = lvmspec.io.findfile("cframe", night, expid0, camera) cframe1 = lvmspec.io.findfile("cframe", night, expid1, camera) cf0 = lvmspec.io.read_frame(cframe0) cf1 = lvmspec.io.read_frame(cframe1) self.assertLess(np.median(cf0.ivar), np.median(cf1.ivar))
def test_quickgen_seed_simspec(self): night = self.night camera = 'r0' expid0 = 100 expid1 = 101 expid2 = 102 # generate exposures seed 1 & 2 obs.new_exposure('dark', night=night, expid=expid0, nspec=1, seed=1) simspec0 = io.findfile('simspec', night, expid0) fibermap0 = lvmspec.io.findfile('fibermap', night, expid0) obs.new_exposure('dark', night=night, expid=expid1, nspec=1, seed=1) simspec1 = io.findfile('simspec', night, expid1) fibermap1 = lvmspec.io.findfile('fibermap', night, expid1) obs.new_exposure('dark', night=night, expid=expid2, nspec=1, seed=2) simspec2 = io.findfile('simspec', night, expid2) fibermap2 = lvmspec.io.findfile('fibermap', night, expid2) # generate quickgen output for each exposure cmd = "quickgen --simspec {} --fibermap {} --seed 1".format( simspec0, fibermap0) quickgen.main(quickgen.parse(cmd.split()[1:])) cmd = "quickgen --simspec {} --fibermap {} --seed 1".format( simspec1, fibermap1) quickgen.main(quickgen.parse(cmd.split()[1:])) cmd = "quickgen --simspec {} --fibermap {} --seed 2".format( simspec2, fibermap2) quickgen.main(quickgen.parse(cmd.split()[1:])) cframe0 = lvmspec.io.findfile("cframe", night, expid0, camera) cframe1 = lvmspec.io.findfile("cframe", night, expid1, camera) cframe2 = lvmspec.io.findfile("cframe", night, expid2, camera) cf0 = lvmspec.io.read_frame(cframe0) cf1 = lvmspec.io.read_frame(cframe1) cf2 = lvmspec.io.read_frame(cframe2) self.assertTrue(np.all(cf0.flux == cf1.flux)) #- same seed self.assertTrue(np.all(cf0.ivar == cf1.ivar)) self.assertTrue(np.any(cf0.flux != cf2.flux)) #- different seed s0 = fits.open(simspec0) s1 = fits.open(simspec1) s2 = fits.open(simspec2) self.assertEqual(s0['TRUTH'].data['OBJTYPE'][0], s1['TRUTH'].data['OBJTYPE'][0]) self.assertEqual(s0['TRUTH'].data['REDSHIFT'][0], s1['TRUTH'].data['REDSHIFT'][0]) self.assertNotEqual(s0['TRUTH'].data['REDSHIFT'][0], s2['TRUTH'].data['REDSHIFT'][0])
def main(args): # Set up the logger. if args.verbose: log = get_logger(DEBUG) else: log = get_logger() objtype = args.objtype.upper() log.debug('Using OBJTYPE {}'.format(objtype)) log.debug('Simulating {:g} bricks each with {:g} spectra'.format(args.nbrick, args.nspec)) # Draw priors uniformly given the input ranges. rand = np.random.RandomState(args.seed) exptime = rand.uniform(args.exptime_range[0], args.exptime_range[1], args.nbrick) airmass = rand.uniform(args.airmass_range[0], args.airmass_range[1], args.nbrick) moonphase = rand.uniform(args.moon_phase_range[0], args.moon_phase_range[1], args.nbrick) moonangle = rand.uniform(args.moon_angle_range[0], args.moon_angle_range[1], args.nbrick) moonzenith = rand.uniform(args.moon_zenith_range[0], args.moon_zenith_range[1], args.nbrick) # Build a metadata table with the simulation inputs. metafile = makepath(os.path.join(args.outdir, '{}-input.fits'.format(args.brickname))) metacols = [ ('BRICKNAME', 'S20'), ('SEED', 'S20'), ('EXPTIME', 'f4'), ('AIRMASS', 'f4'), ('MOONPHASE', 'f4'), ('MOONANGLE', 'f4'), ('MOONZENITH', 'f4')] meta = Table(np.zeros(args.nbrick, dtype=metacols)) meta['EXPTIME'].unit = 's' meta['MOONANGLE'].unit = 'deg' meta['MOONZENITH'].unit = 'deg' meta['BRICKNAME'] = ['{}-{:03d}'.format(args.brickname, ii) for ii in range(args.nbrick)] meta['EXPTIME'] = exptime meta['AIRMASS'] = airmass meta['MOONPHASE'] = moonphase meta['MOONANGLE'] = moonangle meta['MOONZENITH'] = moonzenith log.debug('Writing {}'.format(metafile)) write_bintable(metafile, meta, extname='METADATA', clobber=True) # Generate each brick in turn. for ii in range(args.nbrick): thisbrick = meta['BRICKNAME'][ii] log.debug('Building brick {}'.format(thisbrick)) brickargs = ['--brickname', thisbrick, '--objtype', args.objtype, '--nspec', '{}'.format(args.nspec), '--outdir', os.path.join(args.brickdir, thisbrick), '--outdir-truth', os.path.join(args.brickdir, thisbrick), '--exptime', '{}'.format(exptime[ii]), '--airmass', '{}'.format(airmass[ii]), '--moon-phase', '{}'.format(moonphase[ii]), '--moon-angle', '{}'.format(moonangle[ii]), '--moon-zenith', '{}'.format(moonzenith[ii]), '--zrange-bgs', '{}'.format(args.zrange_bgs[0]), '{}'.format(args.zrange_bgs[1]), '--rmagrange-bgs', '{}'.format(args.rmagrange_bgs[0]), '{}'.format(args.rmagrange_bgs[1])] if args.seed is not None: brickargs.append('--seed') brickargs.append('{}'.format(args.seed)) quickargs = quickbrick.parse(brickargs) if args.verbose: quickargs.verbose = True quickbrick.main(quickargs)
def test_quickgen_simspec(self): night = self.night expid = self.expid camera = 'r0' # flavors = ['flat','dark','gray','bright','bgs','mws','elg','lrg','qso','arc'] flavors = ['arc', 'flat', 'dark', 'bright'] for i in range(len(flavors)): flavor = flavors[i] obs.new_exposure(flavor, night=night, expid=expid, nspec=2) #- output to same directory as input os.environ['LVM_SPECTRO_REDUX'] = os.path.join( os.getenv('LVM_SPECTRO_SIM'), os.getenv('PIXPROD')) #- run quickgen simspec = io.findfile('simspec', night, expid) fibermap = io.findfile('simfibermap', night, expid) self.assertTrue(os.path.exists(simspec)) self.assertTrue(os.path.exists(fibermap)) if flavor == 'flat': try: cmd = "quickgen --simspec {} --fibermap {}".format( simspec, fibermap) quickgen.main(quickgen.parse(cmd.split()[1:])) except SystemExit: pass #- verify flat outputs fiberflatfile = lvmspec.io.findfile('fiberflat', night, expid, camera) self.assertTrue(os.path.exists(fiberflatfile)) elif flavor == 'arc': try: cmd = "quickgen --simspec {} --fibermap {}".format( simspec, fibermap) quickgen.main(quickgen.parse(cmd.split()[1:])) except SystemExit: pass #- verify arc outputs framefile = lvmspec.io.findfile('frame', night, expid, camera) self.assertTrue(os.path.exists(framefile)) else: cmd = "quickgen --simspec {} --fibermap {}".format( simspec, fibermap) quickgen.main(quickgen.parse(cmd.split()[1:])) #- verify outputs framefile = lvmspec.io.findfile('frame', night, expid, camera) self.assertTrue(os.path.exists(framefile)) cframefile = lvmspec.io.findfile('cframe', night, expid, camera) self.assertTrue(os.path.exists(cframefile)) skyfile = lvmspec.io.findfile('sky', night, expid, camera) self.assertTrue(os.path.exists(skyfile)) fluxcalibfile = lvmspec.io.findfile('calib', night, expid, camera) self.assertTrue(os.path.exists(fluxcalibfile)) os.remove(simspec) os.remove(fibermap)