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)

Write or append to an hdf5 file, writing the pre-registered datasets (arrays).

write([file, mode, release_after])

Create or append to an hdf5 file, writing the pre-registered datasets (arrays).


__init__(model)[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_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

  • hdf5_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

write_fp(fp)[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)[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

Returns:

None