def setup(self): filename = 'tardis_configv1_artis_density_v_slice.yml' self.config = Configuration.from_yaml(data_path(filename)) self.config.model.abundances.type = 'file' self.config.model.abundances.filename = 'artis_abundances.dat' self.config.model.abundances.filetype = 'artis' self.model = Radial1DModel.from_config(self.config)
def test_ascii_reader_power_law(): filename = "tardis_configv1_density_power_law_test.yml" config = Configuration.from_yaml(data_path(filename)) model = Radial1DModel.from_config(config) expected_densites = [ 3.29072513e-14, 2.70357804e-14, 2.23776573e-14, 1.86501954e-14, 1.56435277e-14, 1.32001689e-14, 1.12007560e-14, 9.55397475e-15, 8.18935779e-15, 7.05208050e-15, 6.09916083e-15, 5.29665772e-15, 4.61758699e-15, 4.04035750e-15, 3.54758837e-15, 3.12520752e-15, 2.76175961e-15, 2.44787115e-15, 2.17583442e-15, 1.93928168e-15, ] assert model.no_of_shells == 20 for i, mdens in enumerate(expected_densites): assert_almost_equal(model.density[i].to(u.Unit("g / (cm3)")).value, mdens)
def from_config(cls, config, **kwargs): """ Create a new Simulation instance from a Configuration object. Parameters ---------- config : tardis.io.config_reader.Configuration **kwargs Allow overriding some structures, such as model, plasma, atomic data and the runner, instead of creating them from the configuration object. Returns ------- Simulation """ # Allow overriding some config structures. This is useful in some # unit tests, and could be extended in all the from_config classmethods. if 'model' in kwargs: model = kwargs['model'] else: model = Radial1DModel.from_config(config) if 'plasma' in kwargs: plasma = kwargs['plasma'] else: plasma = assemble_plasma(config, model, atom_data=kwargs.get('atom_data', None)) if 'runner' in kwargs: runner = kwargs['runner'] else: runner = MontecarloRunner.from_config(config) luminosity_nu_start = config.supernova.luminosity_wavelength_end.to( u.Hz, u.spectral()) try: luminosity_nu_end = config.supernova.luminosity_wavelength_start.to( u.Hz, u.spectral()) except ZeroDivisionError: luminosity_nu_end = np.inf * u.Hz last_no_of_packets = config.montecarlo.last_no_of_packets if last_no_of_packets is None or last_no_of_packets < 0: last_no_of_packets = config.montecarlo.no_of_packets last_no_of_packets = int(last_no_of_packets) return cls(iterations=config.montecarlo.iterations, model=model, plasma=plasma, runner=runner, no_of_packets=int(config.montecarlo.no_of_packets), no_of_virtual_packets=int( config.montecarlo.no_of_virtual_packets), luminosity_nu_start=luminosity_nu_start, luminosity_nu_end=luminosity_nu_end, last_no_of_packets=last_no_of_packets, luminosity_requested=config.supernova.luminosity_requested.cgs, convergence_strategy=config.montecarlo.convergence_strategy, nthreads=config.montecarlo.nthreads)
def test_ascii_reader_exponential_law(): filename = "tardis_configv1_density_exponential_test.yml" config = Configuration.from_yaml(data_path(filename)) model = Radial1DModel.from_config(config) expected_densites = [ 5.18114795e-14, 4.45945537e-14, 3.83828881e-14, 3.30364579e-14, 2.84347428e-14, 2.44740100e-14, 2.10649756e-14, 1.81307925e-14, 1.56053177e-14, 1.34316215e-14, 1.15607037e-14, 9.95038990e-15, 8.56437996e-15, 7.37143014e-15, 6.34464872e-15, 5.46088976e-15, 4.70023138e-15, 4.04552664e-15, 3.48201705e-15, 2.99699985e-15, ] expected_unit = "g / (cm3)" assert model.no_of_shells == 20 for i, mdens in enumerate(expected_densites): assert_almost_equal(model.density[i].value, mdens) assert model.density[i].unit == u.Unit(expected_unit)
def test_model_decay(simple_isotope_abundance): filename = "tardis_configv1_verysimple.yml" config = Configuration.from_yaml(data_path(filename)) model = Radial1DModel.from_config(config) model.raw_isotope_abundance = simple_isotope_abundance decayed = simple_isotope_abundance.decay(model.time_explosion).as_atoms() norm_factor = 1.4 assert_almost_equal( model.abundance.loc[8][0], model.raw_abundance.loc[8][0] / norm_factor, decimal=4, ) assert_almost_equal( model.abundance.loc[14][0], (model.raw_abundance.loc[14][0] + decayed.loc[14][0]) / norm_factor, decimal=4, ) assert_almost_equal( model._abundance.loc[12][5], (model.raw_abundance.loc[12][5] + decayed.loc[12][5]) / norm_factor, decimal=4, ) assert_almost_equal( model.abundance.loc[6][12], (decayed.loc[6][12]) / norm_factor, decimal=4, )
def setup(self): filename = 'tardis_configv1_artis_density.yml' self.config = Configuration.from_yaml(data_path(filename)) self.config.model.abundances.type = 'file' self.config.model.abundances.filename = 'artis_abundances.dat' self.config.model.abundances.filetype = 'artis' self.model = Radial1DModel.from_config(self.config)
def setup(self): filename = "tardis_configv1_artis_density_v_slice.yml" self.config = Configuration.from_yaml(data_path(filename)) self.config.model.abundances.type = "file" self.config.model.abundances.filename = "artis_abundances.dat" self.config.model.abundances.filetype = "artis" self.model = Radial1DModel.from_config(self.config)
def test_ascii_reader_power_law(): filename = 'tardis_configv1_density_power_law_test.yml' config = Configuration.from_yaml(data_path(filename)) model = Radial1DModel.from_config(config) expected_densites = [3.29072513e-14, 2.70357804e-14, 2.23776573e-14, 1.86501954e-14, 1.56435277e-14, 1.32001689e-14, 1.12007560e-14, 9.55397475e-15, 8.18935779e-15, 7.05208050e-15, 6.09916083e-15, 5.29665772e-15, 4.61758699e-15, 4.04035750e-15, 3.54758837e-15, 3.12520752e-15, 2.76175961e-15, 2.44787115e-15, 2.17583442e-15, 1.93928168e-15] assert model.no_of_shells == 20 for i, mdens in enumerate(expected_densites): assert_almost_equal(model.density[i].to(u.Unit('g / (cm3)')).value, mdens)
def grid_row_to_model(self, row_index): """ Generates a TARDIS Radial1DModel object using the base self.config modified by the specified grid row. Parameters ---------- row_index : int Row index in grid. Returns ------- model : tardis.model.base.Radial1DModel """ rowconfig = self.grid_row_to_config(row_index) model = Radial1DModel.from_config(rowconfig) return model
def test_compare_models(model_config_fnames): """Compare identical models produced by .from_config and .from_csvy to check that velocities, densities and abundances (pre and post decay) are the same""" csvy_config_file, old_config_file = model_config_fnames tardis_config = Configuration.from_yaml(csvy_config_file) tardis_config_old = Configuration.from_yaml(old_config_file) csvy_model = Radial1DModel.from_csvy(tardis_config) config_model = Radial1DModel.from_config(tardis_config_old) csvy_model_props = csvy_model.get_properties().keys() config_model_props = config_model.get_properties().keys() npt.assert_array_equal(csvy_model_props, config_model_props) for prop in config_model_props: csvy_model_val = csvy_model.get_properties()[prop] config_model_val = config_model.get_properties()[prop] if prop == "homologous_density": npt.assert_array_almost_equal( csvy_model_val.density_0.value, config_model_val.density_0.value ) npt.assert_array_almost_equal( csvy_model_val.time_0.value, config_model_val.time_0.value ) else: if hasattr(config_model_val, "value"): config_model_val = config_model_val.value csvy_model_val = csvy_model_val.value npt.assert_array_almost_equal(csvy_model_val, config_model_val) assert csvy_model.raw_abundance.shape == config_model.raw_abundance.shape assert ( csvy_model.raw_isotope_abundance.shape == config_model.raw_isotope_abundance.shape ) assert csvy_model.abundance.shape == config_model.abundance.shape npt.assert_array_almost_equal( csvy_model.raw_abundance.to_numpy(), config_model.raw_abundance.to_numpy(), ) npt.assert_array_almost_equal( csvy_model.raw_isotope_abundance.to_numpy(), config_model.raw_isotope_abundance.to_numpy(), ) npt.assert_array_almost_equal( csvy_model.abundance.to_numpy(), config_model.abundance.to_numpy() )
def test_ascii_reader_exponential_law(): filename = 'tardis_configv1_density_exponential_test.yml' config = Configuration.from_yaml(data_path(filename)) model = Radial1DModel.from_config(config) expected_densites = [5.18114795e-14, 4.45945537e-14, 3.83828881e-14, 3.30364579e-14, 2.84347428e-14, 2.44740100e-14, 2.10649756e-14, 1.81307925e-14, 1.56053177e-14, 1.34316215e-14, 1.15607037e-14, 9.95038990e-15, 8.56437996e-15, 7.37143014e-15, 6.34464872e-15, 5.46088976e-15, 4.70023138e-15, 4.04552664e-15, 3.48201705e-15, 2.99699985e-15] expected_unit = 'g / (cm3)' assert model.no_of_shells == 20 for i, mdens in enumerate(expected_densites): assert_almost_equal(model.density[i].value, mdens) assert model.density[i].unit == u.Unit(expected_unit)
def test_compare_models(full_filename): tardis_config = Configuration.from_yaml(full_filename) csvy_model = Radial1DModel.from_csvy(tardis_config) config_model = Radial1DModel.from_config(tardis_config) csvy_model_props = csvy_model.get_properties().keys() config_model_props = config_model.get_properties().keys() npt.assert_array_equal(csvy_model_props, config_model_props) for prop in config_model_props: csvy_model_val = csvy_model.get_properties()[prop] config_model_val = config_model.get_properties()[prop] if prop == 'homologous_density': npt.assert_array_almost_equal(csvy_model_val.density_0.value, config_model_val.density_0.value) npt.assert_array_almost_equal(csvy_model_val.time_0.value, config_model_val.time_0.value) else: if hasattr(config_model_val, 'value'): config_model_val = config_model_val.value csvy_model_val = csvy_model_val.value npt.assert_array_almost_equal(csvy_model_val, config_model_val)
def test_model_decay(simple_isotope_abundance): filename = 'tardis_configv1_verysimple.yml' config = Configuration.from_yaml(data_path(filename)) model = Radial1DModel.from_config(config) model.raw_isotope_abundance = simple_isotope_abundance decayed = simple_isotope_abundance.decay( model.time_explosion).as_atoms() norm_factor = 1.4 assert_almost_equal( model.abundance.loc[8][0], model.raw_abundance.loc[8][0] / norm_factor, decimal=4) assert_almost_equal(model.abundance.loc[14][0], ( model.raw_abundance.loc[14][0] + decayed.loc[14][0]) / norm_factor, decimal=4) assert_almost_equal(model._abundance.loc[12][5], ( model.raw_abundance.loc[12][5] + decayed.loc[12][5]) / norm_factor, decimal=4) assert_almost_equal( model.abundance.loc[6][12], (decayed.loc[6][12]) / norm_factor, decimal=4)
def setup(self): filename = 'tardis_configv1_artis_density.yml' self.config = Configuration.from_yaml(data_path(filename)) self.model = Radial1DModel.from_config(self.config)
def setup(self): """Initialize config and model.""" filename = "tardis_configv1_verysimple.yml" self.config = Configuration.from_yaml(data_path(filename)) self.model = Radial1DModel.from_config(self.config)
def setup(self): filename = "tardis_configv1_artis_density.yml" self.config = Configuration.from_yaml(data_path(filename)) self.model = Radial1DModel.from_config(self.config)
def setup(self): filename = 'tardis_configv1_uniform_density.yml' self.config = Configuration.from_yaml(data_path(filename)) self.config.plasma.initial_t_inner = 2508 * u.K self.model = Radial1DModel.from_config(self.config)
def raw_model(tardis_model_density_config): return Radial1DModel.from_config(tardis_model_density_config)
def setup(self): filename = "tardis_configv1_ascii_density_abund.yml" self.config = Configuration.from_yaml(data_path(filename)) self.config.model.structure.filename = "density.dat" self.config.model.abundances.filename = "abund.dat" self.model = Radial1DModel.from_config(self.config)
def setup(self): filename = "paper1_tardis_configv1.yml" self.config = Configuration.from_yaml(data_path(filename)) self.model = Radial1DModel.from_config(self.config)
def setup(self): filename = "tardis_configv1_uniform_density.yml" self.config = Configuration.from_yaml(data_path(filename)) self.config.plasma.initial_t_inner = 2508 * u.K self.model = Radial1DModel.from_config(self.config)
def from_config(cls, config, packet_source=None, virtual_packet_logging=False, **kwargs): """ Create a new Simulation instance from a Configuration object. Parameters ---------- config : tardis.io.config_reader.Configuration **kwargs Allow overriding some structures, such as model, plasma, atomic data and the runner, instead of creating them from the configuration object. Returns ------- Simulation """ # Allow overriding some config structures. This is useful in some # unit tests, and could be extended in all the from_config classmethods. if "model" in kwargs: model = kwargs["model"] else: if hasattr(config, "csvy_model"): model = Radial1DModel.from_csvy(config) else: model = Radial1DModel.from_config(config) if "plasma" in kwargs: plasma = kwargs["plasma"] else: plasma = assemble_plasma(config, model, atom_data=kwargs.get("atom_data", None)) if "runner" in kwargs: if packet_source is not None: raise ConfigurationError( "Cannot specify packet_source and runner at the same time." ) runner = kwargs["runner"] else: runner = MontecarloRunner.from_config( config, packet_source=packet_source, virtual_packet_logging=virtual_packet_logging, ) luminosity_nu_start = config.supernova.luminosity_wavelength_end.to( u.Hz, u.spectral()) if u.isclose(config.supernova.luminosity_wavelength_start, 0 * u.angstrom): luminosity_nu_end = np.inf * u.Hz else: luminosity_nu_end = ( const.c / config.supernova.luminosity_wavelength_start).to( u.Hz) last_no_of_packets = config.montecarlo.last_no_of_packets if last_no_of_packets is None or last_no_of_packets < 0: last_no_of_packets = config.montecarlo.no_of_packets last_no_of_packets = int(last_no_of_packets) return cls( iterations=config.montecarlo.iterations, model=model, plasma=plasma, runner=runner, no_of_packets=int(config.montecarlo.no_of_packets), no_of_virtual_packets=int(config.montecarlo.no_of_virtual_packets), luminosity_nu_start=luminosity_nu_start, luminosity_nu_end=luminosity_nu_end, last_no_of_packets=last_no_of_packets, luminosity_requested=config.supernova.luminosity_requested.cgs, convergence_strategy=config.montecarlo.convergence_strategy, nthreads=config.montecarlo.nthreads, )
def setup(self): filename = 'paper1_tardis_configv1.yml' self.config = Configuration.from_yaml(data_path(filename)) self.model = Radial1DModel.from_config(self.config)
def setup(self): filename = 'tardis_configv1_ascii_density_abund.yml' self.config = Configuration.from_yaml(data_path(filename)) self.config.model.structure.filename = 'density.dat' self.config.model.abundances.filename = 'abund.dat' self.model = Radial1DModel.from_config(self.config)
def raw_model(tardis_config): return Radial1DModel.from_config(tardis_config)