HDF5¶
Interfaces for HDF5 Datasets
Note
HDF5 arrays are accessed through a proxy class H5Proxy .
Getting/setting values should work as normal, except that setting
values on nested views is impossible -
Specifically this doesn’t work:
my_model.array[0][0] = 1
But this does work:
my_model.array[0,0] = 1
To have direct access to the hdf5 dataset, use the
H5Proxy.open() method.
- class H5ArrayPath(file: Path | str, path: str, field: str | List[str] | None = None)[source]¶
Location specifier for arrays within an HDF5 file
Create new instance of H5ArrayPath(file, path, field)
- class H5Proxy(file: Path | str, path: str, field: str | List[str] | None = None)[source]¶
Proxy class to mimic numpy-like array behavior with an HDF5 array
The attribute and item access methods only open the file for the duration of the method, making it less perilous to share this object between threads and processes.
This class attempts to be a passthrough class to a
h5py.Datasetobject, including its attributes and item getters/setters.When using read-only methods, no locking is attempted (beyond the HDF5 defaults), but when using the write methods (setting an array value), try and use the
lockingmethods ofh5py.File.- Parameters:
- classmethod from_h5array(h5array: H5ArrayPath) H5Proxy[source]¶
Instantiate using
H5ArrayPath
- open(mode: str = 'r') Dataset[source]¶
Return the opened
h5py.DatasetobjectYou must remember to close the associated file with
close()
- class H5Interface(shape: Tuple[int, ...] | Any, dtype: str | type | Any | generic)[source]¶
Interface for Arrays stored as datasets within an HDF5 file.
Takes a
H5ArrayPathspecifier to select ah5py.Datasetfrom ah5py.Fileand returns aH5Proxyclass that acts like a passthrough numpy-like interface to the dataset.- classmethod check(array: H5ArrayPath | Tuple[Path | str, str]) bool[source]¶
Check that the given array is a
H5ArrayPathor something that resembles one.
- before_validation(array: Any) NDArrayType[source]¶
Create an
H5Proxyto use throughout validation