bamboost.core.hdf5.ref
This module provides a high-level abstraction for working with HDF5 (h5py) groups and
datasets. It is built on the concept of describing an object in the file with a reference
to it (deterministic reference: a file instance, and a path inside the HDF file).
The reference handles file opening and closing, and provides a simple interface to
data, attributes and subgroups. In essence, this model provides h5py objects like any
other in-memory data structure.
Attributes
- log=
BAMBOOST_LOGGER.getChild('hdf5') - _RT_group=
TypeVar('_RT_group', bound=(Union['Group', 'Dataset'])) - _g=
bamboost.core.hdf5.ref.Group - _d=
bamboost.core.hdf5.ref.Dataset
Classes
RefStatus
Attributes:
- INVALID=
0 - VALID=
1 - NOT_CHECKED=
2
H5Reference
(self, path, file)Arguments:
- path:
str - file:
HDF5File[bamboost._typing._MT]
Attributes:
Bases
(self, key)Arguments:
- key
(self) -> str(cls, path, file, _type=None) -> _RT_group(self)Group
(self, path, file)Arguments:
- path:
str - file:
HDF5File[bamboost._typing._MT]
Attributes:
- _group_map=
FilteredFileMap(file.file_map, path) - _status=
RefStatus(_valid) - _obj:
h5py.h5py.Group
Bases
(self)(self, key) -> boolArguments:
- key:
str
(self, key) -> NoneDeletes an item.
Arguments:
- key
(self, key, newvalue)Used to set an attribute. Will be written as an attribute to the group.
Arguments:
- key
- newvalue
(self)(self)(self)(self, *, filter=None) -> Generator[Tuple[str, Union[Group[_MT], Dataset[_MT]]], None, None]Arguments:
- filter:
typing.Optional[typing.Literal['groups', 'datasets']]=None
(self) -> None(self, name, *, return_type=None)(self, name, shape, dtype, exact=False, **kwargs) -> h5py.DatasetEnsure a dataset exists under the given name with the specified shape/dtype.
Arguments:
- name:
str - shape:
tuple[int, ...] - dtype
- exact:
bool=False - kwargs=
{}
(self, name, vector, indices=None, attrs=None, dtype=None, *, file_map=True) -> NoneAdd or overwrite a dataset.
Arguments:
- name:
strName for the dataset
- vector:
ArrayLikeData array to write
- indices:
numpy.typing.NDArray[numpy.numpy.int_] | None=NoneOptional. 1D array of global row indices where local data should be written. If None, data is assumed to be contiguous and will be written as such.
- attrs:
typing.Optional[typing.Dict[str, typing.Any]]=NoneOptional. Attributes of dataset.
- dtype:
typing.Optional[str]=NoneOptional. dtype of dataset.
- file_map:
bool=True
(self, name, vector, attrs=None, dtype=None, *, file_map=True) -> NoneAdd a dataset to the group. Error is thrown if attempting to overwrite with different shape than before. If same shape, data is overwritten (this is inherited from h5py -> require_dataset)
Arguments:
- name:
strName for the dataset
- vector:
ArrayLikeData to write (max 2d)
- attrs:
typing.Optional[typing.Dict[str, typing.Any]]=NoneOptional. Attributes of dataset.
- dtype:
typing.Optional[str]=NoneOptional. dtype of dataset. If not specified, uses dtype of input array
- file_map:
bool=TrueOptional. If True, the dataset is added to the file map. Default is True.
(self, *args, **kwargs)Arguments:
- args=
() - kwargs=
{}
(self, name, indices, vector, attrs=None, dtype=None, *, file_map=True) -> NoneAdd or overwrite a dataset using non-contiguous global indices (DOF map).
Arguments:
- name:
strName for the dataset
- indices:
ArrayLike1D array of global row indices where local data should be written
- vector:
ArrayLikeData array to write
- attrs:
typing.Optional[typing.Dict[str, typing.Any]]=NoneOptional. Attributes of dataset.
- dtype:
typing.Optional[str]=NoneOptional. dtype of dataset.
- file_map:
bool=TrueOptional. If True, the dataset is added to the file map.
(self, name, data, attrs=None, dtype=None) -> NoneAdd a dataset to the group. Error is thrown if attempting to overwrite.
Arguments:
- name:
strName for the dataset
- data:
typing.AnyData to write
- attrs:
typing.Optional[typing.Dict[str, typing.Any]]=NoneOptional. Attributes of dataset.
- dtype:
typing.Optional[str]=NoneOptional. dtype of dataset. If not specified, uses dtype of input data
Note
This method is non-collective and does not require communication. The data is written only by the root process (rank 0), and other processes do not need to call this method.
(self)(self)Repr showing the content of the group.
Dataset
Attributes:
- _obj:
h5py.h5py.Dataset - shape:
tuple[int, ...] - dtype
- array:
numpy.numpy.ndarray
Bases
(self, key) -> AnyArguments:
- key:
tuple | slice | int
Bamboost