mth5.utils.h5_tools
Utilities for HDF5 maintenance tasks.
Attributes
Functions
|
Repack an HDF5 file by copying all objects into a new file. |
Module Contents
- 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 fullh5repackfeature 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, overwriteoutput_filewhen it exists.
- Returns:
The output path.
- Return type:
pathlib.Path
- Raises:
FileNotFoundError – If
input_filedoes not exist.FileExistsError – If
output_fileexists andoverwriteisFalse.
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