mth5.utils.h5_tools

Utilities for HDF5 maintenance tasks.

Attributes

PathLike

Functions

repack_hdf5(→ pathlib.Path)

Repack an HDF5 file by copying all objects into a new file.

Module Contents

mth5.utils.h5_tools.PathLike[source]
mth5.utils.h5_tools.repack_hdf5(input_file: PathLike, output_file: PathLike, *, overwrite: bool = False) pathlib.Path[source]

Repack an HDF5 file by copying all objects into a new file.

Repacking can reduce file size when metadata or datasets were repeatedly modified and the source file contains unused internal space.

This mirrors the core idea of h5repack: rewrite all objects into a new HDF5 container so only live content remains. It does not expose the full h5repack feature set (for example: filter/layout transformation, chunk-size retuning, and advanced option flags).

Parameters:
  • input_file (str | pathlib.Path) – Source HDF5 file to repack.

  • output_file (str | pathlib.Path) – Destination path for the repacked HDF5 file.

  • overwrite (bool, default=False) – If True, overwrite output_file when it exists.

Returns:

The output path.

Return type:

pathlib.Path

Raises:
  • FileNotFoundError – If input_file does not exist.

  • FileExistsError – If output_file exists and overwrite is False.

Examples

>>> from mth5.utils.h5_tools import repack_hdf5
>>> repacked = repack_hdf5("survey_original.h5", "survey_repacked.h5", overwrite=True)
>>> print(repacked)
survey_repacked.h5