Skip to content

Commit

Permalink
Add provision of atom data locally.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Desai committed Aug 19, 2016
1 parent 3e55c13 commit 8d8de89
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
10 changes: 10 additions & 0 deletions tardis/tests/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def data_path(request):
),
'setup_name': hdf_filename[:-3]
}

# For providing atom data per individual setup. Atom data can be fetched
# from a local directory or a remote url.
if integration_tests_config['atom_data']['fetch'] == "remote":
path['atom_data_url'] = integration_tests_config['atom_data']['url']
elif integration_tests_config['atom_data']['fetch'] == "local":
path['atom_data_dirpath'] = os.path.expandvars(os.path.expanduser(
integration_tests_config['atom_data']['dirpath']
))

if (request.config.getoption("--generate-reference") and not
os.path.exists(path['gen_ref_dirpath'])):
os.makedirs(path['gen_ref_dirpath'])
Expand Down
28 changes: 24 additions & 4 deletions tardis/tests/integration_tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os
import yaml
import pytest
import matplotlib.pyplot as plt
from numpy.testing import assert_allclose

from astropy.tests.helper import assert_quantity_allclose
from astropy.utils.data import download_file

from tardis.atomic import AtomData
from tardis.simulation.base import run_radial1d
Expand All @@ -19,7 +22,7 @@ class TestIntegration(object):

@classmethod
@pytest.fixture(scope="class", autouse=True)
def setup(self, request, reference, data_path, atomic_data_fname):
def setup(self, request, reference, data_path):
"""
This method does initial setup of creating configuration and performing
a single run of integration test.
Expand All @@ -29,14 +32,31 @@ def setup(self, request, reference, data_path, atomic_data_fname):

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("{url}/{name}".format(
url=data_path['atom_data_url'], name=atom_data_name), cache=True
)
else:
# If the atom data is to be ingested from local file:
atom_data_filepath = "{dirpath}/{name}".format(
dirpath=data_path['atom_data_dirpath'], name=atom_data_name
)

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

0 comments on commit 8d8de89

Please sign in to comment.