HDF5Serializer#

class pisces.utilities.io_tools.HDF5Serializer[source]#

A JSON-based serialization utility for storing complex Python objects as HDF5 attributes.

This class provides a standardized mechanism for serializing and deserializing Python objects — including extended types like unyt arrays, quantities, and units — to and from JSON strings that can be safely stored as attributes in HDF5 files.

Custom types are registered via the __REGISTRY__ class variable, which maps Python types to a tuple of:

  • A unique string tag identifying the type in serialized form,

  • A serialization function (returning a JSON-serializable dict),

  • A deserialization function (taking that dict and reconstructing the object).

Built-in JSON-compatible types (e.g., int, float, str, list, dict) are serialized directly via json.dumps. All deserialized outputs are reconstructed either via the registry or returned as-is for base types.

This class is intended to be subclassed or extended to support additional custom types.

Methods

__init__()

deserialize_data(data)

Recursively deserialize a JSON string produced by serialize_data.

deserialize_dict(data)

Recursively deserialize a dict produced by serialize_dict.

deserialize_unyt(o)

Deserialize a dictionary into a unyt object.

deserialize_unyt_unit(o)

Deserialize a dictionary into a unyt unit.

serialize_data(data)

Recursively serialize data to a JSON string for HDF5 attributes.

serialize_dict(data)

Recursively serialize a dict’s values (keys must be strings).

serialize_unyt(o)

Serialize a unyt object into a dictionary.

serialize_unyt_unit(o)

Serialize a unyt unit into a dictionary.