geoh5py.io¶
geoh5py.io.h5_reader¶
- 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:
file –
h5py.File
or name of the target geoh5 fileuid – Unique identifier of the target object.
entity_type – Group type to fetch entity from.
key – Field attribute name.
- Return cells:
numpy.ndarray
ofint
.
- classmethod fetch_attributes(file: str | File, uid: UUID, entity_type: str) tuple[dict, dict, dict] | None [source]¶
Get attributes of an
Entity
.- Parameters:
file –
h5py.File
or name of the target geoh5 fileuid – Unique identifier
entity_type – Type of entity from ‘group’, ‘data’, ‘object’, ‘group_type’, ‘data_type’, ‘object_type’
- Returns:
- attributes:
dict
of attributes for theEntity
- type_attributes:
dict
of attributes for theEntityType
- property_groups:
dict
of datauuid.UUID
- attributes:
- classmethod fetch_children(file: str | File, uid: UUID, entity_type: str) dict [source]¶
Get
children
of anEntity
.- Parameters:
file –
h5py.File
or name of the target geoh5 fileuid – 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:
file –
h5py.File
or name of the target geoh5 fileuid – 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:
file –
h5py.File
or name of the target geoh5 fileuid – 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:
file –
h5py.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:
file –
h5py.File
or name of the target geoh5 fileuid – 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:
file –
h5py.File
or name of the target geoh5 fileuid – 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:
file –
h5py.File
or name of the target geoh5 fileentity_type – Type of entity from ‘group’, ‘data’, ‘object’, ‘group_type’, ‘data_type’, ‘object_type’
- Return uuids:
[uuid1, uuid2, …] List of uuids
- classmethod fetch_value_map(h5_handle: Group) dict [source]¶
Get data
value_map
- Parameters:
h5_handle – Handle to the target h5 group.
- Return value_map:
dict
of {int
:str
}
geoh5py.io.h5_writer¶
- class geoh5py.io.h5_writer.H5Writer[source]¶
Bases:
object
Writing class to a geoh5 file.
- classmethod add_or_update_property_group(file, property_group, remove=False)[source]¶
Update a
PropertyGroup
associated with anEntity
.- Parameters:
file – Name or handle to a geoh5 file.
property_group – Target PropertyGroup
- classmethod 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.
- classmethod 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
- classmethod 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.
- classmethod init_geoh5(file: str | h5py.File, workspace: workspace.Workspace)[source]¶
Add the geoh5 core structure.
- Parameters:
file – Name or handle to a geoh5 file.
workspace –
Workspace
object defining the project structure.
- Return h5file:
Pointer to a 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.
- classmethod save_entity(file: str | File, entity, compression: int = 5, add_children: bool = True) Group [source]¶
Save a
Entity
to geoh5 with itschildren
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')¶
- classmethod 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.
- classmethod 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.
- classmethod 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
- classmethod 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.
- classmethod write_color_map(file: str | h5py.File, entity_type: shared.EntityType) None [source]¶
-
- Parameters:
file – Name or handle to a geoh5 file
entity_type – Target entity_type with color_map
- classmethod write_data_values(file: str | File, entity, attribute, compression: int, 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
compression – Compression level for the data.
values – Data values.
- classmethod 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.
- classmethod write_entity_type(file: str | h5py.File, entity_type: shared.EntityType) 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.
- classmethod write_file_name_data(entity_handle: Group, entity: FilenameData, values: bytes) 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
- classmethod 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.
- classmethod write_property_groups(file: str | File, entity) None [source]¶
Write
PropertyGroup
associated with anEntity
.- Parameters:
file – Name or handle to a geoh5 file.
entity – Target
Entity
.
- classmethod 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
.
- classmethod write_value_map(file: str | h5py.File, entity_type: shared.EntityType) None [source]¶
Add
ReferenceValueMap
to aDataType
.- Parameters:
file – Name or handle to a geoh5 file
entity_type – Target entity_type with value_map