tardis.io.hdf_writer_mixin module

class tardis.io.hdf_writer_mixin.HDFWriterMixin(*args: Any, **kwargs: Any)[source]

Bases: object

Mixin class that provides HDF writing functionality to other classes.

Create a new instance and initialize HDF properties.

Parameters:
*argsAny

Positional arguments passed to the parent class.

**kwargsAny

Keyword arguments passed to the parent class.

Returns:
HDFWriterMixin

The new instance with initialized HDF properties.

static convert_to_snake_case(s: str) str[source]

Convert a camelCase or PascalCase string to snake_case.

Parameters:
sstr

The string to convert.

Returns:
str

The string converted to snake_case.

property full_hdf_properties: List[str]

Get the full list of HDF properties.

Returns:
List[str]

List of all HDF property names.

get_properties() Dict[str, Any][source]

Get properties for HDF storage.

Returns:
Dict[str, Any]

Dictionary of property names and their values.

to_hdf(file_path_or_buf: str | HDFStore, path: str = '', name: str | None = None, overwrite: bool = False, format: str | None = None) None[source]

Save the object to an HDF file.

Parameters:
file_path_or_bufstr or pandas.HDFStore

Path or buffer to the HDF file.

pathstr, optional

Path inside the HDF file to store the elements, by default “”.

namestr, optional

Group inside the HDF file to which the elements need to be saved. If None, will use the class name converted to snake_case.

overwritebool, optional

If the HDF file path already exists, whether to overwrite it or not, by default False.

static to_hdf_util(path_or_buf: str | HDFStore, path: str, elements: Dict[str, Any], overwrite: bool, complevel: int = 9, complib: str = 'blosc', format=None) None[source]

A function to uniformly store TARDIS data to an HDF file.

Scalars will be stored in a Series under path/scalars. 1D arrays will be stored under path/property_name as distinct Series. 2D arrays will be stored under path/property_name as distinct DataFrames.

Units will be stored as their CGS value.

Parameters:
path_or_bufstr or pandas.HDFStore

Path or buffer to the HDF file.

pathstr

Path inside the HDF file to store the elements.

elementsdict

A dict of property names and their values to be stored.

overwritebool

If the HDF file path already exists, whether to overwrite it or not.

complevelint, optional

Compression level for the HDF file, by default 9.

complibstr, optional

Compression library to use, by default “blosc”.

Raises:
FileExistsError

If the HDF file already exists and overwrite is False.

Notes

overwrite option doesn’t have any effect when path_or_buf is an HDFStore because the user decides on the mode in which they have opened the HDFStore (‘r’, ‘w’ or ‘a’).

class tardis.io.hdf_writer_mixin.PlasmaWriterMixin(*args: Any, **kwargs: Any)[source]

Bases: HDFWriterMixin

Mixin class for writing plasma data to HDF files.

Create a new instance and initialize HDF properties.

Parameters:
*argsAny

Positional arguments passed to the parent class.

**kwargsAny

Keyword arguments passed to the parent class.

Returns:
HDFWriterMixin

The new instance with initialized HDF properties.

get_properties() Dict[str, Any][source]

Get plasma properties for HDF storage.

Returns:
Dict[str, Any]

Dictionary of plasma property names and their values.

to_hdf(file_path_or_buf: str | HDFStore, path: str = '', name: str | None = None, collection: Any = None, overwrite: bool = False, format: str | None = None) None[source]

Save the plasma object to an HDF file.

Parameters:
file_path_or_bufstr or pandas.HDFStore

Path or buffer to the HDF file.

pathstr, optional

Path inside the HDF file to store the elements, by default “”.

namestr, optional

Group inside the HDF file to which the elements need to be saved.

collectionAny, optional

None or a PlasmaPropertyCollection of which members are the property types which will be stored. If None then all types of properties will be stored. This acts like a filter, for example if a value of property_collections.basic_inputs is given, only those input parameters will be stored to the HDF file.

overwritebool, optional

If the HDF file path already exists, whether to overwrite it or not, by default False.