Skip to content

h5 ⚓︎

HDF5 functions, and utils, and generators, OH MY!

Modules:

  • cli

    h5.cli

  • core

    HDF5 functions, and utils, and generators, OH MY!

  • dev

    h5.dev ~ Under construction!

  • legacy

    Legacy; to be deprecated

  • testing

Classes:

Functions:

Attributes:

H5pyCompression module-attribute ⚓︎

H5pyCompression = Literal['gzip', 'lzf', 'szip']

h5py mode strings (taken from h5py docstrings)):

r        Readonly, file must exist (default)
r+       Read/write, file must exist
w        Create file, truncate if exists
w- or x  Create file, fail if exists
a        Read/write if exists, create otherwise

FileInfo dataclass ⚓︎

FileInfo(
    groups: Dict[str, GroupInfo],
    attrs: Dict[str, Any],
    datasets: Dict[str, DatasetInfo],
    fspath: str,
    fssize: int,
    key: str,
    h5type: Literal["file"],
)

Bases: GroupLikeInfo

Methods:

  • from_h5py_file

    could do with dict-comprehension, but not readable (imo)

from_h5py_file classmethod ⚓︎

from_h5py_file(h5py_group: File) -> FileInfo

could do with dict-comprehension, but not readable (imo)

datasets_and_groups = {
    obj.name: H5Group.from_h5py_group(obj)
    if isinstance(obj, Group)
    else H5Dataset.from_h5py_dataset(obj)
    for obj in h5py_group.values()
}

as_h5py_obj ⚓︎

as_h5py_obj(obj: T_FsPathOrGroupLike) -> Union[File, Group]

Convert a path or h5py object to an h5py object

attrs ⚓︎

attrs(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Iterable[Tuple[str, AttributeManager]]

Return a generator that yields tuples with: (HDF5-path, HDF5-attr)

attrs_dict ⚓︎

attrs_dict(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Dict[
    str, Dict[str, Union[str, NDArray[Any], int, float]]
]

Load an HDF5 file from a fspath into a dictionary

Given a fspath this method loads an HDF5 file into a dictionary where the key => value pairs are the HDF5-path => HDF5-dataset for the file. This method relies on the h5_dataset_gen that is in this very module to generate tuples of the form (HDF5-path, HDF5-dataset).

Parameters:

  • h5_obj ⚓︎

    (str) –

    Filepath to an HDF5 format file

  • h5_path ⚓︎

    (str, default: '' ) –

    HDF5 path to recurse down from

Returns:

attrs_gen ⚓︎

attrs_gen(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Iterable[Tuple[str, AttributeManager]]

Return a generator that yields tuples with: (HDF5-path, HDF5-attr)

attrs_gen_from_fspath ⚓︎

attrs_gen_from_fspath(
    fspath: FsPath, h5_path: str = ""
) -> Iterable[Tuple[str, AttributeManager]]

Given a fspath to an h5, yield (h5-path, h5py.Dataset) tuples

Parameters:

  • fspath ⚓︎

    (FsPath) –

    fspath to h5 format file

  • h5_path ⚓︎

    (str, default: '' ) –

    h5 path to start from. Defaults to "".

Returns:

  • Iterable[Tuple[str, AttributeManager]]

    Generator that yields tuples of the form (h5-path, h5py.AttributeManager) tuples

datasets ⚓︎

datasets(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Iterable[Tuple[str, Dataset]]

Return a generator that yields tuples with: (HDF5-path, Dataset)

datasets_dict ⚓︎

datasets_dict(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Dict[str, Union[NDArray[Any], int8, float64]]

Load an HDF5 file from a fspath into a dictionary

Given a fspath this method loads an HDF5 file into a dictionary where the key => value pairs are the HDF5-path => HDF5-dataset for the file. This method relies on the h5_dataset_gen that is in this very module to generate tuples of the form (HDF5-path, HDF5-dataset).

Parameters:

  • h5_obj ⚓︎

    (str) –

    Filepath to an HDF5 format file

  • h5_path ⚓︎

    (str, default: '' ) –

    Path to start from. Defaults to "".

Returns:

  • Dict[str, Union[NDArray[Any], int8, float64]]

    Dictionary with key => value paris of HDF5-path => HDF5-dataset

datasets_gen ⚓︎

datasets_gen(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Iterable[Tuple[str, Dataset]]

Return a generator that yields tuples with: (HDF5-path, Dataset)

datasets_gen_from_fspath ⚓︎

datasets_gen_from_fspath(
    fspath: str, h5_path: str = ""
) -> Iterable[Tuple[str, Dataset]]

Given a fspath to an h5, yield (h5-path, h5py.Dataset) tuples

Parameters:

  • fspath ⚓︎

    (str) –

    fspath to h5 format file

  • h5_path ⚓︎

    (str, default: '' ) –

    h5 path to start from. Defaults to "".

Returns:

  • Iterable[Tuple[str, Dataset]]

    Generator that yields tuples of the form (h5-path, h5py.Dataset) tuples

datasets_keys_list ⚓︎

datasets_keys_list(
    h5py_obj: Union[File, Group, FsPath],
) -> List[str]

Return a list of all keys/paths for an h5py object.

Parameters:

  • h5py_obj ⚓︎

    (Union[File, Group, FsPath]) –

    h5-h5py group object

Returns:

  • List[str]

    Generator that yields tuples; (h5-path, h5py.Dataset)

fmt_h5_path cached ⚓︎

fmt_h5_path(head: str, tail: str) -> str

Format function for HDF5-path-strings

Example

fmt_h5_path("foo", "bar") '/foo/bar'

groups ⚓︎

groups(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Iterable[Tuple[str, AttributeManager]]

Return a generator that yields tuples with: (HDF5-path, h5py.Group)

groups_gen ⚓︎

groups_gen(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Iterable[Tuple[str, AttributeManager]]

Return a generator that yields tuples with: (HDF5-path, h5py.Group)

groups_gen_from_fspath ⚓︎

groups_gen_from_fspath(
    fspath: FsPath, h5_path: str = ""
) -> Iterable[Tuple[str, Group]]

Given a fspath to an h5, yield (h5-path, h5py.Dataset) tuples

Parameters:

  • fspath ⚓︎

    (FsPath) –

    fspath to h5 format file

  • h5_path ⚓︎

    (str, default: '' ) –

    h5 path to start from. Defaults to "".

Returns:

  • Iterable[Tuple[str, Group]]

    Generator that yields tuples of the form (h5-path, h5py.AttributeManager) tuples

h5_attrs_dict ⚓︎

h5_attrs_dict(
    fspath: str, h5_path: str = ""
) -> Dict[str, H5pyAttributesDict]

Alias for h5.attrs_dict

h5_attrs_gen ⚓︎

h5_attrs_gen(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Iterable[Tuple[str, AttributeManager]]

Alias for h5.datasets_gen

h5_attrs_gen_from_fspath ⚓︎

h5_attrs_gen_from_fspath(
    fspath: FsPath, h5_path: str = ""
) -> Iterable[Tuple[str, AttributeManager]]

Given a fspath to an h5, yield (h5-path, h5py.Dataset) tuples

Parameters:

  • fspath ⚓︎

    (FsPath) –

    fspath to h5 format file

  • h5_path ⚓︎

    (str, default: '' ) –

    h5 path to start from. Defaults to "".

Returns:

  • Iterable[Tuple[str, AttributeManager]]

    Generator that yields tuples of the form (h5-path, h5py.AttributeManager) tuples

h5_datasets_dict ⚓︎

h5_datasets_dict(
    fspath: str, h5_path: str = ""
) -> Dict[str, Union[NDArray[Any], int8, float64]]

Alias for h5.datasets_dict

h5_datasets_gen ⚓︎

h5_datasets_gen(
    h5_obj: Union[FsPath, File, Group], h5_path: str = ""
) -> Iterable[Tuple[str, Dataset]]

Alias for h5.datasets_gen

h5_datasets_gen_from_fspath ⚓︎

h5_datasets_gen_from_fspath(
    fspath: str, h5_path: str = ""
) -> Iterable[Tuple[str, Dataset]]

Given a fspath to an h5, yield (h5-path, h5py.Dataset) tuples

Parameters:

  • fspath ⚓︎

    (str) –

    fspath to h5 format file

  • h5_path ⚓︎

    (str, default: '' ) –

    h5 path to start from. Defaults to "".

Returns:

  • Iterable[Tuple[str, Dataset]]

    Generator that yields tuples of the form (h5-path, h5py.Dataset) tuples

h5py_obj_attrs_gen ⚓︎

h5py_obj_attrs_gen(
    h5py_obj: Union[File, Group],
    h5_path: str = "",
    root: bool = True,
) -> Iterable[Tuple[str, AttributeManager]]

Recursive h5py.AttributeManager generator.

Parameters:

  • h5py_obj ⚓︎

    (Union[File, Group]) –

    h5-h5py group object

  • h5_path ⚓︎

    (str, default: '' ) –

    path so far (Default value = "")

  • root ⚓︎

    (bool, default: True ) –

    if True, yield the root path (Default value = True)

Returns:

  • Iterable[Tuple[str, AttributeManager]]

    Generator that yields tuples; (h5-path, h5py.AttributeManager)

h5py_obj_dataset_gen ⚓︎

h5py_obj_dataset_gen(
    h5py_obj: Union[File, Group], h5_path: str = ""
) -> Iterable[Tuple[str, Dataset]]

Recursive h5 dataset generator.

Given an h5 group, which is what one gets after loading an h5 file via h5py, this function yields tuples containing (1.) a path (h5_path) to a dataset in the group, and (2.) the dataset itself as a numpy array.

Parameters:

  • h5py_obj ⚓︎

    (Union[File, Group]) –

    h5-h5py group object

  • h5_path ⚓︎

    (str, default: '' ) –

    path so far (Default value = "")

Returns:

  • Iterable[Tuple[str, Dataset]]

    Generator that yields tuples; (h5-path, h5py.Dataset)

h5py_obj_gen ⚓︎

h5py_obj_gen(
    h5py_obj: Union[File, Group],
    h5_path: str = "",
    root: bool = True,
) -> Iterable[Tuple[str, Union[Dataset, Group, File]]]

Recursive h5 dataset/group generator.

Parameters:

  • h5py_obj ⚓︎

    (Union[File, Group]) –

    h5-h5py group object

  • h5_path ⚓︎

    (str, default: '' ) –

    path so far (Default value = "")

  • root ⚓︎

    (bool, default: True ) –

    if True, yield the root path (Default value = True)

Returns:

  • Iterable[Tuple[str, Union[Dataset, Group, File]]]

    Generator that yields tuples; (h5-path, h5py.AttributeManager)

h5py_obj_groups_gen ⚓︎

h5py_obj_groups_gen(
    h5py_obj: Union[File, Group],
    h5_path: str = "",
    root: bool = True,
) -> Iterable[Tuple[str, Group]]

Recursive h5 groups generator.

Parameters:

  • h5py_obj ⚓︎

    (Union[File, Group]) –

    h5-h5py group object

  • h5_path ⚓︎

    (str, default: '' ) –

    path so far (Default value = "")

  • root ⚓︎

    (bool, default: True ) –

    if True, yield the root path (Default value = True)

Returns:

  • Iterable[Tuple[str, Group]]

    Generator that yields tuples; (h5-path, h5py.AttributeManager)

h5py_obj_keys_gen ⚓︎

h5py_obj_keys_gen(
    h5py_obj: Union[File, Group],
    h5_path: str = "",
    root: bool = True,
) -> Iterable[str]

Recursive h5 dataset generator.

Parameters:

  • h5py_obj ⚓︎

    (Union[File, Group]) –

    h5-h5py group object

  • h5_path ⚓︎

    (str, default: '' ) –

    path so far (Default value = "")

  • root ⚓︎

    (bool, default: True ) –

    if True, yield the root path (Default value = True)

Returns:

  • Iterable[str]

    Generator that yields tuples; (h5-path, h5py.AttributeManager)

is_dataset ⚓︎

is_dataset(obj: Any) -> TypeGuard[Dataset]

h5py.Dataset type guard

is_file ⚓︎

is_file(obj: Any) -> TypeGuard[File]

h5py.File type guard

is_group ⚓︎

is_group(obj: Any) -> TypeGuard[Group]

h5py.Group type guard

is_h5py_dataset ⚓︎

is_h5py_dataset(obj: Any) -> TypeGuard[Dataset]

h5py.Dataset type guard

is_h5py_file ⚓︎

is_h5py_file(obj: Any) -> TypeGuard[File]

h5py.File type guard

is_h5py_group ⚓︎

is_h5py_group(obj: Any) -> TypeGuard[Group]

h5py.Group type guard

is_hdf5 ⚓︎

is_hdf5(path: FsPath) -> bool

Check if a file is an HDF5 file

keys_list ⚓︎

keys_list(
    h5py_obj: Union[File, Group, FsPath],
) -> List[str]

Return a list of all keys/paths for an h5py object.

Parameters:

  • h5py_obj ⚓︎

    (Union[File, Group, FsPath]) –

    h5-h5py group object

Returns:

  • List[str]

    Generator that yields tuples; (h5-path, h5py.Dataset)