def test_simobs(self): """ Simulate observations using cached versions of the sed grid and noise model and compare the result to a cached version. """ # download files specific to this test simobs_fname_cache = download_rename("beast_example_phat_simobs.fits") # get the physics model grid - includes priors modelsedgrid = SEDGrid(self.seds_fname_cache) # read in the noise model - includes bias, unc, and completeness noisegrid = noisemodel.get_noisemodelcat(self.noise_fname_cache) table_new = gen_SimObs_from_sedgrid( modelsedgrid, noisegrid, nsim=100, compl_filter="max", ranseed=1234, ) # check that the simobs files are exactly the same table_cache = Table.read(simobs_fname_cache) # to avoid issues with uppercase vs lowercase column names, make them all # the same before comparing for col in table_new.colnames: table_new[col].name = col.upper() for col in table_cache.colnames: table_cache[col].name = col.upper() compare_tables(table_cache, table_new)
def test_trim_grid(): # download the needed files vega_fname = download_rename('vega.hd5') seds_fname = download_rename('beast_example_phat_seds.grid.hd5') noise_fname = download_rename('beast_example_phat_noisemodel.hd5') # download cached version of noisemodel on the sed grid simobs_fname_cache = download_rename('beast_example_phat_simobs.fits') ################ # get the physics model grid - includes priors modelsedgrid = FileSEDGrid(seds_fname) # read in the noise model - includes bias, unc, and completeness noisegrid = noisemodel.get_noisemodelcat(noise_fname) table_new = gen_SimObs_from_sedgrid(modelsedgrid, noisegrid, nsim=100, compl_filter="f475w", ranseed=1234, vega_fname=vega_fname) # check that the simobs files are exactly the same table_cache = Table.read(simobs_fname_cache) compare_tables(table_cache, table_new)
def test_simobs(): # download the needed files vega_fname = download_rename("vega.hd5") seds_fname = download_rename("beast_example_phat_seds.grid.hd5") noise_fname = download_rename("beast_example_phat_noisemodel.grid.hd5") # download cached version of noisemodel on the sed grid simobs_fname_cache = download_rename("beast_example_phat_simobs.fits") ################ # get the physics model grid - includes priors modelsedgrid = SEDGrid(seds_fname) # read in the noise model - includes bias, unc, and completeness noisegrid = noisemodel.get_noisemodelcat(noise_fname) table_new = gen_SimObs_from_sedgrid( modelsedgrid, noisegrid, nsim=100, compl_filter="f475w", ranseed=1234, vega_fname=vega_fname, ) # check that the simobs files are exactly the same table_cache = Table.read(simobs_fname_cache) # to avoid issues with uppercase vs lowercase column names, make them all # the same before comparing for col in table_new.colnames: table_new[col].name = col.upper() for col in table_cache.colnames: table_cache[col].name = col.upper() compare_tables(table_cache, table_new)
def simulate_obs( physgrid_list, noise_model_list, output_catalog, nsim=100, compl_filter="F475W", weight_to_use='weight', ranseed=None, ): """ Wrapper for creating a simulated photometry. Parameters ---------- physgrid_list : list of strings Name of the physics model file. If there are multiple physics model grids (i.e., if there are subgrids), list them all here, and they will each be sampled nsim/len(physgrid_list) times. noise_model_list : list of strings Name of the noise model file. If there are multiple files for physgrid_list (because of subgrids), list the noise model file associated with each physics model file. output_catalog : string Name of the output simulated photometry catalog n_sim : int (default=100) Number of simulated objects to create. If nsim/len(physgrid_list) isn't an integer, this will be increased so that each grid has the same number of samples. compl_filter : string (default='F475W') filter name to use for completeness weight_to_use : string (default='weight') Set to either 'weight' (prior+grid), 'prior_weight', or 'grid_weight' to choose the weighting for SED selection. ranseed : int seed for random number generator """ # numbers of samples to do # (ensure there are enough for even sampling of multiple model grids) n_phys = len(physgrid_list) samples_per_grid = int(np.ceil(nsim / n_phys)) # list to hold all simulation tables simtable_list = [] # make a table for each physics model + noise model for physgrid, noise_model in zip(np.atleast_1d(physgrid_list), np.atleast_1d(noise_model_list)): # get the physics model grid - includes priors modelsedgrid = SEDGrid(str(physgrid)) # read in the noise model - includes bias, unc, and completeness noisegrid = noisemodel.get_noisemodelcat(str(noise_model)) # generate the table simtable = gen_SimObs_from_sedgrid( modelsedgrid, noisegrid, nsim=samples_per_grid, compl_filter=compl_filter, weight_to_use=weight_to_use, ranseed=ranseed, ) # append to the list simtable_list.append(simtable) # stack all the tables into one and write it out vstack(simtable_list).write(output_catalog, overwrite=True)
parser.add_argument("obsgrid", help="filename of observation/nosie grid") parser.add_argument("outfile", help="filename for simulated observations") parser.add_argument("--nsim", default=100, type=int, help="number of simulated objects") parser.add_argument("--compl_filter", default="F475W", help="filter name to use for completeness") parser.add_argument("--ranseed", default=None, type=int, help="seed for random number generator") args = parser.parse_args() # get the physics model grid - includes priors modelsedgrid = FileSEDGrid(args.physgrid) # read in the noise model - includes bias, unc, and completeness noisegrid = noisemodel.get_noisemodelcat(args.obsgrid) simtable = gen_SimObs_from_sedgrid( modelsedgrid, noisegrid, nsim=args.nsim, compl_filter=args.compl_filter, ranseed=args.ranseed, ) simtable.write(args.outfile, overwrite=True)
def simulate_obs( physgrid_list, noise_model_list, output_catalog, beastinfo_list=None, nsim=100, compl_filter="F475W", complcut=None, magcut=None, weight_to_use="weight", ranseed=None, ): """ Simulate photometry based on a physicsmodel grid(s) and observation model(s). Parameters ---------- physgrid_list : list of strings Name of the physics model file. If there are multiple physics model grids (i.e., if there are subgrids), list them all here, and they will each be sampled nsim/len(physgrid_list) times. noise_model_list : list of strings Name of the noise model file. If there are multiple files for physgrid_list (because of subgrids), list the noise model files associated with each physics model file. output_catalog : string Name of the output simulated photometry catalog beastinfo_list : list of strings (default=None) Name of the beast info file. The mass and age prior models are read from this model to use to compute the number of stars to simulate. If there are multiple files for physgrid_list (because of subgrids), list the beast info files associated with each physics model file. n_sim : int (default=100) Number of simulated objects to create if beastinfo_list is not given. If nsim/len(physgrid_list) isn't an integer, this will be increased so that each grid has the same number of samples. compl_filter : str (default=F475W) filter to use for completeness (required for toothpick model) set to max to use the max value in all filters complcut : float (defualt=None) completeness cut for only including model seds above the given completeness, where the cut ranges from 0 to 1. magcut : float (defualt=None) faint-end magnitude cut for only including model seds brighter than the given magnitude in compl_filter. weight_to_use : string (default='weight') Set to either 'weight' (prior+grid), 'prior_weight', 'grid_weight', or 'uniform' (this option is valid only when nsim is supplied) to choose the weighting for SED selection. ranseed : int seed for random number generator """ # numbers of samples to do # (ensure there are enough for even sampling of multiple model grids) n_phys = len(np.atleast_1d(physgrid_list)) nsim = int(nsim) samples_per_grid = int(np.ceil(nsim / n_phys)) if complcut is not None: complcut = float(complcut) if magcut is not None: magcut = float(magcut) if ranseed is not None: ranseed = int(ranseed) # list to hold all simulation tables simtable_list = [] # make a table for each physics model + noise model for k, physgrid in enumerate(np.atleast_1d(physgrid_list)): noise_model = np.atleast_1d(noise_model_list)[k] # get the physics model grid - includes priors modelsedgrid = SEDGrid(str(physgrid)) # read in the noise model - includes bias, unc, and completeness noisegrid = noisemodel.get_noisemodelcat(str(noise_model)) if beastinfo_list is not None: with asdf.open(np.atleast_1d(beastinfo_list)[k]) as af: binfo = af.tree age_prior_model = binfo["age_prior_model"] mass_prior_model = binfo["mass_prior_model"] else: age_prior_model = None mass_prior_model = None # generate the table simtable = gen_SimObs_from_sedgrid( modelsedgrid, noisegrid, age_prior_model=age_prior_model, mass_prior_model=mass_prior_model, nsim=samples_per_grid, compl_filter=compl_filter, complcut=complcut, magcut=magcut, weight_to_use=weight_to_use, ranseed=ranseed, ) # append to the list simtable_list.append(simtable) # stack all the tables into one and write it out vstack(simtable_list).write(output_catalog, overwrite=True)