def test_create_tables_normal(self): method_list = methods.builtin_method_functions() cosmology_list = cosmologies.builtin_cosmology_functions() # Create a lookup table for each method and cosmology for method in method_list: for key in cosmology_list: here = os.getcwd() cosmo = cosmologies.builtin_cosmology_functions()[key] filename = "_".join(["pytest_output", method, key]) table.create(method=method, filename=filename, cosmo=cosmo, output_dir=here, zmin=0, zmax=20, num_samples=10000) # Compare new tables to existing tables for 4 dm values pre_calc_fn = ".".join(["_".join([method, key]), "npz"]) new_calc_fn = "".join([filename, ".npz"]) pre_calc = table.load(pre_calc_fn) new_calc = table.load(new_calc_fn, data_dir=here) test_dm_list = [0, 100, 1000, 2000] for dm in test_dm_list: new_z = table.get_z_from_table(dm, new_calc) pre_z = table.get_z_from_table(dm, pre_calc) assert new_z == pre_z
def test_create_table_zhang_free_elec_error(self): cosmo = cosmologies.builtin_cosmology_functions()["Planck18"] filename = "_".join(["pytest_output", "Zhang2018", "Planck18", "free_elec_error"]) with pytest.raises(ValueError): table.create(method="Zhang2018", filename=filename, cosmo=cosmo, free_elec=-1)
def test_create_table_zhang_figm_free_elec(self): cosmo = cosmologies.builtin_cosmology_functions()["Planck18"] filename = "_".join(["pytest_output", "Zhang2018", "Planck18", "figm_free_elec"]) here = os.getcwd() table.create(method="Zhang2018", filename=filename, cosmo=cosmo, output_dir=here, f_igm=0.5, free_elec=0.4)
def test_create_custom_method(): """ This bug was found when creating a custon method, using calc_redshift wouldn't return any value. """ def simple_dm(z): """ A simple DM-z scaling relation""" dm = 1200 * z return dm methods.add_method("pytest_output_simple_dm", simple_dm) table.create("pytest_output_simple_dm") f = Frb(1200) print(f.calc_redshift(method="pytest_output_simple_dm")) assert np.isclose(f.calc_redshift(method="pytest_output_simple_dm"), 1.0)
def test_create_table_invalid_method(self): with pytest.raises(ValueError): table.create(method="Webb1995")
def test_create_table_zhang_figm_error(self): cosmo = cosmologies.builtin_cosmology_functions()["Planck18"] with pytest.raises(ValueError): table.create(method="Zhang2018", cosmo=cosmo, f_igm=-1)