本文整理汇总了Python中tardis.io.config_reader.Configuration.from_config_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.from_config_dict方法的具体用法?Python Configuration.from_config_dict怎么用?Python Configuration.from_config_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tardis.io.config_reader.Configuration
的用法示例。
在下文中一共展示了Configuration.from_config_dict方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_config_dict
# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_config_dict [as 别名]
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: _get_config_from_args
# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_config_dict [as 别名]
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)
示例3: setup
# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_config_dict [as 别名]
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()
示例4: setup
# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_config_dict [as 别名]
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)
示例5: setup
# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_config_dict [as 别名]
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"))
示例6: setup
# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_config_dict [as 别名]
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()
示例7: run_tardis
# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_config_dict [as 别名]
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
示例8: tardis_config
# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_config_dict [as 别名]
def tardis_config(tardis_config_verysimple):
return Configuration.from_config_dict(tardis_config_verysimple)
示例9: _generate_config
# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_config_dict [as 别名]
def _generate_config(self, callback):
config_ns = callback(self.config)
return Configuration.from_config_dict(
config_ns,
validate=False,
atom_data=self.atom_data)