odpy.hdf5

Copyright (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
  • AUTHOR : A. Huck

  • DATE : Nov 2018

Module Summary

Tools for reading hdf5 files created by OpendTect. Ensures standard access to hdf5 for independent workflow

KEY methods

  • openFile()

    • opens any h5 or hdf5 files, ensures and optimize access to the file

Example

>>> import odpy.hdf5 as odhdf
>>> file =odhdf.openFile(filenm='DTECT_DATA/F3_Demo_2020/NLAs/3D_seismic_energy.h5', mode='r')
>>> file
    <HDF5 file "3D_seismic_energy.h5" (mode r)>
>>> info = odhdf.getInfoDataSet(h5file_or_grp=file)
>>> info
    <HDF5 dataset "++info++": shape (1,), type "|S1">

Module Contents

Functions

openFile(filenm, mode)

Opens and ensures and optimize access to the hdf5 file

getInfoDataSet(h5file_or_grp)

Gets info on HDF5 object

ensureHasDataset(h5file_or_grp)

Ensures HDF5 object has info file (++info++) created by OpendTect

getAttr(dataset, ky)

Gets attribute value from HDF5 Dataset

setAttr(dataset, ky, str)

Sets HDF5 dataset attribute

hasAttr(dataset, ky)

Checks if HDF5 object has attribute

getAttrs(dataset, ky)

Gets attribute value(s) from HDF5 dataset

getText(infos, ky)

Gets attribute text value from HDF5 dataset

setArray(infos, ky, arr)

Sets array values for dataset attribute

getBoolValue(infos, ky)

Gets boolean value

getIArray_(valsstr)

Provides integer equivalence of input. Converts input or element of input into integers

getIntValue(infos, ky)

Gets integer value of attribute

getIInterval(infos, ky)

Gets interval int values of attribute

getIStepInterval(infos, ky)

Gets interval step int values of attribute

getIArray(infos, ky)

Gets array int values of attribute

getDArray_(valsstr)

Provides float equivalence of input. Converts input or element of input into floats

getDValue(infos, ky)

Gets float value of attribute

getDInterval(infos, ky)

Gets interval float values of attribute

getDStepInterval(infos, ky)

Gets float interval step values of attribute

getDArray(infos, ky)

Gets array float values of attribute

getAttribInfo(filenm)

getTransform(info)

getSurveyInfo(filenm)

Gets survey information

Attributes

dGBInfoDSName

odpy.hdf5.dGBInfoDSName = ++info++
odpy.hdf5.openFile(filenm, mode)

Opens and ensures and optimize access to the hdf5 file

Parameters:
  • filenm (str): HDF5 file name

  • mode (str): options to read, write or edit to the file (r, r+, w, w-, x, a)

Returns:
  • obj: A HDF5 file object (in mode selected)

odpy.hdf5.getInfoDataSet(h5file_or_grp)

Gets info on HDF5 object

Parameters:
  • h5file_or_grp (object): hdf5 file object

Returns:
  • obj: A h5 dataset object created by OpendTect,

    Input error is generated if HDF5 file is not created by OpendTect

Notes:
  • KeyError (HDF5 key not found) is returned if dataset has no attribute passed

odpy.hdf5.ensureHasDataset(h5file_or_grp)

Ensures HDF5 object has info file (++info++) created by OpendTect

Parameters:
  • h5file_or_grp (obj): HDF5 file object

Returns:
  • obj: A h5 dataset object created by OpendTect

odpy.hdf5.getAttr(dataset, ky)

Gets attribute value from HDF5 Dataset

Parameters:
  • dataset (obj): HDF5 file object

  • ky (str): HDF5 attribute name

Returns:

bytes: Attribute value

Notes:
  • KeyError (HDF5 key not found) is returned if dataset has no attribute passed

odpy.hdf5.setAttr(dataset, ky, str)

Sets HDF5 dataset attribute

Parameters:
  • dataset (obj): HDF5 file object

  • ky (str): attribute name

  • str (str): attribute value

Returns:
  • Nothing (sets dataset attribute)

odpy.hdf5.hasAttr(dataset, ky)

Checks if HDF5 object has attribute

Parameters:
  • dataset (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • bool: True if attribute is present, False if otherwise

odpy.hdf5.getAttrs(dataset, ky)

Gets attribute value(s) from HDF5 dataset

Parameters:
  • dataset (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • list: of atrribute value(s)

Notes:
  • KeyError (HDF5 key not found) is returned if dataset has no attribute passed List of available attributes is displayed

odpy.hdf5.getText(infos, ky)

Gets attribute text value from HDF5 dataset

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • str: attribute value

odpy.hdf5.setArray(infos, ky, arr)

Sets array values for dataset attribute

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

  • arr (list, tup, int, float, str): attribute value(s)

Returns:
  • Nothing (sets dataset attribute value(s))

odpy.hdf5.getBoolValue(infos, ky)

Gets boolean value

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:

bool: True if attribute key evaluates to ‘Yes’, False if otherwise

odpy.hdf5.getIArray_(valsstr)

Provides integer equivalence of input. Converts input or element of input into integers

Parameters:
  • valsstr (int, float, list of int/float)

Returns:
  • int, list of int

odpy.hdf5.getIntValue(infos, ky)

Gets integer value of attribute

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • int: attribute value

Notes:
  • Returns ValueError if attribute value is text

odpy.hdf5.getIInterval(infos, ky)

Gets interval int values of attribute

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • list: interval int values

Notes:
  • Returns ValueError if attribute value is text

odpy.hdf5.getIStepInterval(infos, ky)

Gets interval step int values of attribute

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • tuple: interval step int values

Notes:
  • Returns ValueError if attribute value is text

odpy.hdf5.getIArray(infos, ky)

Gets array int values of attribute

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • list: attribute int values

Notes:
  • Returns ValueError if attribute value is text

odpy.hdf5.getDArray_(valsstr)

Provides float equivalence of input. Converts input or element of input into floats

Parameters:
  • valsstr (int, float, list of int/float)

Returns:
  • float, list of float

odpy.hdf5.getDValue(infos, ky)

Gets float value of attribute

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • float: attribute value

Notes:
  • Returns ValueError if attribute value is text

odpy.hdf5.getDInterval(infos, ky)

Gets interval float values of attribute

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • list: interval float values

Notes:
  • Returns ValueError if attribute value is text

odpy.hdf5.getDStepInterval(infos, ky)

Gets float interval step values of attribute

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • tuple: interval step float values

Notes:
  • Returns ValueError if attribute value is text

odpy.hdf5.getDArray(infos, ky)

Gets array float values of attribute

Parameters:
  • infos (obj): HDF5 file object

  • ky (str): attribute name

Returns:
  • list: attribute float values

Notes:
  • Returns ValueError if attribute value is text

odpy.hdf5.getAttribInfo(filenm)
odpy.hdf5.getTransform(info)
odpy.hdf5.getSurveyInfo(filenm)

Gets survey information

Parameters:
  • filenm (str): file name

Returns:
  • orderedDict: containing information on survey name, survey ranges (inline, crossline, x, y), transform