resqpy.olio.write_hdf5.H5Register¶
- class resqpy.olio.write_hdf5.H5Register(model)[source]¶
Bases:
object
Class for registering arrays and then writing to an hdf5 file.
Methods:
__init__
(model)Create a new, empty register of arrays to be written to an hdf5 file.
register_dataset
(object_uuid, group_tail, a)Register an array to be included as a dataset in the hdf5 file.
write_fp
(fp[, use_int32])Write or append to an hdf5 file, writing the pre-registered datasets (arrays).
write
([file, mode, release_after, use_int32])Create or append to an hdf5 file, writing the pre-registered datasets (arrays).
- register_dataset(object_uuid, group_tail, a, dtype=None, hdf5_internal_path=None, copy=False)[source]¶
Register an array to be included as a dataset in the hdf5 file.
- Parameters
object_uuid (uuid.UUID) – the uuid of the object (part) that this array is for
group_tail (string) – the remainder of the hdf5 internal path (following RESQML and uuid elements)
a (numpy array) – the dataset (array) to be registered for writing
dtype (type or string) – the required type of the individual elements within the dataset; special value of ‘pack’ may be used to cause a bool array to be packed before writing
hdf5_internal_path (string, optional) – if present, a full hdf5 internal path to use instead of the default generated from the uuid
copy (boolean, default False) – if True, a copy of the array will be made at the time of registering, otherwise changes made to the array before the write() method is called are likely to be in the data that is written
- Returns
None
Notes
several arrays might belong to the same object; if a dtype is given and necessitates a conversion of the array data, the behaviour will be as if the copy argument is True regardless of its setting; the use of ‘pack’ as dtype will result in hdf5 data that will not generally be readable by non-resqpy applications; when reading packed data, the required shape must be specified; packing only takes place over the last axis; do not use packing if the array needs to be read or updated in slices, or read a single value at a time with index values
- write_fp(fp, use_int32=None)[source]¶
Write or append to an hdf5 file, writing the pre-registered datasets (arrays).
- Parameters
fp – an already open h5py._hl.files.File object
- Returns
None
Note
the file handle fp must have been opened with mode ‘w’ or ‘a’
- write(file=None, mode='w', release_after=True, use_int32=None)[source]¶
Create or append to an hdf5 file, writing the pre-registered datasets (arrays).
- Parameters
file – either a string being the file path, or an already open h5py._hl.files.File object; if None (recommended), the file is opened through the model object’s hdf5 management functions
mode (string, default 'w') – the mode to open the file in; only relevant if file is a path; must be ‘w’ or ‘a’ for (over)write or append
release_after (bool, default True) – if True, h5_release() is called after the write
use_int32 (bool, optional) – if True, int64 arrays will be written as int32; if None, global default will be used (currently True); if False, int64 arrays will be written as such
- Returns
None