• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python config_reader.Configuration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Configuration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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')
开发者ID:kush789,项目名称:tardis,代码行数:15,代码来源:test_config_reader.py


示例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
开发者ID:lukeshingles,项目名称:tardis,代码行数:30,代码来源:test_plasmas_full.py


示例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)
开发者ID:kush789,项目名称:tardis,代码行数:7,代码来源:test_base.py


示例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)
开发者ID:tardis-sn,项目名称:dalek,代码行数:9,代码来源:base.py


示例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()
开发者ID:kush789,项目名称:tardis,代码行数:19,代码来源:test_plasmas_full.py


示例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
开发者ID:tardis-sn,项目名称:tardis,代码行数:41,代码来源:base.py


示例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
开发者ID:rcthomas,项目名称:tardis,代码行数:12,代码来源:test_tardis_full_formal_integral.py


示例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
开发者ID:rithwiksv,项目名称:tardis,代码行数:52,代码来源:test_integration.py


示例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)
开发者ID:Chrischanmarc,项目名称:tardis,代码行数:13,代码来源:test_tardis_full.py


示例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"))
开发者ID:yeganer,项目名称:tardis,代码行数:51,代码来源:test_w7.py


示例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()
开发者ID:kush789,项目名称:tardis,代码行数:14,代码来源:test_tardis_full.py


示例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
开发者ID:lukeshingles,项目名称:tardis,代码行数:17,代码来源:test_complete_plasmas.py


示例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)
开发者ID:kush789,项目名称:tardis,代码行数:17,代码来源:test_base.py


示例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)
开发者ID:rcthomas,项目名称:tardis,代码行数:18,代码来源:test_base.py


示例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)
开发者ID:kush789,项目名称:tardis,代码行数:18,代码来源:test_base.py


示例16: runner

    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,代码行数:24,代码来源:test_tardis_full.py


示例17: tardis_model_density_config

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,代码行数:3,代码来源:test_tardis_model_density_config.py


示例18: config_verysimple

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,代码行数:5,代码来源:conftest.py


示例19: setup

    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,代码行数:74,代码来源:test_integration.py


示例20: _generate_config

 def _generate_config(self, callback):
     config_ns = callback(self.config)
     return Configuration.from_config_dict(
             config_ns,
             validate=False,
             atom_data=self.atom_data)
开发者ID:yeganer,项目名称:dalek,代码行数:6,代码来源:tardis_wrapper.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ParameterSetManager.ParameterSetManager类代码示例发布时间:2022-05-27
下一篇:
Python publishing.PublishHandler类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap