def test_compare_spec_type_inFOV(self): """ Test for compare_spec_type. Inputs and expected outputs created by running generate_files_for_tests.py in beast-examples/metal_small. In this version, the stars are in the imaging field of view. """ # download cached file compare_spec_type_fname = download_rename( f"{self.basename}_compare_spec_type.asdf") with asdf.open(compare_spec_type_fname) as af: compare_spec_type_info = copy.deepcopy(af.tree) # run compare_spec_type spec_type = compare_spec_type( self.obs_fname_cache, self.stats_fname_cache, **compare_spec_type_info["input"], ) # expected output table expected_table = Table(compare_spec_type_info["output"]) # compare to new table compare_tables(expected_table, Table(spec_type), rtol=2e-3)
def test_compare_spec_type_inFOV(): """ Test for compare_spec_type. The spectrally-typed stars aren't real sources, they're just invented for the purposes of documenting/testing the code. In this version, the stars are in the imaging field of view. """ # download the needed files obs_fname = download_rename("b15_4band_det_27_A.fits") stats_fname = download_rename("beast_example_phat_stats.fits") # run compare_spec_type spec_type = compare_spec_type( obs_fname, stats_fname, [11.2335881, 11.23342557], # RA [41.9001895, 41.90006316], # Dec ['A', 'G'], # Spectral type [2, 7], # Subtype ['II', 'II'], # Luminosity class match_radius=0.2 # Match radius (arcsec) ) # expected output table expected_table = Table({ 'spec_ra': [11.2335881, 11.23342557], 'spec_dec': [41.9001895, 41.90006316], 'spec_type': ['A 2 II', 'G 7 II'], 'spec_teff': [9000.0, 4916.666666666667], 'spec_logg': [2.7164474106543732, 1.7184474106543735], 'phot_cat_ind': [27, 8], 'stats_cat_ind': [27, 8], 'beast_teff_p50': [9046.250020338754, 4528.230977991138], 'beast_teff_p16': [8643.670633196869, 4335.617282355577], 'beast_teff_p84': [9536.391362054928, 4729.401710221546], 'beast_logg_p50': [2.714286917261312, 1.7684285714285717], 'beast_logg_p16': [2.636272525730954, 1.7014832653061227], 'beast_logg_p84': [2.799534708811963, 1.8353738775510207], 'teff_sigma': [-0.11488422362383206, 1.9308757510045778], 'logg_sigma': [0.025343687546173433, -0.7465969411324851] }) # compare to new table compare_tables(expected_table, Table(spec_type), rtol=2e-3)
def test_compare_spec_type_notFOV(): """ Test for compare_spec_type. The spectrally-typed stars aren't real sources, they're just invented for the purposes of documenting/testing the code. In this version, the stars are NOT in the imaging field of view. """ # download the needed files obs_fname = download_rename("b15_4band_det_27_A.fits") stats_fname = download_rename("beast_example_phat_stats.fits") # run compare_spec_type spec_type = compare_spec_type( obs_fname, stats_fname, [1.0], # RA [1.0], # Dec ['B'], # Spectral type [4], # Subtype ['V'], # Luminosity class match_radius=0.2 # Match radius (arcsec) ) # expected output table expected_table = Table({ 'spec_ra': [1.0], 'spec_dec': [1.0], 'spec_type': ['B 4 V'], 'spec_teff': [None], 'spec_logg': [None], 'phot_cat_ind': [None], 'stats_cat_ind': [None], 'beast_teff_p50': [None], 'beast_teff_p16': [None], 'beast_teff_p84': [None], 'beast_logg_p50': [None], 'beast_logg_p16': [None], 'beast_logg_p84': [None], 'teff_sigma': [None], 'logg_sigma': [None], }) # compare to new table compare_tables(expected_table, Table(spec_type))
def test_compare_spec_type_notFOV(self): """ Test for compare_spec_type. In this version, the stars are NOT in the imaging field of view. """ # run compare_spec_type spec_type = compare_spec_type( self.obs_fname_cache, self.stats_fname_cache, [1.0], # RA [1.0], # Dec ["B"], # Spectral type [4], # Subtype ["V"], # Luminosity class match_radius=0.2, # Match radius (arcsec) ) # expected output table expected_table = Table( { "spec_ra": [1.0], "spec_dec": [1.0], "spec_type": ["B 4 V"], "spec_teff": [None], "spec_logg": [None], "phot_cat_ind": [None], "stats_cat_ind": [None], "beast_teff_p50": [None], "beast_teff_p16": [None], "beast_teff_p84": [None], "beast_logg_p50": [None], "beast_logg_p16": [None], "beast_logg_p84": [None], "teff_sigma": [None], "logg_sigma": [None], } ) # compare to new table compare_tables(expected_table, Table(spec_type))
def test_compare_spec_type_inFOV(self): """ Test for compare_spec_type. The spectrally-typed stars aren't real sources, they're just invented for the purposes of documenting/testing the code. In this version, the stars are in the imaging field of view. """ # run compare_spec_type spec_type = compare_spec_type( self.obs_fname_cache, self.stats_fname_cache, [11.2335881, 11.23342557], # RA [41.9001895, 41.90006316], # Dec ["A", "G"], # Spectral type [2, 7], # Subtype ["II", "II"], # Luminosity class match_radius=0.2, # Match radius (arcsec) ) # expected output table expected_table = Table({ "spec_ra": [11.2335881, 11.23342557], "spec_dec": [41.9001895, 41.90006316], "spec_type": ["A 2 II", "G 7 II"], "spec_teff": [9000.0, 4916.666666666667], "spec_logg": [2.7164474106543732, 1.7184474106543735], "phot_cat_ind": [27, 8], "stats_cat_ind": [27, 8], "beast_teff_p50": [9046.250020338754, 4528.230977991138], "beast_teff_p16": [8643.670633196869, 4335.617282355577], "beast_teff_p84": [9536.391362054928, 4729.401710221546], "beast_logg_p50": [2.714286917261312, 1.7684285714285717], "beast_logg_p16": [2.636272525730954, 1.7014832653061227], "beast_logg_p84": [2.799534708811963, 1.8353738775510207], "teff_sigma": [-0.11488422362383206, 1.9308757510045778], "logg_sigma": [0.025343687546173433, -0.7465969411324851], }) # compare to new table compare_tables(expected_table, Table(spec_type), rtol=2e-3)
def generate_files_for_tests(run_beast=True, run_tools=True): """ Use the metal_small example to generate a full set of files for the BEAST regression tests. Parameters ---------- run_beast : boolean (default=True) if True, run the BEAST run_tools : boolean (default=True) if True, run the code to generate things for tools """ # read in BEAST settings settings_orig = beast_settings.beast_settings("beast_settings.txt") # also make a version with subgrids settings_subgrids = copy.deepcopy(settings_orig) settings_subgrids.n_subgrid = 2 settings_subgrids.project = f"{settings_orig.project}_subgrids" # ========================================== # run the beast for each set of settings # ========================================== if run_beast: for settings in [settings_orig, settings_subgrids]: # ----------------- # physics model # ----------------- create_physicsmodel.create_physicsmodel( settings, nsubs=settings.n_subgrid, nprocs=1, ) # ----------------- # ASTs # ----------------- # currently only works for no subgrids if settings.n_subgrid == 1: make_ast_inputs.make_ast_inputs(settings, pick_method="flux_bin_method") # ----------------- # obs model # ----------------- create_obsmodel.create_obsmodel( settings, use_sd=False, nsubs=settings.n_subgrid, nprocs=1, use_rate=True, ) # ----------------- # trimming # ----------------- # make file names file_dict = create_filenames.create_filenames( settings, use_sd=False, nsubs=settings.n_subgrid) # read in the observed data obsdata = Observations(settings.obsfile, settings.filters, settings.obs_colnames) for i in range(settings.n_subgrid): # get the modesedgrid on which to generate the noisemodel modelsedgridfile = file_dict["modelsedgrid_files"][i] modelsedgrid = SEDGrid(modelsedgridfile) # read in the noise model just created noisemodel_vals = noisemodel.get_noisemodelcat( file_dict["noise_files"][i]) # trim the model sedgrid sed_trimname = file_dict["modelsedgrid_trim_files"][i] noisemodel_trimname = file_dict["noise_trim_files"][i] trim_grid.trim_models( modelsedgrid, noisemodel_vals, obsdata, sed_trimname, noisemodel_trimname, sigma_fac=3.0, ) # ----------------- # fitting # ----------------- run_fitting.run_fitting( settings, use_sd=False, nsubs=settings.n_subgrid, nprocs=1, pdf2d_param_list=["Av", "M_ini", "logT"], pdf_max_nbins=200, ) # ----------------- # merging # ----------------- # it'll automatically skip for no subgrids merge_files.merge_files(settings, use_sd=False, nsubs=settings.n_subgrid) print("\n\n") # ========================================== # reference files for assorted tools # ========================================== if run_tools: # ----------------- # compare_spec_type # ----------------- # the input settings input = { "spec_ra": [72.67213351], "spec_dec": [-67.71720515], "spec_type": ["A"], "spec_subtype": [0], "lumin_class": ["IV"], "match_radius": 0.2, } # run it output = compare_spec_type.compare_spec_type( settings_orig.obsfile, "{0}/{0}_stats.fits".format(settings_orig.project), **input, ) # save the inputs and outputs asdf.AsdfFile({ "input": input, "output": output }).write_to("{0}/{0}_compare_spec_type.asdf".format( settings_orig.project)) # ----------------- # star_type_probability # ----------------- # input settings input = { "output_filebase": None, "ext_O_star_params": { "min_M_ini": 10, "min_Av": 0.5, "max_Av": 5 }, } # run it output = star_type_probability.star_type_probability( "{0}/{0}_pdf1d.fits".format(settings_orig.project), "{0}/{0}_pdf2d.fits".format(settings_orig.project), **input, ) # save the inputs and outputs asdf.AsdfFile({ "input": input, "output": output }).write_to("{0}/{0}_star_type_probability.asdf".format( settings_orig.project)) # ========================================== # asdf file permissions # ========================================== # for unknown reasons, asdf currently writes files with permissions set # to -rw-------. This changes it to -rw-r--r-- (like the rest of the # BEAST files) so Karl can easily copy them over to the cached file # website. # list of asdf files asdf_files = glob.glob("*/*.asdf") # go through each one to change permissions for fname in asdf_files: os.chmod(fname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)