本文整理汇总了Python中tardis.io.config_reader.Configuration类的典型用法代码示例。如果您正苦于以下问题:Python Configuration类的具体用法?Python Configuration怎么用?Python Configuration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_config_dict
def test_from_config_dict(tardis_config_verysimple):
conf = Configuration.from_config_dict(tardis_config_verysimple,
validate=True,
config_dirname='test')
assert conf.config_dirname == 'test'
assert_almost_equal(conf.spectrum.start.value,
tardis_config_verysimple['spectrum']['start'].value)
assert_almost_equal(conf.spectrum.stop.value,
tardis_config_verysimple['spectrum']['stop'].value)
tardis_config_verysimple['spectrum']['start'] = 'Invalid'
with pytest.raises(ValidationError):
conf = Configuration.from_config_dict(tardis_config_verysimple,
validate=True,
config_dirname='test')
示例2: simulation
def simulation(
self, request, atomic_data_fname,
generate_reference, tardis_ref_data):
name = request.param[0]
config = Configuration.from_yaml(request.param[1])
config['atom_data'] = atomic_data_fname
simulation = Simulation.from_config(config)
simulation.run()
self._test_name = name
if not generate_reference:
return simulation
else:
simulation.plasma.hdf_properties = [
'level_number_density',
]
simulation.model.hdf_properties = [
't_radiative'
]
simulation.plasma.to_hdf(
tardis_ref_data,
self.name,
self._test_name)
simulation.model.to_hdf(
tardis_ref_data,
self.name,
self._test_name)
pytest.skip(
'Reference data was generated during this run.')
return simulation
示例3: setup
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)
示例4: _get_config_from_args
def _get_config_from_args(self, args):
config_name_space = copy.deepcopy(self.config_name_space)
for i, param_value in enumerate(args):
param_value = np.squeeze(param_value)
config_name_space.set_config_item(
self.convert_param_dict.values()[i], param_value)
return Configuration.from_config_dict(config_name_space,
validate=False,
atom_data=self.atom_data)
示例5: setup
def setup(self):
self.atom_data_filename = os.path.expanduser(os.path.expandvars(
pytest.config.getvalue('atomic-dataset')))
assert os.path.exists(self.atom_data_filename), ("{0} atomic datafiles"
" does not seem to "
"exist".format(
self.atom_data_filename))
self.config_yaml = yaml_load_config_file(
'tardis/plasma/tests/data/plasma_test_config_lte.yml')
self.config_yaml['atom_data'] = self.atom_data_filename
conf = Configuration.from_config_dict(self.config_yaml)
self.lte_simulation = Simulation.from_config(conf)
self.lte_simulation.run()
self.config_yaml = yaml_load_config_file(
'tardis/plasma/tests/data/plasma_test_config_nlte.yml')
self.config_yaml['atom_data'] = self.atom_data_filename
conf = Configuration.from_config_dict(self.config_yaml)
self.nlte_simulation = Simulation.from_config(conf)
self.nlte_simulation.run()
示例6: run_tardis
def run_tardis(config, atom_data=None, simulation_callbacks=[]):
"""
This function is one of the core functions to run TARDIS from a given
config object.
It will return a model object containing
Parameters
----------
config: ~str or ~dict
filename of configuration yaml file or dictionary
atom_data: ~str or ~tardis.atomic.AtomData
if atom_data is a string it is interpreted as a path to a file storing
the atomic data. Atomic data to use for this TARDIS simulation. If set to None, the
atomic data will be loaded according to keywords set in the configuration
[default=None]
"""
from tardis.io.config_reader import Configuration
from tardis.io.atom_data.base import AtomData
from tardis.simulation import Simulation
if atom_data is not None:
try:
atom_data = AtomData.from_hdf(atom_data)
except TypeError:
atom_data = atom_data
try:
tardis_config = Configuration.from_yaml(config)
except TypeError:
tardis_config = Configuration.from_config_dict(config)
simulation = Simulation.from_config(tardis_config, atom_data=atom_data)
for cb in simulation_callbacks:
simulation.add_callback(cb)
simulation.run()
return simulation
示例7: base_config
def base_config(request):
config = Configuration.from_yaml(
'tardis/io/tests/data/tardis_configv1_verysimple.yml')
config["plasma"]["line_interaction_type"] = request.param
config["montecarlo"]["no_of_packets"] = 4.0e+4
config["montecarlo"]["last_no_of_packets"] = 1.0e+5
config["montecarlo"]["no_of_virtual_packets"] = 0
config["spectrum"]["method"] = "integrated"
config["spectrum"]["integrated"]["points"] = 200
return config
示例8: setup
def setup(self, request, reference, data_path, atomic_data_fname):
"""
This method does initial setup of creating configuration and performing
a single run of integration test.
"""
# The last component in dirpath can be extracted as name of setup.
self.name = data_path['setup_name']
self.config_file = os.path.join(data_path['config_dirpath'], "config.yml")
# Load atom data file separately, pass it for forming tardis config.
self.atom_data = AtomData.from_hdf5(atomic_data_fname)
# Check whether the atom data file in current run and the atom data
# file used in obtaining the reference data are same.
# TODO: hard coded UUID for kurucz atom data file, generalize it later.
kurucz_data_file_uuid1 = "5ca3035ca8b311e3bb684437e69d75d7"
assert self.atom_data.uuid1 == kurucz_data_file_uuid1
# Create a Configuration through yaml file and atom data.
tardis_config = Configuration.from_yaml(
self.config_file, atom_data=self.atom_data)
# Check whether current run is with less packets.
if request.config.getoption("--less-packets"):
less_packets = request.config.integration_tests_config['less_packets']
tardis_config['montecarlo']['no_of_packets'] = (
less_packets['no_of_packets']
)
tardis_config['montecarlo']['last_no_of_packets'] = (
less_packets['last_no_of_packets']
)
# We now do a run with prepared config and get radial1d model.
self.result = Radial1DModel(tardis_config)
# If current test run is just for collecting reference data, store the
# output model to HDF file, save it at specified path. Skip all tests.
# Else simply perform the run and move further for performing
# assertions.
if request.config.getoption("--generate-reference"):
run_radial1d(self.result, hdf_path_or_buf=os.path.join(
data_path['gen_ref_dirpath'], "{0}.h5".format(self.name)
))
pytest.skip("Reference data saved at {0}".format(
data_path['gen_ref_dirpath']
))
else:
run_radial1d(self.result)
# Get the reference data through the fixture.
self.reference = reference
示例9: setup
def setup(self):
self.atom_data_filename = os.path.expanduser(os.path.expandvars(
pytest.config.getvalue('atomic-dataset')))
assert os.path.exists(self.atom_data_filename), ("{0} atomic datafiles "
"does not seem to "
"exist".format(
self.atom_data_filename))
self.config_yaml = yaml.load(open('tardis/io/tests/data/tardis_configv1_verysimple.yml'))
self.config_yaml['atom_data'] = self.atom_data_filename
self.config = Configuration.from_config_dict(self.config_yaml)
self.model = model.Radial1DModel(self.config)
simulation.run_radial1d(self.model)
示例10: setup
def setup(self):
"""
This method does initial setup of creating configuration and performing
a single run of integration test.
"""
self.config_file = data_path("config_w7.yml")
self.abundances = data_path("abundancies_w7.dat")
self.densities = data_path("densities_w7.dat")
# First we check whether atom data file exists at desired path.
self.atom_data_filename = os.path.expanduser(os.path.expandvars(
pytest.config.getvalue('atomic-dataset')))
assert os.path.exists(self.atom_data_filename), \
"{0} atom data file does not exist".format(self.atom_data_filename)
# The available config file doesn't have file paths of atom data file,
# densities and abundances profile files as desired. We load the atom
# data seperately and provide it to tardis_config later. For rest of
# the two, we form dictionary from the config file and override those
# parameters by putting file paths of these two files at proper places.
config_yaml = yaml.load(open(self.config_file))
config_yaml['model']['abundances']['filename'] = self.abundances
config_yaml['model']['structure']['filename'] = self.densities
# Load atom data file separately, pass it for forming tardis config.
self.atom_data = AtomData.from_hdf5(self.atom_data_filename)
# Check whether the atom data file in current run and the atom data
# file used in obtaining the baseline data for slow tests are same.
# TODO: hard coded UUID for kurucz atom data file, generalize it later.
kurucz_data_file_uuid1 = "5ca3035ca8b311e3bb684437e69d75d7"
assert self.atom_data.uuid1 == kurucz_data_file_uuid1
# The config hence obtained will be having appropriate file paths.
tardis_config = Configuration.from_config_dict(config_yaml, self.atom_data)
# We now do a run with prepared config and get radial1d model.
self.obtained_radial1d_model = Radial1DModel(tardis_config)
simulation = Simulation(tardis_config)
simulation.legacy_run_simulation(self.obtained_radial1d_model)
# The baseline data against which assertions are to be made is ingested
# from already available compressed binaries (.npz). These will return
# dictionaries of numpy.ndarrays for performing assertions.
self.slow_test_data_dir = os.path.join(os.path.expanduser(
os.path.expandvars(pytest.config.getvalue('slow-test-data'))), "w7")
self.expected_ndarrays = np.load(os.path.join(self.slow_test_data_dir,
"ndarrays.npz"))
self.expected_quantities = np.load(os.path.join(self.slow_test_data_dir,
"quantities.npz"))
示例11: setup
def setup(self):
self.atom_data_filename = os.path.expanduser(os.path.expandvars(
pytest.config.getvalue('atomic-dataset')))
assert os.path.exists(self.atom_data_filename), ("{0} atomic datafiles"
" does not seem to "
"exist".format(
self.atom_data_filename))
self.config_yaml = yaml_load_config_file(
'tardis/io/tests/data/tardis_configv1_verysimple.yml')
self.config_yaml['atom_data'] = self.atom_data_filename
tardis_config = Configuration.from_config_dict(self.config_yaml)
self.simulation = Simulation.from_config(tardis_config)
self.simulation.run()
示例12: config
def config(self, request):
config_path = os.path.join(
'tardis', 'plasma', 'tests', 'data', 'plasma_base_test_config.yml')
config = Configuration.from_yaml(config_path)
hash_string = ''
for prop, value in request.param.items():
hash_string = '_'.join((hash_string, prop))
if prop == 'nlte':
for nlte_prop, nlte_value in request.param[prop].items():
config.plasma.nlte[nlte_prop] = nlte_value
if nlte_prop != 'species':
hash_string = '_'.join((hash_string, nlte_prop))
else:
config.plasma[prop] = value
hash_string = '_'.join((hash_string, str(value)))
setattr(config.plasma, 'save_path', hash_string)
return config
示例13: test_ascii_reader_power_law
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)
示例14: test_model_decay
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)
示例15: test_ascii_reader_exponential_law
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)