Skip to content

Commit

Permalink
Relocate test_w7.py and add documentation.
Browse files Browse the repository at this point in the history
- Some changes are made in setup() method of the
  integration test - the description about it is
  now updated in the block comments.
  • Loading branch information
karandesai-96 committed Mar 13, 2016
1 parent 00784be commit e6cb426
Showing 1 changed file with 57 additions and 11 deletions.
68 changes: 57 additions & 11 deletions tardis/tests/w7_13d/test_w7.py → tardis/tests/test_w7.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import os
import yaml
import pytest
import numpy as np
import tardis
import numpy.testing as nptesting
from astropy import units as u
import os

import tardis
from tardis.simulation.base import Simulation
from tardis.model import Radial1DModel
from tardis.io.config_reader import Configuration


def w7_path(fname):
return os.path.join(tardis.__path__[0], 'tests', 'w7_13d', fname)


@pytest.mark.skipif(not pytest.config.getoption("--run-slow"),
Expand All @@ -16,18 +25,55 @@ class TestW7:
@classmethod
@pytest.fixture(scope="class", autouse=True)
def setup(self):
self.w7_config_filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'tardis_w7.yml')
self.atom_data_filepath = os.path.realpath('/tmp/kurucz_cd23_chianti_H_He.h5')
self.obtained_w7_radial1d_model = tardis.run_tardis(config=self.w7_config_filepath,
atom_data=self.atom_data_filepath)

"""
This method does an initial setup of making the configuration and performing
a single run of this integration test from Stratified W7 setup.
"""

# First we check whether the config file does even exist at the desired path.
assert os.path.exists(w7_path('tardis_w7.yml')), ('%s config file does not exist' %
w7_path('tardis_w7.yml'))

# The available config file does not have the filepaths of atom data file,
# densities and abundances profile files as desired. We form a dictionary
# from the config file and tweak those parameters - putting the filepaths
# of these three files at proper places.
self.config_yaml = yaml.load(open(w7_path('tardis_w7.yml')))

# Remaining assertions are made here - each for atom data file, abundances
# profile file and densities profile file.
assert os.path.exists('/tmp/kurucz_cd23_chianti_H_He.h5'), ('%s atom data file does not exist' %
w7_path('tardis_w7.yml'))

assert os.path.exists(w7_path('tardis_w7_13d_abundances.dat')), ('%s abundances profile file does not exist' %
w7_path('tardis_w7.yml'))

assert os.path.exists(w7_path('tardis_w7_13d_densities.dat')), ('%s densities profile file does not exist' %
w7_path('tardis_w7.yml'))

self.config_yaml['atom_data'] = '/tmp/kurucz_cd23_chianti_H_He.h5'
self.config_yaml['model']['abundances']['filename'] = w7_path('tardis_w7_13d_abundances.dat')
self.config_yaml['model']['structure']['filename'] = w7_path('tardis_w7_13d_densities.dat')

# The configuration hence obtained will be having appropriate file paths.
tardis_config = Configuration.from_config_dict(self.config_yaml)

# We now do a run with the prepared configuration and get radial1d model.
self.obtained_w7_radial1d_model = Radial1DModel(tardis_config)
self.simulation = Simulation(tardis_config)
self.simulation.legacy_run_simulation(self.obtained_w7_radial1d_model)

# The benchmark data against which assertions are to be made is ingested
# from an already available compressed binary (.npz). This will return a
# dictionary of numpy.ndarrays and the latter will also return dictionary
# of numpy.ndarrays - difference is, they were astropy quantities earlier.
self.expected_w7_ndarrays = np.load(
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'expected_ndarrays.npz')
)
os.path.join(os.path.dirname(w7_path('expected_ndarrays.npz'))
))

self.expected_w7_astropy_quantities = np.load(
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'expected_quantities.npz')
)
os.path.join(os.path.dirname(w7_path('expected_quantities.npz'))
))

def test_j_estimators(self):
np.testing.assert_allclose(
Expand Down

0 comments on commit e6cb426

Please sign in to comment.