-
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests to the simulation package
- Loading branch information
1 parent
31a94bc
commit df96a6b
Showing
5 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
from setuptools import Extension | ||
from astropy_helpers.setup_helpers import get_distutils_option | ||
import numpy as np | ||
|
||
def get_package_data(): | ||
return {'tardis.simulation.tests':['data/*.h5']} | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import numpy.testing as npt | ||
|
||
import h5py | ||
import pytest | ||
from tardis.io import config_reader | ||
from tardis.model import Radial1DModel | ||
from tardis.simulation import Simulation | ||
|
||
|
||
|
||
import pandas as pd | ||
|
||
@pytest.fixture | ||
def tardis_config(kurucz_atomic_data, tardis_config_verysimple): | ||
return config_reader.Configuration.from_config_dict( | ||
tardis_config_verysimple, atom_data=kurucz_atomic_data) | ||
|
||
|
||
@pytest.fixture() | ||
def raw_model(tardis_config): | ||
return Radial1DModel(tardis_config) | ||
|
||
|
||
@pytest.fixture() | ||
def simulation_one_loop(raw_model, tardis_config): | ||
sim = Simulation(tardis_config) | ||
sim.run_single_montecarlo(raw_model, 40000) | ||
|
||
return sim | ||
|
||
@pytest.fixture() | ||
def simulation_compare_data_fname(): | ||
return 'tardis/simulation/tests/data/test_data.h5' | ||
|
||
@pytest.fixture() | ||
def simulation_compare_data(simulation_compare_data_fname): | ||
return h5py.File(simulation_compare_data_fname, mode='r') | ||
|
||
|
||
|
||
def test_plasma_estimates(simulation_one_loop, simulation_compare_data): | ||
npt.assert_allclose(simulation_one_loop.runner.j_estimator, | ||
simulation_compare_data['test1/j_estimators'], atol=0.0) | ||
npt.assert_allclose(simulation_one_loop.runner.nu_bar_estimator, | ||
simulation_compare_data['test1/nubar_estimators'], | ||
atol=0.0) | ||
|
||
t_rad, w = simulation_one_loop.runner.calculate_radiationfield_properties() | ||
npt.assert_allclose(t_rad, simulation_compare_data['test1/t_rad'], atol=0.0) | ||
npt.assert_allclose(w, simulation_compare_data['test1/w'], atol=0.0) | ||
|
||
def test_packet_output(simulation_one_loop, simulation_compare_data): | ||
npt.assert_allclose(simulation_one_loop.runner.output_nu, | ||
simulation_compare_data['test1/output_nu'], atol=0.0) | ||
|
||
npt.assert_allclose(simulation_one_loop.runner.output_energy, | ||
simulation_compare_data['test1/output_energy'], | ||
atol=0.0) |