geoh5py.shared¶
geoh5py.shared.concatenation¶
- class geoh5py.shared.concatenation.Concatenated(entity_type, **kwargs)[source]¶
Bases:
Entity
Base class modifier for concatenated objects and data.
- property concat_attr_str: str¶
String identifier for the concatenated attributes.
- property concatenator: Concatenator¶
Parental Concatenator entity.
- class geoh5py.shared.concatenation.ConcatenatedData(entity_type, **kwargs)[source]¶
Bases:
Concatenated
- property parent: ConcatenatedObject¶
- property property_group¶
Get the property group containing the data interval.
- class geoh5py.shared.concatenation.ConcatenatedDrillhole(entity_type, **kwargs)[source]¶
Bases:
ConcatenatedObject
- validate_data(attributes: dict, property_group=None, collocation_distance=None) → tuple[source]¶
Validate input drillhole data attributes.
- Parameters
attributes – Dictionary of data attributes.
property_group – Input property group to validate against.
- validate_interval_data(name: str | None, from_to: list | np.ndarray | None, values: np.ndarray, property_group: str | ConcatenatedPropertyGroup | None = None, collocation_distance=0.0001) → ConcatenatedPropertyGroup[source]¶
Compare new and current depth values and re-use the property group if possible. Otherwise a new property group is added.
- Parameters
from_to – Array of from-to values.
values – Data values to be added on the from-to intervals.
property_group – Property group name
- Collocation_distance
Threshold on the comparison between existing depth values.
- class geoh5py.shared.concatenation.ConcatenatedObject(entity_type, **kwargs)[source]¶
Bases:
Concatenated
,ObjectBase
- find_or_create_property_group(**kwargs) → ConcatenatedPropertyGroup[source]¶
Find or create
PropertyGroup
from given name and properties.- Parameters
kwargs – Any arguments taken by the
PropertyGroup
class.- Returns
A new or existing
PropertyGroup
- get_data(name: str | uuid.UUID) → list[Data][source]¶
Generic function to get data values from object.
- property parent: Concatenator¶
- property property_groups: list | None¶
List of
PropertyGroup
.
- class geoh5py.shared.concatenation.ConcatenatedPropertyGroup(parent: ConcatenatedObject, **kwargs)[source]¶
Bases:
PropertyGroup
- property from_¶
Return the data entities definind the ‘from’ depth intervals.
- property parent¶
The parent
ObjectBase
- property to_¶
Return the data entities definind the ‘to’ depth intervals.
- class geoh5py.shared.concatenation.Concatenator(group_type: GroupType, **kwargs)[source]¶
Bases:
Group
Class modifier for concatenation of objects and data.
- add_save_concatenated(child) → None[source]¶
Add or save a concatenated entity.
- Parameters
child – Concatenated entity
- property attributes_keys: list | None¶
List of uuids present in the concatenated attributes.
- property concat_attr_str: str¶
String identifier for the concatenated attributes.
- property concatenated_attributes: dict | None¶
Dictionary of concatenated objects and data attributes.
- property concatenated_object_ids: list[bytes] | None¶
Dictionary of concatenated objects and data concatenated_object_ids.
- copy(parent=None, copy_children: bool = True, **kwargs)[source]¶
Function to copy an entity to a different parent entity.
- Parameters
parent – Target parent to copy the entity under. Copied to current
parent
if None.copy_children – Create copies of all children entities along with it.
- Return entity
Registered Entity to the workspace.
- property data: dict¶
Concatenated data values stored as a dictionary.
- fetch_index(entity: Concatenated, field: str) → int | None[source]¶
Fetch the array index for specific concatenated object and data field.
- Parameters
entity – Parent entity with data
field – Name of the target data.
- fetch_start_index(entity: Concatenated, label: str) → int[source]¶
Fetch starting index for a given entity and label. Existing date is removed such that new entries can be appended.
- Parameters
entity – Concatenated entity to be added.
label – Name of the attribute requiring an update.
- fetch_values(entity: Concatenated, field: str) → np.ndarray | None[source]¶
Get an array of values from concatenated data.
- Parameters
entity – Parent entity with data
field – Name of the target data.
- get_concatenated_attributes(uid: bytes | str | uuid.UUID) → dict[source]¶
Fast reference index to concatenated attribute keys.
- property index: dict¶
Concatenated index stored as a dictionary.
- property property_group_ids: list | None¶
Dictionary of concatenated objects and data property_group_ids.
- remove_entity(entity: Concatenated)[source]¶
Remove a concatenated entity.
- save_attribute(field: str)[source]¶
Save a concatenated attribute.
- Parameters
field – Name of the attribute
- update_array_attribute(entity: Concatenated, field: str, remove=False) → None[source]¶
Update values stored as data. Row data and indices are first remove then appended.
- Parameters
entity – Concatenated entity with array values.
field – Name of the valued field.
- update_attributes(entity: Concatenated, label: str) → None[source]¶
Update a concatenated entity.
- update_concatenated_attributes(entity: Concatenated) → None[source]¶
Update the concatenated attributes. :param entity: Concatenated entity with attributes.
geoh5py.shared.entity¶
- class geoh5py.shared.entity.Entity(uid: uuid.UUID | None = None, name='Entity', **kwargs)[source]¶
Bases:
ABC
Base Entity class
- add_children(children: list[shared.Entity])[source]¶
- Parameters
children – Add a list of entities as
children
- add_file(file: str)[source]¶
Add a file to the object or group stored as bytes on a FilenameData
- Parameters
file – File name with path to import.
- property allow_delete: bool¶
bool
Entity can be deleted from the workspace.
- property allow_rename: bool¶
bool
Entity can change name
- property attribute_map: dict¶
dict
Correspondence map between property names used in geoh5py and geoh5.
- property children¶
list
Children entities in the workspace tree
- property clipping_ids: list[uuid.UUID] | None¶
List of clipping uuids
- copy(parent=None, copy_children: bool = True, **kwargs)[source]¶
Function to copy an entity to a different parent entity.
- Parameters
parent – Target parent to copy the entity under. Copied to current
parent
if None.copy_children – (Optional) Create copies of all children entities along with it.
kwargs – Additional keyword arguments to pass to the copy constructor.
- Return entity
Registered Entity to the workspace.
- classmethod create(workspace, **kwargs)[source]¶
Function to create an entity.
- Parameters
workspace – Workspace to be added to.
kwargs – List of keyword arguments defining the properties of a class.
- Return entity
Registered Entity to the workspace.
- abstract property entity_type: shared.EntityType¶
- classmethod fix_up_name(name: str) → str[source]¶
If the given name is not a valid one, transforms it to make it valid :return: a valid name built from the given name. It simply returns the given name if it was already valid.
- get_entity(name: str | uuid.UUID) → list[Entity][source]¶
Get a child
Data
by name.- Parameters
name – Name of the target child data
entity_type – Sub-select entities based on type.
- Returns
A list of children Data objects
- get_entity_list(entity_type=<class 'abc.ABC'>) → list[str][source]¶
Get a list of names of all children
Data
.- Parameters
entity_type – Option to sub-select based on type.
- Returns
List of names of data associated with the object.
- property metadata: dict | None¶
Metadata attached to the entity.
- property name: str¶
str
Name of the entity
- property parent¶
- property partially_hidden: bool¶
Whether this Entity is partially hidden.
- property public: bool¶
- Whether this Entity is accessible in the workspace tree and other parts
of the the user interface in ANALYST.
- reference_to_uid(value: Entity | str | uuid.UUID) → list[uuid.UUID][source]¶
General entity reference translation.
- Parameters
value – Either an Entity, string or uuid
- Returns
List of unique identifier associated with the input reference.
- remove_children(children: list[shared.Entity])[source]¶
Remove children from the list of children entities.
- Parameters
children – List of entities
Warning
Removing a child entity without re-assigning it to a different parent may cause it to become inactive. Inactive entities are removed from the workspace by
remove_none_referents()
.
- remove_data_from_group(data: list | Entity | uuid.UUID | str, name: str | None = None) → None[source]¶
Remove data children to a
PropertyGroup
All given data must be children of the parent object.- Parameters
name – Name of a
PropertyGroup
. A new group is created if none exist with the given name.
- save(add_children: bool = True)[source]¶
Alias method of
save_entity()
.- Parameters
add_children – Option to also save the children.
- property uid: UUID¶
- property visible: bool¶
Whether the Entity is visible in camera (checked in ANALYST object tree).
geoh5py.shared.entity_type¶
- class geoh5py.shared.entity_type.EntityType(workspace: ws.Workspace, uid: uuid.UUID | None = None, **kwargs)[source]¶
Bases:
ABC
- property attribute_map¶
dict
Correspondence map between property names used in geoh5py and geoh5.
- property description: str | None¶
- classmethod find(workspace: ws.Workspace, type_uid: uuid.UUID) → EntityTypeT | None[source]¶
Finds in the given Workspace the EntityType with the given UUID for this specific EntityType implementation class.
- Returns
EntityType of None
- property name: str | None¶
- property uid: UUID¶
uuid.UUID
The unique identifier of an entity, either as stored in geoh5 or generated inuuid4()
format.
geoh5py.shared.exceptions¶
- exception geoh5py.shared.exceptions.AssociationValidationError(name: str, value: Entity | PropertyGroup | UUID, validation: Entity | Workspace)[source]¶
Bases:
BaseValidationError
Error on association between child and parent entity validation.
- exception geoh5py.shared.exceptions.AtLeastOneValidationError(name: str, value: list[str])[source]¶
Bases:
BaseValidationError
- exception geoh5py.shared.exceptions.BaseValidationError[source]¶
Bases:
ABC
,Exception
Base class for custom exceptions.
- exception geoh5py.shared.exceptions.Geoh5FileClosedError[source]¶
Bases:
ABC
,Exception
Error for closed geoh5 file.
- exception geoh5py.shared.exceptions.JSONParameterValidationError(name: str, err: str)[source]¶
Bases:
Exception
Error on uuid validation.
- exception geoh5py.shared.exceptions.OptionalValidationError(name: str, value: Any | None, validation: bool)[source]¶
Bases:
BaseValidationError
Error if None value provided to non-optional parameter.
- exception geoh5py.shared.exceptions.PropertyGroupValidationError(name: str, value: PropertyGroup, validation: str)[source]¶
Bases:
BaseValidationError
Error on property group validation.
- exception geoh5py.shared.exceptions.RequiredValidationError(name: str)[source]¶
Bases:
BaseValidationError
- exception geoh5py.shared.exceptions.ShapeValidationError(name: str, value: tuple[int], validation: tuple[int] | str)[source]¶
Bases:
BaseValidationError
Error on shape validation.
- exception geoh5py.shared.exceptions.TypeValidationError(name: str, value: str, validation: str | list[str])[source]¶
Bases:
BaseValidationError
Error on type validation.
- exception geoh5py.shared.exceptions.UUIDValidationError(name: str, value: str)[source]¶
Bases:
BaseValidationError
Error on uuid string validation.
- exception geoh5py.shared.exceptions.ValueValidationError(name: str, value: Any, validation: list[Any])[source]¶
Bases:
BaseValidationError
Error on value validation.
geoh5py.shared.utils¶
- geoh5py.shared.utils.as_str_if_uuid(value: UUID | Any) → str | Any[source]¶
Convert
UUID
to string used in geoh5.
- geoh5py.shared.utils.compare_entities(object_a, object_b, ignore: list | None = None, decimal: int = 6) → None[source]¶
- geoh5py.shared.utils.dict_mapper(val, string_funcs: list[Callable], *args, omit: dict | None = None) → dict[source]¶
Recursion through nested dictionaries and applies mapping functions to values.
- Parameters
val – Value (could be another dictionary) to apply transform functions.
string_funcs – Functions to apply on values within the input dictionary.
omit – Dictionary of functions to omit.
- Return val
Transformed values
- geoh5py.shared.utils.fetch_active_workspace(workspace: Workspace | None, mode: str = 'r')[source]¶
Open a workspace in the requested ‘mode’. If receiving an opened Workspace instead, merely return the given workspace.
- Parameters
workspace – A Workspace class
mode – Set the h5 read/write mode
- Return h5py.File
Handle to an opened Workspace.
- geoh5py.shared.utils.fetch_h5_handle(file: str | h5py.File | Path, mode: str = 'r') → h5py.File[source]¶
Open in read+ mode a geoh5 file from string. If receiving a file instead of a string, merely return the given file.
- Parameters
file – Name or handle to a geoh5 file.
mode – Set the h5 read/write mode
- Return h5py.File
Handle to an opened h5py file.
- geoh5py.shared.utils.get_attributes(entity, omit_list=(), attributes=None)[source]¶
Extract the attributes of an object with omissions.
- geoh5py.shared.utils.iterable(value: Any, checklen: bool = False) → bool[source]¶
Checks if object is iterable.
- Parameters
- valueObject to check for iterableness.
- checklenRestrict objects with __iter__ method to len > 1.
- Returns
- True if object has __iter__ attribute but is not string or dict type.
- geoh5py.shared.utils.iterable_message(valid: list[Any] | None) → str[source]¶
Append possibly iterable valid: “Must be (one of): {valid}.”.
- geoh5py.shared.utils.mask_by_extent(locations: np.ndarray, extent: np.ndarray | list[list]) → np.ndarray[source]¶
Find indices of locations within a rectangular extent.
- Parameters
locations – shape(, 3) or shape(, 2) Coordinates to be evaluated.
extent – shape(2, 2) Limits defined by the South-West and North-East corners. Extents can also be provided as 3D coordinates with shape(2, 3) defining the top and bottom limits.
- geoh5py.shared.utils.match_values(vec_a, vec_b, collocation_distance=0.0001) → ndarray[source]¶
Find indices of matching values between two arrays, within collocation_distance.
- Param
vec_a, list or numpy.ndarray Input sorted values
- Param
vec_b, list or numpy.ndarray Query values
- Returns
indices, numpy.ndarray Pairs of indices for matching values between the two arrays such that vec_a[ind[:, 0]] == vec_b[ind[:, 1]].
- geoh5py.shared.utils.merge_arrays(head, tail, replace='A->B', mapping=None, collocation_distance=0.0001, return_mapping=False) → ndarray[source]¶
Given two numpy.arrays of different length, find the matching values and append both arrays.
- Param
head, numpy.array of float First vector of shape(M,) to be appended.
- Param
tail, numpy.array of float Second vector of shape(N,) to be appended
- Param
mapping=None, numpy.ndarray of int Optional array where values from the head are replaced by the tail.
- Param
collocation_distance=1e-4, float Tolerance between matching values.
- Returns
numpy.array shape(O,) Unique values from head to tail without repeats, within collocation_distance.
geoh5py.shared.validators¶
- class geoh5py.shared.validators.AssociationValidator(**kwargs)[source]¶
Bases:
BaseValidator
Validate the association between data and parent object.
- classmethod validate(name: str, value: Entity | PropertyGroup | UUID | None, valid: Entity | Workspace) → None[source]¶
- Parameters
name – Parameter identifier.
value – Input parameter value.
valid – Expected value shape
- validator_type = 'association'¶
- class geoh5py.shared.validators.AtLeastOneValidator(**kwargs)[source]¶
Bases:
BaseValidator
- validator_type = 'one_of'¶
- class geoh5py.shared.validators.BaseValidator(**kwargs)[source]¶
Bases:
ABC
Concrete base class for validators.
- abstract classmethod validate(name: str, value: Any, valid: Any)[source]¶
Custom validation function.
- abstract property validator_type: str¶
Validation type identifier.
- class geoh5py.shared.validators.OptionalValidator(**kwargs)[source]¶
Bases:
BaseValidator
Validate that forms contain optional parameter if None value is given.
- classmethod validate(name: str, value: Any | None, valid: bool) → None[source]¶
- Parameters
name – Parameter identifier.
value – Input parameter value.
valid – True if optional keyword in form for parameter.
- validator_type = 'optional'¶
- class geoh5py.shared.validators.PropertyGroupValidator(**kwargs)[source]¶
Bases:
BaseValidator
Validate property_group from parent entity.
- classmethod validate(name: str, value: PropertyGroup, valid: str) → None[source]¶
Custom validation function.
- validator_type = 'property_group_type'¶
- class geoh5py.shared.validators.RequiredValidator(**kwargs)[source]¶
Bases:
BaseValidator
Validate that required keys are present in parameter.
- classmethod validate(name: str, value: Any, valid: bool) → None[source]¶
- Parameters
name – Parameter identifier.
value – Input parameter value.
valid – Assert to be required
- validator_type = 'required'¶
- class geoh5py.shared.validators.ShapeValidator(**kwargs)[source]¶
Bases:
BaseValidator
Validate the shape of provided value.
- classmethod validate(name: str, value: Any, valid: tuple[int]) → None[source]¶
- Parameters
name – Parameter identifier.
value – Input parameter value.
valid – Expected value shape
- validator_type = 'shape'¶
- class geoh5py.shared.validators.TypeValidator(**kwargs)[source]¶
Bases:
BaseValidator
Validate the value type from a list of valid types.
- classmethod validate(name: str, value: Any, valid: list[type] | type) → None[source]¶
- Parameters
name – Parameter identifier.
value – Input parameter value.
valid – List of accepted value types
- validator_type = 'types'¶
- class geoh5py.shared.validators.UUIDValidator(**kwargs)[source]¶
Bases:
BaseValidator
Validate a uuui.UUID value or uuid string.
- classmethod validate(name: str, value: Any, valid: None = None) → None[source]¶
- Parameters
name – Parameter identifier.
value – Input parameter uuid.
valid – [Optional] Validate uuid from parental entity or known uuids
- validator_type = 'uuid'¶
- class geoh5py.shared.validators.ValueValidator(**kwargs)[source]¶
Bases:
BaseValidator
Validator that ensures that values are valid entries.
- classmethod validate(name: str, value: Any, valid: list[float | str]) → None[source]¶
- Parameters
name – Parameter identifier.
value – Input parameter value.
valid – List of accepted values
- validator_type = 'values'¶
geoh5py.shared.weakref_utils¶
- geoh5py.shared.weakref_utils.get_clean_ref(some_dict: dict[K, ReferenceType[T]], key: K) → T | None[source]¶
Gets the referent value for the given
key
in asome_dict
ofweakref
values. In casekey
points to a reference to a deleted value, remove that key fromsome_dict
on the fly, and returns None.- Parameters
some_dict – The dictionary of
weakref
values.key – The key
- Returns
the referent value for
key
if found in the the dictionary, else None.
- geoh5py.shared.weakref_utils.insert_once(some_dict: dict[K, ReferenceType], key: K, value)[source]¶
Check if the reference to an Entity with uuid is already in use.
- Parameters
some_dict – Dictionary of UUID keys and weakref values.
key – UUID key to be checked.
value – Entity to be checked
- Returns
Dictionary with clean weakref