当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.from_yaml方法代码示例

本文整理汇总了Python中tardis.io.config_reader.Configuration.from_yaml方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.from_yaml方法的具体用法?Python Configuration.from_yaml怎么用?Python Configuration.from_yaml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tardis.io.config_reader.Configuration的用法示例。


在下文中一共展示了Configuration.from_yaml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
 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)
开发者ID:kush789,项目名称:tardis,代码行数:9,代码来源:test_base.py

示例2: simulation

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
    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
开发者ID:lukeshingles,项目名称:tardis,代码行数:32,代码来源:test_plasmas_full.py

示例3: base_config

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
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
开发者ID:rcthomas,项目名称:tardis,代码行数:14,代码来源:test_tardis_full_formal_integral.py

示例4: setup

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
    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
开发者ID:rithwiksv,项目名称:tardis,代码行数:54,代码来源:test_integration.py

示例5: config

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
 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
开发者ID:lukeshingles,项目名称:tardis,代码行数:19,代码来源:test_complete_plasmas.py

示例6: test_ascii_reader_power_law

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
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)
开发者ID:kush789,项目名称:tardis,代码行数:19,代码来源:test_base.py

示例7: test_model_decay

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
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)
开发者ID:rcthomas,项目名称:tardis,代码行数:20,代码来源:test_base.py

示例8: test_ascii_reader_exponential_law

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
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)
开发者ID:kush789,项目名称:tardis,代码行数:20,代码来源:test_base.py

示例9: run_tardis

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [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
开发者ID:tardis-sn,项目名称:tardis,代码行数:43,代码来源:base.py

示例10: runner

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
    def runner(
            self, atomic_data_fname,
            tardis_ref_data, generate_reference):
        config = Configuration.from_yaml(
                'tardis/io/tests/data/tardis_configv1_verysimple.yml')
        config['atom_data'] = atomic_data_fname

        simulation = Simulation.from_config(config)
        simulation.run()

        if not generate_reference:
            return simulation.runner
        else:
            simulation.runner.hdf_properties = [
                    'j_blue_estimator',
                    'spectrum',
                    'spectrum_virtual'
                    ]
            simulation.runner.to_hdf(
                    tardis_ref_data,
                    '',
                    self.name)
            pytest.skip(
                    'Reference data was generated during this run.')
开发者ID:lukeshingles,项目名称:tardis,代码行数:26,代码来源:test_tardis_full.py

示例11: setup

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
    def setup(self, request, reference, data_path, pytestconfig):
        """
        This method does initial setup of creating configuration and performing
        a single run of integration test.
        """
        # Get capture manager
        capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')

        # 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")

        # A quick hack to use atom data per setup. Atom data is ingested from
        # local HDF or downloaded and cached from a url, depending on data_path
        # keys.
        atom_data_name = yaml.load(open(self.config_file))['atom_data']

        # Get the path to HDF file:
        atom_data_filepath = os.path.join(
            data_path['atom_data_path'], atom_data_name
        )

        # Load atom data file separately, pass it for forming tardis config.
        self.atom_data = AtomData.from_hdf(atom_data_filepath)

        # 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)

        # 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 the simulation object.
        self.result = Simulation.from_config(tardis_config,
                                             atom_data=self.atom_data)

        capmanager.suspendcapture(True)
        # 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.
        self.result.run()
        if request.config.getoption("--generate-reference"):
            ref_data_path = os.path.join(
                data_path['reference_path'], "{0}.h5".format(self.name)
            )
            if os.path.exists(ref_data_path):
                pytest.skip(
                    'Reference data {0} does exist and tests will not '
                    'proceed generating new data'.format(ref_data_path))
            self.result.to_hdf(file_path=ref_data_path)
            pytest.skip("Reference data saved at {0}".format(
                data_path['reference_path']
            ))
        capmanager.resumecapture()

        # Get the reference data through the fixture.
        self.reference = reference
开发者ID:rcthomas,项目名称:tardis,代码行数:76,代码来源:test_integration.py

示例12: config

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
def config():
    return Configuration.from_yaml(
            'tardis/io/tests/data/tardis_configv1_verysimple.yml')
开发者ID:lukeshingles,项目名称:tardis,代码行数:5,代码来源:test_simulation.py

示例13: config_verysimple

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
def config_verysimple():
    filename = 'tardis_configv1_verysimple.yml'
    path = os.path.abspath(os.path.join('tardis/io/tests/data/', filename))
    config = Configuration.from_yaml(path)
    return config
开发者ID:tardis-sn,项目名称:tardis,代码行数:7,代码来源:conftest.py

示例14: isotope_uniform_abundance

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
def isotope_uniform_abundance():
    config_path = os.path.join(
        data_path, 'tardis_configv1_isotope_uniabund.yml')
    config = Configuration.from_yaml(config_path)
    return config.model.abundances
开发者ID:rcthomas,项目名称:tardis,代码行数:7,代码来源:test_model_reader.py

示例15: tardis_model_density_config

# 需要导入模块: from tardis.io.config_reader import Configuration [as 别名]
# 或者: from tardis.io.config_reader.Configuration import from_yaml [as 别名]
def tardis_model_density_config():
    filename = 'tardis_configv1_tardis_model_format.yml'
    return Configuration.from_yaml(os.path.join(data_path, filename))
开发者ID:rcthomas,项目名称:tardis,代码行数:5,代码来源:test_tardis_model_density_config.py


注:本文中的tardis.io.config_reader.Configuration.from_yaml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。