resqpy.olio.write_hdf5.H5Register

class resqpy.olio.write_hdf5.H5Register(model, default_chunks=None, default_compression=None)[source]

Bases: object

Class for registering arrays and then writing to an hdf5 file.

Methods:

__init__(model[, default_chunks, ...])

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).


__init__(model, default_chunks=None, default_compression=None)[source]

Create a new, empty register of arrays to be written to an hdf5 file.

register_dataset(object_uuid, group_tail, a, dtype=None, hdf5_internal_path=None, copy=False, chunks=None, compression=None)[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

  • chunks (str or tuple of ints, optional) – if not None, chunked hdf5 storage will be used; if str, options are ‘auto’, ‘all’, ‘slice’

  • compression (str, optional) – if not None, either ‘gzip’ or ‘lzf’

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; if chunks is set to a tuple, it must have the same ndim as a and the shape of a must be a mulitple of the entries in the chunks tuple, in each dimension; if chunks is ‘all’, the shape of a will be used as the tuple; if ‘auto’ then hdf5 auto chunking will be used; if ‘slice’ and a has more than one dimension, then the chunks tuple will be the shape of a with the first entry replaced with 1

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