예제 #1
0
    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

        tardis_config = Configuration.from_config_dict(self.config_yaml)
        self.model = Radial1DModel(tardis_config)
        self.simulation = Simulation(tardis_config)

        self.simulation.legacy_run_simulation(self.model)
예제 #2
0
def raw_model(tardis_config):
    return Radial1DModel(tardis_config)
예제 #3
0
    def setup(self, request, reference, data_path):
        """
        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")

        # 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:
        if 'atom_data_url' in data_path:
            # If the atom data is to be ingested from url:
            atom_data_filepath = download_file(urlparse.urljoin(
                base=data_path['atom_data_url'], url=atom_data_name), cache=True
            )
        else:
            # If the atom data is to be ingested from local file:
            atom_data_filepath = os.path.join(
                data_path['atom_data_dirpath'], atom_data_name
            )

        # Load atom data file separately, pass it for forming tardis config.
        self.atom_data = AtomData.from_hdf5(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, 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