Heirarchical Data Format (HDF)

geobipy.src.base.HDF.hdfRead.find(filename, tag)

Find the locations of all groups with ‘tag’ in their path.

Parameters:
  • filename (str) – HDF5 file name

  • tag (str) – Sub string that appears in the group name.

Returns:

out – List of paths into the HDF5 file.

Return type:

list

geobipy.src.base.HDF.hdfRead.readKeyFromFile(h5obj, fName, groupName, key, index=None, **kwargs)

Reads in the keys from a file

Iterates over group names and keys and reads them from a HDF5 file

Parameters:
  • h5obj (h5py._hl.files.File or h5py._hl.group.Group) – An opened hdf5 handle or a h5py group object

  • fName (str) – The path and/or file name to the file that was opened

  • groupName (str or list of str) – The group(s) path within the hdf5 file to read from. i.e. ‘/group1/group1a’

  • key (str or list of str) – The key(s) in the group to read

  • index (slice, optional) – Specifies the index’th entry of the data to return. If the group was created using a createHDF procedure in parallel with the nRepeats option, index specifies the index’th entry from which to read the data.

  • necessary. (Any other parameters in **kwargs are optional but may be necessary if an object's .fromHDF() procedure requires extra arguments. Refer to the object you wish to read in to determine whether extra arguments are) –

Returns:

out – Returns the read in entries as a list if there are multiple or as a single object if there is only one.

Return type:

object or list

geobipy.src.base.HDF.hdfRead.readKeyFromFiles(fNames, groupName, key, index=None, **kwargs)

Reads in the keys from multiple files

Iterates over filenames, group names, and keys and reads them from a HDF5 file

Parameters:
  • fNames (str or list of str) – The path(s) and/or file name(s)

  • groupName (str or list of str) – The group(s) path within the hdf5 file(s) to read from. i.e. ‘/group1/group1a’

  • key (str or list of str) – The key(s) in the group to read

  • index (slice, optional) – Specifies the index’th entry of the data to return. If the group was created using a createHDF procedure in parallel with the nRepeats option, index specifies the index’th entry from which to read the data.

  • necessary. (Any other parameters in **kwargs are optional but may be necessary if an object's .fromHDF() procedure requires extra arguments. Refer to the object you wish to read in to determine whether extra arguments are) –

Returns:

out – Returns the read in entries as a list if there are multiple or as a single object if there is only one.

Return type:

object or list

geobipy.src.base.HDF.hdfRead.read_all(fName)

Reads all the entries written to a HDF file

Iterates through the highest set of keys in the hdf5 file, and reads each one to a list. If each entry has an attached .readHdf procedure, that will be used to read in an object (Those objects imported at the top of this file can be successfully read in using this attached procedure.) If an entry is a numpy array, that will be the return type. This function will read in the entire file! Use this with caution if you are using large files.

Parameters:

fName (str) – A path and/or file name.

Returns:

out – A list of the read in items from the hdf5 file.

Return type:

list

geobipy.src.base.HDF.hdfRead.read_groups_with_tag(filename, tag, index=None, **kwargs)

Reads all groups with ‘tag’ in their path into memory.

Parameters:
  • filename (str) – HDF5 file name

  • tag (str) – Sub string that appears in the group name.

Returns:

out – List of geobipy classes.

Return type:

list

geobipy.src.base.HDF.hdfRead.read_item(h5obj, index=None, **kwargs)

Read an object from a HDF file

This function provides a flexible way to read in either a numpy hdf5 entry, or an object in this package. The objects in this package may have an attached .createHdf and writeHdf procedure. If so, this function will read in those objects and return that object. If the entry is instead a numpy array, a numpy array will be returned.

Parameters:
  • hObj (h5py._hl.dataset.Dataset or h5py._hl.group.Group) – A h5py object from which to read entries.

  • index (slice, optional) – Specifies the index’th entry of the data to return. If the group was created using a createHDF procedure in parallel with the nRepeats option, index specifies the index’th entry from which to read the data.

  • necessary. (Any other parameters in **kwargs are optional but may be necessary if an object's .fromHDF() procedure requires extra arguments. Refer to the object you wish to read in to determine whether extra arguments are) –

Returns:

out – An object that has a .fromHdf() procedure or a numpy array of the returned variable.

Return type:

object or numpy.ndarray

geobipy.src.base.HDF.hdfWrite.write_nd(arr, h5obj, myName, index=None)

Writes a numpy array to a preallocated dataset in a h5py group object

Parameters:
  • h5obj (h5py._hl.files.File or h5py._hl.group.Group) – A HDF file or group object to write the contents to. The dataset must have already been allocated in the file.

  • myName (str) – The name of the h5py dataset key inside the h5py object. e.g. ‘/group1/group1a/dataset’

  • index (slice, optional) – Specifies the index’th entry of the data to return. If the group was created using a createHDF procedure in parallel with the nRepeats option, index specifies the index’th entry from which to read the data.