gemseo / utils

Hide inherited members

hdf5 module

Helper functions for hdf5 data.

gemseo.utils.hdf5.convert_h5_group_to_dict(h5_handle, group_name)[source]

Convert the values of a hdf5 dataset.

Values that are of the kind string or bytes are converted to string or list of strings.

Parameters:
  • h5_handle (h5py.File | h5py.Group) – A hdf5 file or group.

  • group_name (str) – The name of the group to be converted.

Returns:

The converted dataset.

Return type:

dict[str, str | list[str]]

gemseo.utils.hdf5.get_hdf5_group(h5py_data, name='')[source]

Return a group from a h5py data handle.

This function shall be used to show a better error message to the end user.

Parameters:
  • h5py_data (h5py.File | h5py.Group) – The hdf5 data handle.

  • name (str) –

    The name of the group, if empty returns the root.

    By default it is set to “”.

Returns:

The contents of the group.

Raises:

KeyError – if the group does not exist.

Return type:

h5py.Group

gemseo.utils.hdf5.store_attr_h5data(obj, group)[source]

Store an object in the HDF5 dataset.

The object shall be a mapping or have a method to_dict().

Parameters:
  • obj (Any) – The object to store

  • group (Group) – The hdf5 group.

Return type:

None

gemseo.utils.hdf5.store_h5data(group, data_array, dataset_name, dtype=None)[source]

Store an array in a hdf5 file group.

Parameters:
  • group (Any) – The group pointer.

  • data_array (RealArray[Number] | str | list[str | Number]) – The data to be stored.

  • dataset_name (str) – The name of the dataset to store the array.

  • dtype (str | None) – Numpy dtype or string. If None, dtype(‘f’) will be used.

Return type:

None