Groups#

Groups are effectively containers for other entities, such as Objects (Points, Curve, Surface, etc.) and other Groups. Groups are used to establish parent-child relationships and to store information about a collection of entities.

RootGroup#

By default, the parent of any new Entity is the workspace RootGroup. It is the only entity in the Workspace without a parent. Users rarely have to interect with the Root group as it is mainly used to maintain the overall project hierarchy.

Root

ContainerGroup#

A ContainerGroup can easily be added to the workspace and can be assigned a name and description.

from geoh5py import Workspace
from geoh5py.groups import ContainerGroup


# Create a blank project
workspace = Workspace.create("my_project.geoh5")

# Add a group
group = ContainerGroup.create(workspace, name="myGroup")

At creation, "myGroup" is written to the project geoh5 file and visible in the Analyst project tree.

Groups

Once added to the workspace, an entity can be accessed by its name or uid (unique identifier):

print(group.uid)
print(workspace.get_entity("myGroup")[0] == workspace.get_entity(group.uid)[0])
e16bae85-3916-4230-9dbe-af78e8f5b266
True

Parent/child relationship#

Any object or group can be added to another group to form a tree structure. This relationship can be established from either the parent or the child entity.

We can create a new group and assign the parent at the onset.

# Would default to the Root otherwise
new_group = ContainerGroup.create(workspace, parent=group)

print(f"The parent entity is: {new_group.parent.name}")
print(f"The 'group' now has {len(group.children)} child.")
The parent entity is: myGroup
The 'group' now has 1 child.

The relationship can always be changed afterwards.

new_group.parent = workspace.root

print(new_group.parent)
print(f"The 'group' now has {len(group.children)} children.")
<geoh5py.groups.root.RootGroup object at 0x725ca0f9d240>
The 'group' now has 0 children.

Alternatively, a child can be added from the parent.

# Defaults to the root
another_group = ContainerGroup.create(workspace)

# Transfer the custody to another group
group.add_children([another_group])

print(f"The parent entity is: {another_group.parent.name}")
print(f"The group now has {len(group.children)} child.")
The parent entity is: myGroup
The group now has 1 child.
workspace.close()