Skip to content

Commit

Permalink
Reintroduce and adjust various to_hdf methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
ftsamis committed Aug 19, 2016
1 parent fb1f5de commit 8bc1341
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from tardis.util import quantity_linspace, element_symbol2atomic_number
from tardis.io.model_reader import read_density_file, read_abundances_file
from tardis.io.util import to_hdf
from density import HomologousDensity

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -192,6 +193,27 @@ def v_boundary_outer_index(self):
return None
return self.raw_velocity.searchsorted(self.v_boundary_outer) + 1

def to_hdf(self, path_or_buf, path=''):
"""
Store the model to an HDF structure.
Parameters
----------
path_or_buf
Path or buffer to the HDF store
path : str
Path inside the HDF store to store the model
Returns
-------
None
"""
model_path = os.path.join(path, 'model')
properties = ['t_inner', 'w', 't_radiative', 'v_inner', 'v_outer']
to_hdf(path_or_buf, model_path, {name: getattr(self, name) for name
in properties})

@classmethod
def from_config(cls, config):
time_explosion = config.supernova.time_explosion.cgs
Expand Down
4 changes: 4 additions & 0 deletions tardis/plasma/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,7 @@ def to_hdf(self, path_or_buf, path='', collection=None):
properties = self.plasma_properties
for prop in properties:
prop.to_hdf(path_or_buf, os.path.join(path, 'plasma'))

metadata = pd.Series({'atom_data_uuid': self.atomic_data.uuid1})
metadata.to_hdf(path_or_buf,
os.path.join(os.path.join(path, 'plasma'), 'metadata'))
22 changes: 22 additions & 0 deletions tardis/simulation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,28 @@ def log_run_results(self, emitted_luminosity, absorbed_luminosity):
emitted_luminosity, absorbed_luminosity,
self.luminosity_requested))

def to_hdf(self, path_or_buf, path='', plasma_properties=None):
"""
Store the simulation to an HDF structure.
Parameters
----------
path_or_buf
Path or buffer to the HDF store
path : str
Path inside the HDF store to store the simulation
plasma_properties
`None` or a `PlasmaPropertyCollection` which will
be passed as the collection argument to the
plasma.to_hdf method.
Returns
-------
None
"""
self.runner.to_hdf(path_or_buf, path)
self.model.to_hdf(path_or_buf, path)
self.plasma.to_hdf(path_or_buf, path, plasma_properties)

@classmethod
def from_config(cls, config):
model = Radial1DModel.from_config(config)
Expand Down

0 comments on commit 8bc1341

Please sign in to comment.