Documentation

This module contains functions to save and load objects, using the HDF5 format.

class fsc.hdf5_io.HDF5Enabled[source]

Base class for data which can be serialized to and deserialized from HDF5.

class fsc.hdf5_io.SimpleHDF5Mapping[source]

Base class for data classes which simply map their member to HDF5 values / groups.

The child class needs to define a list HDF5_ATTRIBUTES of attributes which should be serialized. The name of the attributes must correspond to the name accepted by the constructor.

For attributes which can be serialized but are not required, it can also define a list HDF5_OPTIONAL. The same logic as for the HDF5_ATTRIBUTES applies, but no error is raised if an attribute does not exist.

to_hdf5(hdf5_handle)[source]

Serializes the object to HDF5 format, attaching it to the given HDF5 handle (might be a HDF5 File or Dataset).

fsc.hdf5_io.from_hdf5(hdf5_handle)[source]

Deserializes the given HDF5 handle into an object.

Parameters

hdf5_handle (h5py.File or h5py.Group.) – HDF5 location where the serialized object is stored.

fsc.hdf5_io.from_hdf5_file(hdf5_file)[source]

Alias for from_hdf5_file().

fsc.hdf5_io.load(hdf5_file)

Alias for from_hdf5_file().

fsc.hdf5_io.save(obj, hdf5_file)

Alias for to_hdf5_file().

fsc.hdf5_io.subscribe_hdf5(type_tag, extra_tags=(), check_on_load=True)[source]

Class decorator that subscribes the class with the given type_tag for serialization.

Parameters
  • type_tag (str) – Unique identifier of the class, which is injected into the HDF5 data to identify the class.

  • extra_tags (tuple(str)) – Additional tags which should be deserialized to the given class.

  • check_on_load (bool) – Flag that determines whether the ‘type_tag’ is checked when de-serializing the object.

fsc.hdf5_io.to_hdf5(obj, hdf5_handle)[source]

Serializes a given object to HDF5 format.

Parameters
  • obj – Object to serialize.

  • hdf5_handle (h5py.File or h5py.Group.) – HDF5 location where the serialized object gets stored.

fsc.hdf5_io.to_hdf5_file(obj, hdf5_file)[source]

Alias for to_hdf5_file().

fsc.hdf5_io.to_hdf5_singledispatch(obj, hdf5_handle)[source]
fsc.hdf5_io.to_hdf5_singledispatch(obj: collections.abc.Iterable, hdf5_handle)
fsc.hdf5_io.to_hdf5_singledispatch(obj: tuple, hdf5_handle)
fsc.hdf5_io.to_hdf5_singledispatch(obj: collections.abc.Mapping, hdf5_handle)
fsc.hdf5_io.to_hdf5_singledispatch(obj: numbers.Complex, hdf5_handle)
fsc.hdf5_io.to_hdf5_singledispatch(obj: numpy.str_, hdf5_handle)
fsc.hdf5_io.to_hdf5_singledispatch(obj: str, hdf5_handle)
fsc.hdf5_io.to_hdf5_singledispatch(obj: bytes, hdf5_handle)
fsc.hdf5_io.to_hdf5_singledispatch(obj: None, hdf5_handle)
fsc.hdf5_io.to_hdf5_singledispatch(obj: numpy.ndarray, hdf5_handle)

Singledispatch function which is called to serialize and object when it does not have a to_hdf5 method.

Parameters
  • obj – Object to serialize.

  • hdf5_handle (h5py.File or h5py.Group.) – HDF5 location where the serialized object gets stored.