geoh5py.io package

Submodules

geoh5py.io.h5_reader module

class geoh5py.io.h5_reader.H5Reader[source]

Bases: object

Class to read information from a geoh5 file.

classmethod fetch_array_attribute(file: str | File, uid: UUID, entity_type: str, key: str) ndarray | None[source]

Get an entity attribute stores as array such as cells.

Parameters:
  • fileh5py.File or name of the target geoh5 file

  • uid – Unique identifier of the target object.

  • entity_type – Group type to fetch entity from.

  • key – Field attribute name.

Return cells:

numpy.ndarray of int.

classmethod fetch_attributes(file: str | File, uid: UUID, entity_type: str) tuple[dict, dict, dict] | tuple[None, None, None][source]

Get attributes of an Entity.

Parameters:
  • fileh5py.File or name of the target geoh5 file

  • uid – Unique identifier

  • entity_type – Type of entity from ‘group’, ‘data’, ‘object’, ‘group_type’, ‘data_type’, ‘object_type’

Returns:
attributes: dict of attributes for the Entity
type_attributes: dict of attributes for the EntityType
property_groups: dict of data uuid.UUID
classmethod fetch_children(file: str | File, uid: UUID, entity_type: str) dict[source]

Get children of an Entity.

Parameters:
  • fileh5py.File or name of the target geoh5 file

  • uid – Unique identifier

  • entity_type – Type of entity from ‘group’, ‘data’, ‘object’, ‘group_type’, ‘data_type’, ‘object_type’

Return children:

[{uuid: type}, … ] List of dictionaries for the children uid and type

classmethod fetch_concatenated_attributes(file: str | File, uid: UUID, entity_type: str, label: str) list | dict | None[source]

Get ‘Attributes’, ‘Data’ or ‘Index’ from Concatenator group.

Parameters:
  • fileh5py.File or name of the target geoh5 file

  • uid – Unique identifier

  • entity_type – Type of entity from ‘group’, ‘data’, ‘object’, ‘group_type’, ‘data_type’, ‘object_type’

  • label – Group identifier for the attribute requested.

Return children:

[{uuid: type}, … ] List of dictionaries for the children uid and type

classmethod fetch_concatenated_values(file: str | File, uid: UUID, entity_type: str, label: str) tuple | None[source]

Get children values of concatenated group.

Parameters:
  • fileh5py.File or name of the target geoh5 file

  • uid – Unique identifier

  • entity_type – Type of entity from ‘group’, ‘data’, ‘object’, ‘group_type’, ‘data_type’, ‘object_type’

  • label – Group identifier for the attribute requested.

Return children:

[{uuid: type}, … ] List of dictionaries for the children uid and type

classmethod fetch_file_object(file: str | File, uid: UUID, file_name: str) bytes | None[source]

Load data associated with an image file

Parameters:
  • file – Name of the target geoh5 file

  • uid – Unique identifier of the target entity

  • file_name – Name of the file stored as bytes data.

Return values:

Data file stored as bytes

classmethod fetch_metadata(file: str | File, uid: UUID, entity_type: str = 'Objects', argument: str = 'Metadata') str | dict | None[source]

Fetch text of dictionary type attributes of an entity.

Parameters:
  • file – Target h5 file.

  • uid – Unique identifier of the target Entity.

  • entity_type – Base type of the target Entity.

  • argument – Label name of the dictionary.

classmethod fetch_project_attributes(file: str | File) dict[Any, Any][source]

Get attributes of an Entity.

Parameters:

fileh5py.File or name of the target geoh5 file

Return attributes:

dict of attributes.

classmethod fetch_property_groups(file: str | File, uid: UUID) dict[str, dict[str, str]][source]

Get the property groups.

Parameters:
  • fileh5py.File or name of the target geoh5 file

  • uid – Unique identifier of the target entity

Return property_group_attributes:

dict of property groups and respective attributes.

property_group = {
    "group_1": {"attribute": value, ...},
    ...,
    "group_N": {"attribute": value, ...},
}
classmethod fetch_type(file: str | File, uid: UUID, entity_type: str) dict[source]

Fetch a type from the target geoh5.

Parameters:
  • fileh5py.File or name of the target geoh5 file

  • uid – Unique identifier of the target entity

  • entity_type – One of ‘Data’, ‘Object’ or ‘Group’

Return property_group_attributes:

dict of property groups and respective attributes.

classmethod fetch_type_attributes(type_handle: Group) dict[source]

Fetch type attributes from a given h5 handle.

classmethod fetch_uuids(file: str | File, entity_type: str) list[source]

Fetch all uuids of a given type from geoh5

Parameters:
  • fileh5py.File or name of the target geoh5 file

  • entity_type – Type of entity from ‘group’, ‘data’, ‘object’, ‘group_type’, ‘data_type’, ‘object_type’

Return uuids:

[uuid1, uuid2, …] List of uuids

classmethod fetch_values(file: str | File, uid: UUID) ndarray | str | float | None[source]

Get data values

Parameters:
  • fileh5py.File or name of the target geoh5 file

  • uid – Unique identifier of the target entity

Return values:

numpy.array of float

static format_type_string(string: str) str[source]

Format names used for types.

geoh5py.io.h5_writer module

class geoh5py.io.h5_writer.H5Writer[source]

Bases: object

Writing class to a geoh5 file.

static add_or_update_property_group(file, property_group, remove=False)[source]

Update a PropertyGroup associated with an Entity.

Parameters:
  • file – Name or handle to a geoh5 file.

  • property_group – Target PropertyGroup

static clear_stats_cache(file: str | File, entity: Data) None[source]

Clear the StatsCache dataset.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target entity.

static create_dataset(entity_handle, dataset: ndarray, label: str) None[source]

Create a dataset on geoh5.

Parameters:
  • entity_handle – Pointer to a hdf5 group

  • dataset – Array of values to be written

  • label – Name of the dataset on file

static fetch_handle(file: str | File, entity, return_parent: bool = False) None | Group[source]

Get a pointer to an Entity in geoh5.

Parameters:
  • file – Name or handle to a geoh5 file

  • entity – Target Entity

  • return_parent – Option to return the handle to the parent entity.

Return entity_handle:

HDF5 pointer to an existing entity, parent or None if not found.

static init_geoh5(file: str | h5py.File, workspace: workspace.Workspace)[source]

Add the geoh5 core structure.

Parameters:
  • file – Name or handle to a geoh5 file.

  • workspaceWorkspace object defining the project structure.

Return h5file:

Pointer to a geoh5 file.

static prepare_data_to_write(h5file: File, entity: Data | Group | ObjectBase, attribute: str) tuple[Group, str] | tuple[None, None][source]

Prepare data to be written to a geoh5 file.

Parameters:
  • h5file – Name or handle to a geoh5 file.

  • entity – Entity with attributes to be added to the geoh5 file.

  • attribute – The attribute to be written to the geoh5 file.

Returns:

The entity handle, the name map, and the values to be written to the geoh5 file.

static remove_child(file: str | File, uid: UUID, ref_type: str, parent: Entity) None[source]

Remove a child from a parent.

Parameters:
  • file – Name or handle to a geoh5 file

  • uid – uuid of the target Entity

  • ref_type – Input type from: ‘Types’, ‘Groups’, ‘Objects’ or ‘Data

  • parent – Remove entity from parent.

static remove_entity(file: str | File, uid: UUID, ref_type: str, parent: Entity | None = None) None[source]

Remove an entity and its type from the target geoh5 file.

Parameters:
  • file – Name or handle to a geoh5 file

  • uid – uuid of the target Entity

  • ref_type – Input type from: ‘Types’, ‘Groups’, ‘Objects’ or ‘Data

  • parent – Remove entity from parent.

static save_entity(file: str | File, entity, compression: int = 5, add_children: bool = True) Group[source]

Save a Entity to geoh5 with its children recursively.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target Entity.

  • compression – Compression level for the data.

  • add_children – Add children.

str_type = dtype('O')
static update_concatenated_field(file: str | File, entity, attribute: str, channel: str) None[source]

Update the attributes of a concatenated Entity.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target Entity.

  • attribute – Name of the attribute to get updated.

  • channel – Name of the data or index to be modified.

static update_field(file: str | File, entity, attribute: str, compression: int = 5, **kwargs) None[source]

Update the attributes of an Entity.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target Entity.

  • attribute – Name of the attribute to get updated.

  • compression – Compression level for the data.

static write_array_attribute(file: str | File, entity, attribute, values=None, **kwargs) None[source]

Add surveys of an object.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target entity.

  • attribute – Name of the attribute to be written to geoh5

static write_attributes(file: str | File, entity) None[source]

Write attributes of an Entity.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Entity with attributes to be added to the geoh5 file.

static write_color_map(file: str | h5py.File, entity_type: shared.EntityType) None[source]

Add ColorMap to a DataType.

Parameters:
  • file – Name or handle to a geoh5 file

  • entity_type – Target entity_type with color_map

static write_data_map(file: str | File, data: ReferencedData)[source]

Write the value map of geometric data.

Parameters:
  • file – Name or handle to a geoh5 file

  • data – Target referenced data with value map

static write_data_values(file: str | File, entity: Data, attribute, compression: int, **kwargs) None[source]

Add data values.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target entity.

  • attribute – Name of the attribute to be written to geoh5

  • compression – Compression level for the data.

static write_entity(file: str | File, entity, compression: int) Group[source]

Add an Entity and its attributes to geoh5. The function returns a pointer to the entity if already present on file.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target Entity.

  • compression – Compression level for data.

Return entity:

Pointer to the written entity. Active link if “close_file” is False.

static write_entity_type(file: str | h5py.File, entity_type: shared.EntityType | ReferenceDataType) h5py.Group[source]

Add an EntityType to geoh5.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity_type – Entity with type to be added.

Return type:

Pointer to EntityType in geoh5.

static write_file_name_data(entity_handle: Group, entity: FilenameData) None[source]

Write a dataset for the file name and file blob.

Parameters:
  • entity_handle – Pointer to the geoh5 Group.

  • entity – Target FilenameData entity.

  • values – Bytes data

static write_group_values(file: str | File, entity: Group, attribute, compression: int, values=None, **kwargs)[source]

Add Concatenator values.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target entity.

  • attribute – Name of the attribute to be written to geoh5

  • compression – Compression level for the data.

  • values – Data values.

static write_metadata(file: str | File, entity: Group | ObjectBase, attribute, values=None, **kwargs) None[source]

Add data values.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target entity.

  • attribute – Name of the attribute to be written to geoh5

  • values – Data values.

static write_properties(file: str | File, entity: Entity, compression: int) None[source]

Add properties of an Entity.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target Entity.

  • compression – Compression level for data.

static write_property_groups(file: str | File, entity) None[source]

Write PropertyGroup associated with an Entity.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Target Entity.

static write_to_parent(file: str | File, entity: Entity, compression: int, recursively: bool = False) None[source]

Add/create an Entity and add it to its parent.

Parameters:
  • file – Name or handle to a geoh5 file.

  • entity – Entity to be added or linked to a parent in geoh5.

  • compression – Compression level for data.

  • recursively – Add parents recursively until reaching the RootGroup.

static write_value_map(file: str | File, entity_type: ReferenceDataType, name='Value map', value_map: ReferenceValueMap | None = None) None[source]

Add ReferenceValueMap to a DataType.

Parameters:
  • file – Name or handle to a geoh5 file

  • entity_type – Target entity_type with value_map

  • name – Name of the value map

  • value_map – Value map to be written

static write_visible(file: str | File, entity) None[source]

Needs revision once Visualization is implemented

Parameters:
  • file – Name or handle to a geoh5 file

  • entity – Target entity

geoh5py.io.utils module

geoh5py.io.utils.str_from_subtype(entity_type: EntityType) str[source]

Convert sub entity type to geoh5 string standard.

Parameters:

entity_type – Sub-class of entity type.

Returns:

String equivalent.

geoh5py.io.utils.str_from_type(entity: Entity | PropertyGroup | EntityType) str[source]

Convert entity type to geoh5 string standard.

Parameters:

entity – Entity, PropertyGroup or EntityType

Returns:

String equivalent.

Module contents