### Install Pre-commit Hooks Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Install the pre-commit framework and its associated hooks. This command should be run from the project's root directory. ```bash pip install --user pre-commit ``` ```bash conda install -c conda-forge pre-commit ``` ```bash pre-commit install ``` -------------------------------- ### Initialize Workspace and Object Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/data.ipynb Setup a workspace and create a curve object for data demonstration. ```python import numpy as np from geoh5py import Workspace from geoh5py.objects import Curve # Re-use the previous workspace workspace = Workspace.create("my_project.geoh5") # Create some curve object for demo curve = Curve.create(workspace, vertices=np.c_[np.arange(100), np.zeros((100, 2))]) ``` -------------------------------- ### Activate Conda Environment and Install Dependencies Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Activate the previously created Conda environment and then run 'poetry install' to install project dependencies. Poetry will automatically detect and use the active Conda environment. ```bash conda activate my-env poetry install ``` -------------------------------- ### Install geoh5py from Source Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/installation.rst Clone the geoh5py repository and install it locally for development purposes. Ensure the repository is cloned with submodules. ```bash $ git clone --recursive https://github.com/MiraGeoscience/geoh5py.git $ cd geoh5py $ python setup.py install ``` -------------------------------- ### Install Poetry with PowerShell Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Use this command to install Poetry if you have Python in your system's PATH. Ensure you are using PowerShell. ```powershell (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py - ``` -------------------------------- ### Install Dependencies Without Development Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Use this command to install only the production dependencies, excluding development-specific ones. This is useful for deployment. ```bash poetry install --without=dev ``` -------------------------------- ### Import required libraries Source: https://github.com/mirageoscience/geoh5py/blob/develop/examples/EMAG_global_plot.ipynb Initial setup for plotting, data manipulation, and geoh5py workspace management. ```python %matplotlib inline import matplotlib.pyplot as plt import numpy as np import scipy.sparse as sp from GeoToolkit.graphics import graphics from GeoToolkit.Mag import DataIO, Mag, MathUtils, ProblemSetter, Simulator from scipy.spatial import Delaunay from skimage import exposure from geoh5py.objects import Surface from geoh5py.workspace import Workspace ``` -------------------------------- ### Install Project Dependencies with Poetry Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Run this command from the project folder to have Poetry create and manage its own virtual environment for the project. This is an alternative to using Conda environments. ```bash poetry install ``` -------------------------------- ### Install geoh5py from PyPI Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/installation.rst Use this command to install the latest stable version of geoh5py from the Python Package Index. ```bash $ pip install geoh5py ``` -------------------------------- ### Example ui.json Structure Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/uijson_format/usage.rst A basic ui.json file defining a block model selection parameter, a UI title, and the command to run. Ensure 'meshType' UUIDs are correct for object selection. ```json { "grid_object": { "meshType": ["{B020A277-90E2-4CD7-84D6-612EE3F25051}"], "main": true, "label": "Select Block Model", "value": "" }, "title":"My first UI", "run_command": "run_me", "conda_environment": "my_env" } ``` -------------------------------- ### Install Git LFS Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Install Git Large File Storage (LFS) to manage large files within the Git repository. This command should be run from the project folder. ```bash git lfs install ``` -------------------------------- ### Boolean Parameter Example Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/uijson_format/forms.rst Use for boolean inputs. 'value' determines the initial state. ```json { "input":{ "main": true, "label": "Do you like Python?", "value": true, "tooltip": "Check if you like Python" } } ``` -------------------------------- ### Install Poetry in Conda Environment Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Install Poetry within an activated Conda environment using this command. This is an alternative to the PowerShell installation. ```bash curl -sSL https://install.python-poetry.org | python - ``` -------------------------------- ### Install geoh5py Development Version Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/installation.rst Install the latest development version of geoh5py directly from the GitHub repository's development branch. ```bash $ pip install git+https://github.com/MiraGeoscience/geoh5py.git ``` -------------------------------- ### List Installed Packages in Conda Environment Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Check if the 'my-app' package is installed within the specified Conda environment. This helps verify the installation. ```bash conda list my-app ``` -------------------------------- ### Get Poetry Environment Info Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Use this command to find the location of your Poetry virtual environment. This is useful for configuring interpreters in IDEs. ```bash poetry env info ``` -------------------------------- ### Configure Pre-commit for Push Events Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Uninstall pre-commit hooks from running on commit and install them to run on push instead. This reduces overhead during the commit process. ```bash pre-commit uninstall -t pre-commit pre-commit install -t pre-push ``` -------------------------------- ### Specify Python Executable for Poetry Environment Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Instruct Poetry to use a specific Python executable (e.g., from a Conda environment) for the project's virtual environment. Replace the example path with the actual path to your Python executable. ```bash poetry env use C:\...\envs\py310\python.exe ``` -------------------------------- ### Add a New Dependency with Poetry Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Add a new dependency to pyproject.toml, update the lock file, and install it in one step. Use the '-G dev' flag for development dependencies. ```bash poetry add some-dependency ``` ```bash poetry add some-other-dependency==1.2.3 ``` ```bash poetry add -G dev some-dev-dependency ``` -------------------------------- ### Update Poetry Lock File and Install Dependencies Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst If dependencies in pyproject.toml are updated, or to resolve to the latest compatible versions, use these commands to update the lock file and reinstall. ```bash poetry lock poetry install ``` -------------------------------- ### Conditional check Source: https://github.com/mirageoscience/geoh5py/blob/develop/examples/EMAG_global_plot.ipynb Simple boolean check example. ```python aa = [1] if aa: print("Is true") ``` -------------------------------- ### Find and Retrieve Entities in Geoh5py Source: https://context7.com/mirageoscience/geoh5py/llms.txt Demonstrates finding entities by name and UUID, listing all entities, objects, groups, and data within a workspace, and retrieving specific data from an object. Ensure the geoh5py library is installed and a workspace is properly managed. ```python from geoh5py import Workspace from geoh5py.objects import Points, Curve import numpy as np import uuid with Workspace() as ws: # Create multiple objects points = Points.create( ws, vertices=np.random.rand(10, 3), name="Sample Points" ) curve = Curve.create( ws, vertices=np.random.rand(5, 3), name="Survey Line" ) points.add_data({ "Grade": {"values": np.random.rand(10), "association": "VERTEX"} }) # Find entity by name found = ws.get_entity("Sample Points")[0] print(f"Found by name: {found.name}") # Find entity by UUID point_uid = points.uid found_by_uid = ws.get_entity(point_uid)[0] print(f"Found by UUID: {found_by_uid.name}") # List all entities print(f"All entity names: {ws.list_entities_name}") print(f"All objects: {ws.list_objects_name}") print(f"All groups: {ws.list_groups_name}") print(f"All data: {ws.list_data_name}") # Get data from object by name grade_data = points.get_data("Grade")[0] print(f"Data values: {grade_data.values}") # Get list of data names on object print(f"Data on points: {points.get_data_list()}") ws.save_as("find_entity_example.geoh5") ``` -------------------------------- ### Initialize Workspace and GeoImage Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/objects.ipynb Create a new workspace and a GeoImage object. ```python workspace = Workspace.create("my_images.geoh5") geoimage = GeoImage.create(workspace) ``` -------------------------------- ### Activate Poetry Shell and Run Module Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Activate the project's virtual environment using 'poetry shell' and then run Python modules directly. ```bash poetry shell python -m my-app ``` -------------------------------- ### Create a new geoh5py Workspace Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/workspace.ipynb Use the `.create` method to initialize a new, blank workspace file on disk. Ensure the `geoh5py` library is imported. ```python from pathlib import Path from geoh5py.workspace import Workspace # Create a new project workspace = Workspace.create("project.geoh5") ``` -------------------------------- ### Create a new project and add a ContainerGroup Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/groups.ipynb Use this snippet to create a new blank geoh5 project and add a ContainerGroup with a specified name. The group is immediately written to the project file. ```python 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") ``` -------------------------------- ### Grid data using Simulator Source: https://github.com/mirageoscience/geoh5py/blob/develop/examples/EMAG_global_plot.ipynb Grids the downloaded data based on file type, either using a CSV gridding widget or georeferenced grid. ```python if download.result is not None: if download.result[1] == "CSV": grid = Simulator.dataGriddingWidget( download.result[0], marker=False, dataColumn=3, Resolution=100, Method="linear", ) display(grid) else: grid = Simulator.dataGridGeoref(download.result[0]) display(grid) ``` -------------------------------- ### Fetch data using DataIO Source: https://github.com/mirageoscience/geoh5py/blob/develop/examples/EMAG_global_plot.ipynb Downloads data from a specified path and displays the interactive fetch widget. ```python download = DataIO.fetchData( path=r"C:\Users\DominiqueFournier\Documents\GIT\GeoToolkit\Notebooks\Output", localCloud="Local", ) display(download) ``` -------------------------------- ### Retrieve Data List and Specific Data Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/data.ipynb Use to get a list of all data associated with an object and retrieve a specific data entity. ```python my_list = curve.get_data_list() print(my_list, curve.get_data(my_list[0])) ``` -------------------------------- ### Build API Docs with Sphinx Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Command to generate API documentation using Sphinx. It specifies the output directory, the source directory of the Python package, and the template directory. ```bash sphinx-apidoc -o source/ ../geoh5py -t docs/templates ``` -------------------------------- ### Manage geoh5py Workspaces Source: https://context7.com/mirageoscience/geoh5py/llms.txt Demonstrates creating, opening, and closing workspaces. Supports context managers for automatic closing and read-only modes. ```python from geoh5py import Workspace from pathlib import Path import numpy as np # Create a new workspace and save to disk workspace = Workspace() workspace.save_as("my_project.geoh5") # Open existing workspace with context manager (auto-closes) with Workspace("my_project.geoh5") as ws: # Access all objects in workspace for obj in ws.objects: print(f"Object: {obj.name}, Type: {type(obj).__name__}") # Get entity by name or UUID entity = ws.get_entity("MyPoints")[0] # List all data names print(ws.list_data_name) # Open workspace in read-only mode ws_readonly = Workspace("my_project.geoh5", mode="r") # Manually close workspace ws_readonly.close() ``` -------------------------------- ### Create and Add Data to a Drillhole in Geoh5py Source: https://context7.com/mirageoscience/geoh5py/llms.txt Illustrates creating a Drillhole object with collar and survey information, then adding both point (depth-referenced) and interval (from-to) data, including value mapping. Also shows how to desurvey points. ```python from geoh5py import Workspace from geoh5py.objects import Drillhole import numpy as np with Workspace() as ws: # Create a drillhole with collar and survey drillhole = Drillhole.create( ws, name="DDH-001", collar=np.array([1000.0, 2000.0, 500.0]), surveys=np.array([ [0.0, 0.0, -90.0], # Depth, Azimuth, Dip at surface [50.0, 10.0, -85.0], # Survey at 50m depth [100.0, 15.0, -80.0], # Survey at 100m depth [200.0, 20.0, -75.0], # End of hole ]), cost=50000.0, planning="Completed", ) print(f"End of hole: {drillhole.end_of_hole}m") # Output: 200.0m print(f"Collar: {drillhole.collar}") # Add depth-referenced (point) data depths = np.array([10.0, 25.0, 50.0, 75.0, 100.0]) grades = np.array([0.5, 1.2, 2.1, 0.8, 1.5]) drillhole.add_data({ "Au_ppm": { "depth": depths, "values": grades, } }) # Add interval (from-to) data from_to = np.array([ [0.0, 25.0], [25.0, 50.0], [50.0, 100.0], ]) lithology_codes = np.array([1, 2, 1]) drillhole.add_data({ "Lithology": { "from-to": from_to, "values": lithology_codes, "type": "REFERENCED", "value_map": {1: "Granite", 2: "Sediment"}, } }) # Desurvey: convert depths to XYZ coordinates xyz_at_50m = drillhole.desurvey(np.array([50.0])) print(f"Location at 50m depth: {xyz_at_50m}") ws.save_as("drillhole_example.geoh5") ``` -------------------------------- ### Add Various Data Types to Geoh5py Objects Source: https://context7.com/mirageoscience/geoh5py/llms.txt Demonstrates adding float, integer, referenced (categorical), and text data to a Points object. Includes examples of accessing data and listing all data on an object. ```python from geoh5py import Workspace from geoh5py.objects import Points import numpy as np with Workspace() as ws: # Create points object vertices = np.random.rand(100, 3) * 100 points = Points.create(ws, vertices=vertices, name="Sample Data") # Add float data (associated with vertices) points.add_data({ "Elevation": { "values": vertices[:, 2], "association": "VERTEX", } }) # Add integer data points.add_data({ "Sample_ID": { "values": np.arange(100, dtype="int32"), "association": "VERTEX", "type": "INTEGER", } }) # Add referenced (categorical) data with value map categories = np.random.randint(0, 3, size=100) points.add_data({ "Rock_Type": { "values": categories, "association": "VERTEX", "type": "REFERENCED", "value_map": {0: "Unknown", 1: "Granite", 2: "Basalt"}, } }) # Add text data labels = [f"Point_{i}" for i in range(100)] points.add_data({ "Labels": { "values": labels, "association": "VERTEX", "type": "TEXT", } }) # Access data by name elevation_data = points.get_data("Elevation")[0] print(f"Elevation values: {elevation_data.values[:5]}") # List all data on object print(f"Data list: {points.get_data_list()}") ws.save_as("data_example.geoh5") ``` -------------------------------- ### Create a BlockModel Object Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/objects.ipynb Initialize a rectilinear grid (tensor mesh) with defined cell delimiters and orientation. ```python from geoh5py.objects import BlockModel with Workspace.create("my_block_model.geoh5") as workspace: mesh = BlockModel.create( workspace, origin=[25, -100, 50], u_cell_delimiters=np.cumsum(np.ones(16) * 5), # Offsets along u v_cell_delimiters=np.cumsum(np.ones(32) * 5), # Offsets along v z_cell_delimiters=np.cumsum(np.ones(16) * -2.5), # Offsets along z (down) rotation=30.0, ) ``` -------------------------------- ### Execute Module with Poetry Run Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Run a Python module using Poetry's execution command. This ensures the module runs within the project's virtual environment. ```bash poetry run python -m my-app ``` -------------------------------- ### Create a new group with a specified parent Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/groups.ipynb This code demonstrates how to create a new ContainerGroup and assign its parent at the time of creation. If no parent is specified, it defaults to the workspace's root group. ```python # 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.") ``` -------------------------------- ### Create Surface from Delaunay Triangulation Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/objects.ipynb Build a Surface object using Delaunay triangulation from a set of 2D points. Requires scipy.spatial.Delaunay and geoh5py.objects.Surface. ```python from scipy.spatial import Delaunay # Get a project with Workspace.create("delaunay_surface.geoh5") as workspace: # Create a triangulated surface from points surf_2D = Delaunay(xyz[:, :2]) # Create the Surface object surface = Surface.create( workspace, vertices=points.vertices, # Add vertices cells=surf_2D.simplices, ) ``` -------------------------------- ### Create a Tipper survey Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/tipper.ipynb Initializes a new geoh5 workspace and creates Tipper receiver and base station entities from vertex coordinates. ```python import numpy as np from geoh5py.objects import TipperBaseStations, TipperReceivers from geoh5py.workspace import Workspace # Create a new project workspace = Workspace("my_project.geoh5") # Define the pole locations n_stations = 64 n_lines = 2 x_loc, y_loc = np.meshgrid( np.linspace(0, 60, n_stations), np.linspace(-20, 20.0, n_lines) ) vertices = np.c_[x_loc.ravel(), y_loc.ravel(), np.zeros_like(x_loc).ravel()] # Assign a line ID to the poles (vertices) parts = np.kron(np.arange(n_lines), np.ones(n_stations)).astype("int") # Create the survey from vertices receivers = TipperReceivers.create(workspace, vertices=vertices, parts=parts) base = TipperBaseStations.create(workspace, vertices=vertices) ``` -------------------------------- ### Create geoh5py Points Objects Source: https://context7.com/mirageoscience/geoh5py/llms.txt Shows how to create Points objects with 3D coordinates and manage vertices. Supports adding and removing points. ```python from geoh5py import Workspace from geoh5py.objects import Points import numpy as np with Workspace() as ws: # Create points with 3D coordinates vertices = np.array([ [0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 1.0, 1.0], [3.0, 2.0, 0.5], [4.0, 3.0, 0.0], ]) points = Points.create(ws, vertices=vertices, name="Sample Points") # Access properties print(f"Number of vertices: {points.n_vertices}") # Output: 5 print(f"Vertices shape: {points.vertices.shape}") # Output: (5, 3) # Remove specific vertices points.remove_vertices([0, 2]) # Removes first and third points ws.save_as("points_example.geoh5") ``` -------------------------------- ### Access and configure metadata Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/tipper.ipynb Retrieves the metadata object and sets the frequency channels for the survey. ```python receivers.metadata ``` ```python receivers.channels = [30.0, 45.0, 90.0, 180.0, 360.0, 720.0] ``` -------------------------------- ### Open an existing geoh5py Workspace Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/workspace.ipynb Instantiate the `Workspace` object with an existing file path to open the project. The file will be opened in read-write mode by default. ```python workspace = Workspace("project.geoh5") ``` -------------------------------- ### Simple String Parameter Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/uijson_format/forms.rst Use for basic string inputs. Requires 'label' and 'value'. ```json { "my_string": { "main": true, "label": "Name", "value": "Default answer" } } ``` -------------------------------- ### Create Conda Environment Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Create a new Conda environment named 'my-env' with Python version 3.10. This environment will be used by Poetry. ```bash conda create -n my-env python=3.10 ``` -------------------------------- ### Accessing ui.json Parameters in Python Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/uijson_format/usage.rst Demonstrates how to read parameters from a ui.json file using geoh5py's InputFile module. The script expects the ui.json path as a command-line argument. ```python import sys from geoh5py.ui_json import InputFile ui_json = sys.argv[1] ifile = InputFile.read_ui_json(ui_json) params = ifile.data # Get the block model grid object bm = params["grid_object"] print(f"The selected object name is {bm.name}") ``` -------------------------------- ### Run Pre-commit Hooks Manually Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Manually execute all configured pre-commit hooks on all files in the repository. This is useful for checking code quality and formatting before committing. ```bash pre-commit run --all-files ``` -------------------------------- ### Configure Data or Value Parameter with UI Switching Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/uijson_format/forms.rst Allows a parameter to accept either a direct float value or data from a Geoscience ANALYST object. The 'isValue' and 'property' members control the UI switching. ```json { "data_mesh": { "main": true, "meshType": ["{202C5DB1-A56D-4004-9CAD-BAAFD8899406}" , "{6A057FDC-B355-11E3-95BE-FD84A7FFCB88}"], "main": true, "label": "Select Points or Curve", "value": "" }, "uncertainty_channel": { "main": true, "association": "Vertex", "dataType": "Float", "isValue": true, "property": "", "min": 0.001, "max": 100.0, "precision": 3 } } ``` -------------------------------- ### Access metadata and components Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/tipper.ipynb Retrieves updated metadata and the list of survey components. ```python receivers.metadata ``` ```python receivers.components ``` -------------------------------- ### File Parameter with Type Filtering Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/uijson_format/forms.rst Use for file selection. Supports filtering by 'fileType' and providing descriptions via 'fileDescription'. ```json { "model_file": { "fileDescription": ["Chargeability", "Conductivity"], "fileType": ["chg", "con"], "main": true, "label": "DC/IP model file", "value": "" } } ``` -------------------------------- ### Create Parameter Dependencies Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/uijson_format/forms.rst Defines dependencies between parameters where one parameter controls the enabled state of another. ```json { "python_interest": { "main": true, "label": "Do you like Python?", "value": false, "tooltip": "Check if you like Python" }, "favourite_package": { "main": true, "label": "Favourite Python package", "value": "geoh5py", "dependency": "python_interest", "dependencyType": "enabled" } } ``` ```json { "territory": { "choiceList": ["Northwest Territories", "Yukon", "Nunavut"], "main": true, "label": "Favourite Canadian territory", "value": "Yukon", "optional": true, "enabled": false }, "city": { "main": true, "choiceList": ["Yellowknife", "Whitehorse", "Iqaluit"], "label": "Favourite capital", "value": "", "dependency": "territory", "dependencyType": "enabled" } } ``` -------------------------------- ### Organize Data with Property Groups in Geoh5py Source: https://context7.com/mirageoscience/geoh5py/llms.txt Shows how to create and use PropertyGroups to organize related data entities. Demonstrates adding data directly to a group and accessing tabular data from a group. ```python from geoh5py import Workspace from geoh5py.objects import Points from geoh5py.groups import PropertyGroup import numpy as np with Workspace() as ws: # Create points with multiple data fields vertices = np.random.rand(50, 3) * 100 points = Points.create(ws, vertices=vertices, name="Geochemistry Samples") # Add multiple geochemistry data points.add_data({ "Au_ppm": {"values": np.random.rand(50) * 10, "association": "VERTEX"}, "Cu_pct": {"values": np.random.rand(50) * 5, "association": "VERTEX"}, "Ag_ppm": {"values": np.random.rand(50) * 100, "association": "VERTEX"}, }) # Create property group and add data prop_group = points.create_property_group( name="Precious Metals", association="VERTEX", ) prop_group.add_properties(["Au_ppm", "Ag_ppm"]) # Add data directly to a property group during creation points.add_data( {"Fe_pct": {"values": np.random.rand(50) * 30, "association": "VERTEX"}}, property_group="Base Metals", ) # Access property groups for pg in points.property_groups: print(f"Group: {pg.name}, Properties: {pg.properties_name}") # Get specific property group precious = points.get_property_group("Precious Metals")[0] print(f"Association: {precious.association}") # Access tabular data from property group table = precious.table print(f"Column names: {table.columns}") ws.save_as("property_group_example.geoh5") ``` -------------------------------- ### Create a Drillhole Object Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/objects.ipynb Create a Drillhole object using collar and survey data. Requires a DrillholeGroup entity. Requires geoh5py.groups.DrillholeGroup and geoh5py.objects.Drillhole. ```python from geoh5py.groups import DrillholeGroup from geoh5py.objects import Drillhole # Get a project with Workspace.create("my_drillhole.geoh5") as workspace: dh_group = DrillholeGroup.create(workspace) # Create a simple well total_depth = 100 dist = np.linspace(0, total_depth, 10) azm = np.ones_like(dist) * 45.0 dip = np.linspace(-89, -75, dist.shape[0]) collar = np.r_[0.0, 10.0, 10] well = Drillhole.create( workspace, collar=collar, surveys=np.c_[dist, azm, dip], name="Drillhole", parent=dh_group, ) print(well.name) ``` -------------------------------- ### Working with Groups in Geoh5py Source: https://context7.com/mirageoscience/geoh5py/llms.txt Illustrates creating container groups, adding objects and sub-groups to them, and accessing the group hierarchy. This is useful for organizing complex geological projects. ```python from geoh5py import Workspace from geoh5py.groups import ContainerGroup from geoh5py.objects import Points, Surface import numpy as np with Workspace() as ws: # Create a container group geology_group = ContainerGroup.create(ws, name="Geology") # Create objects within the group samples = Points.create( geology_group, # Parent is the group vertices=np.random.rand(20, 3) * 100, name="Rock Samples", ) # Create another group as sub-group surfaces_group = ContainerGroup.create(geology_group, name="Surfaces") topo = Surface.create( surfaces_group, vertices=np.array([[0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0]]), cells=np.array([[0, 1, 2], [0, 2, 3]]), name="Topography", ) # Access group hierarchy print(f"Root children: {[c.name for c in ws.root.children]}") print(f"Geology children: {[c.name for c in geology_group.children]}") # Find all groups in workspace print(f"All groups: {[g.name for g in ws.groups]}") ws.save_as("groups_example.geoh5") ``` -------------------------------- ### Load geoh5py Workspace from BytesIO Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/workspace.ipynb An existing `geoh5` project can be loaded into memory from a `BytesIO` object. This involves reading the file as bytes and then passing the `BytesIO` object to the `Workspace` constructor. ```python from io import BytesIO with open("project.geoh5", "rb") as in_file: byte_data = in_file.read() bytes_ws = Workspace(BytesIO(byte_data)) print(bytes_ws.h5file) ``` -------------------------------- ### Create a CurrentElectrode object Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/direct_current.ipynb Initializes a new geoh5 workspace and defines pole locations to create a CurrentElectrode object. ```python import uuid from pathlib import Path import numpy as np from geoh5py.objects import CurrentElectrode, PotentialElectrode from geoh5py.workspace import Workspace # Create a new project workspace = Workspace("my_project.geoh5") # Define the pole locations n_poles = 9 n_lines = 2 x_loc, y_loc = np.meshgrid(np.linspace(0, 60, n_poles), np.linspace(-20, 20.0, n_lines)) vertices = np.c_[x_loc.ravel(), y_loc.ravel(), np.zeros_like(x_loc).ravel()] # Assign a line ID to the poles (vertices) parts = np.kron(np.arange(n_lines), np.ones(n_poles)).astype("int") # Create the CurrentElectrode object currents = CurrentElectrode.create(workspace, vertices=vertices, parts=parts) ``` -------------------------------- ### Save and Load GeoImage Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/objects.ipynb Save a GeoImage to a file or create one directly from an existing image file. ```python geoimage.save_as("my_image.jpg") ``` ```python geoimage = GeoImage.create(workspace, image="my_image.jpg") ``` -------------------------------- ### Run Project Tests with Pytest Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Execute all tests located in the 'tests' folder using Pytest. Test files should be named with a '_test.py' suffix. ```bash poetry run pytest ``` -------------------------------- ### Create an in-memory geoh5py Workspace Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/workspace.ipynb A workspace can be created and managed entirely in memory by omitting the file path during instantiation. The `h5file` attribute will reference a `BytesIO` object. ```python in_memory = Workspace() print(in_memory.h5file) ``` -------------------------------- ### Initialize Airborne TEM Survey Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/airborne_tem.ipynb Creates a new geoh5 workspace and initializes transmitter and receiver entities with defined vertex locations. ```python import numpy as np from geoh5py.objects import AirborneTEMReceivers, AirborneTEMTransmitters from geoh5py.workspace import Workspace # Create a new project workspace = Workspace("my_project.geoh5") # Define the pole locations n_stations = 9 n_lines = 2 x_loc, y_loc = np.meshgrid( np.linspace(0, 60, n_stations), np.linspace(-20, 20.0, n_lines) ) vertices = np.c_[x_loc.ravel(), y_loc.ravel(), np.zeros_like(x_loc).ravel()] # Assign a line ID to the poles (vertices) parts = np.kron(np.arange(n_lines), np.ones(n_stations)).astype("int") # Create the survey as a coincident loop system aem_receivers = AirborneTEMReceivers.create(workspace, vertices=vertices, parts=parts) aem_transmitters = AirborneTEMTransmitters.create( workspace, vertices=vertices, parts=parts ) ``` -------------------------------- ### Verify Metadata Equality Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/direct_current.ipynb Checks if the metadata objects for potential and current electrodes are identical, confirming the successful association. ```python print(potentials.metadata == currents.metadata) ``` -------------------------------- ### Access entity by name or UID Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/groups.ipynb Once an entity is added to the workspace, it can be retrieved using its name or unique identifier (UID). This snippet demonstrates how to access an entity and verify that retrieval by name or UID yields the same object. ```python print(group.uid) print(workspace.get_entity("myGroup")[0] == workspace.get_entity(group.uid)[0]) ``` -------------------------------- ### Create a 3D Block Model in Geoh5py Source: https://context7.com/mirageoscience/geoh5py/llms.txt Shows how to create a 3D Block Model using cell delimiters for each axis, defining origin, rotation, and dimensions. Essential for volumetric modeling. ```python from geoh5py import Workspace from geoh5py.objects import BlockModel import numpy as np with Workspace() as ws: # Define cell delimiters (nodal offsets from origin) u_delimiters = np.cumsum(np.r_[0, np.ones(10) * 25.0]) # 10 cells, 25m each v_delimiters = np.cumsum(np.r_[0, np.ones(10) * 25.0]) z_delimiters = np.cumsum(np.r_[0, np.ones(5) * -10.0]) # 5 layers, 10m thick going down block_model = BlockModel.create( ws, name="Resource Model", origin=[1000.0, 2000.0, 500.0], u_cell_delimiters=u_delimiters, v_cell_delimiters=v_delimiters, z_cell_delimiters=z_delimiters, rotation=30.0, ) print(f"Shape (u, v, z): {block_model.shape}") # Output: (10, 10, 5) print(f"Total cells: {np.prod(block_model.shape)}") # Output: 500 print(f"Centroids shape: {block_model.centroids.shape}") # Output: (500, 3) # Access cell sizes print(f"U cell sizes: {block_model.u_cells}") print(f"V cell sizes: {block_model.v_cells}") print(f"Z cell sizes: {block_model.z_cells}") ws.save_as("blockmodel_example.geoh5") ``` -------------------------------- ### Verify Python Executable in Conda Environment Source: https://github.com/mirageoscience/geoh5py/blob/develop/README-dev.rst Confirm that Poetry is using the correct Python executable from the active Conda environment. This command shows the path to the Python interpreter. ```bash poetry run where python ``` -------------------------------- ### Create a Points Object Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/objects.ipynb Use this to create a Points object from an array of 3D coordinates. Requires numpy and geoh5py.objects.Points. ```python import numpy as np from geoh5py import Workspace from geoh5py.objects import Points # Get a project with Workspace.create("my_points.geoh5") as workspace: # Generate a numpy array of xyz locations n = 100 radius, theta = np.arange(n), np.linspace(0, np.pi * 8, n) x, y = radius * np.cos(theta), radius * np.sin(theta) z = (x**2.0 + y**2.0) ** 0.5 xyz = np.c_[x.ravel(), y.ravel(), z.ravel()] # Form a 2D array # Create the Point object points = Points.create( workspace, # The target Workspace vertices=xyz, # Set vertices ) ``` -------------------------------- ### Create a Surface Object with Data Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/objects.ipynb Create a Surface object with vertices and cells, and add associated data for nodes and faces. Requires geoh5py.objects.Surface. ```python from geoh5py.objects import Surface # Get a project with Workspace.create("simple_surface.geoh5") as workspace: # Create the surface surface = Surface.create( workspace, vertices=vertices, cells=simplices, name="simple" ) # Data can be added to either the triangles or the nodes. # The association can be specified by the user, or determined # by the length of the array provided. vertex_data_values = np.array([200.0, 100.0, 300.0, 400.0]) cell_data = surface.add_data( { "Node values": { # Name of the data property "association": "VERTEX", # Data associated with vertices "values": vertex_data_values, "units": "m/s", }, "Face values": { # Name of the data property "values": np.r_[1, 3], # Two values will be detected as "cell" data. "units": "SI", }, } ) ``` -------------------------------- ### Use geoh5py Workspace as a Context Manager Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/workspace.ipynb Employing a `with` statement is the preferred method for managing workspaces, as it automatically handles closing the file upon exiting the block, preventing resource leaks. ```python with Workspace("project.geoh5") as workspace: print(workspace.geoh5) print(workspace._geoh5) ``` -------------------------------- ### Configure Geoscience ANALYST Object Parameter Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/uijson_format/forms.rst Sets up a parameter to select geoh5py objects, filtering by meshType and allowing multi-selection. The value returned is the object's UUID. ```json { "interesting_object": { "meshType": ["{202C5DB1-A56D-4004-9CAD-BAAFD8899406}" , "{6A057FDC-B355-11E3-95BE-FD84A7FFCB88}"], "main": true, "multiSelect": false, "label": "Select Points or Curve", "value": "" } } ``` -------------------------------- ### Add Interval (From-To) Data to Drillhole Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/data.ipynb Use to add interval-based data defined by 'from-to' depth ranges. Data with matching 'from-to' values within tolerance will be grouped. ```python # Define a from-to array from_to = np.vstack([[0.25, 25.5], [30.1, 55.5], [56.5, 80.2]]) # Add some reference data well.add_data( { "interval_values": { "values": np.asarray([1, 2, 3]), "from-to": from_to, "value_map": {1: "Unit_A", 2: "Unit_B", 3: "Unit_C"}, "type": "referenced", } } ) # Add float data on the same intervals well.add_data( { "random_values": { "values": np.random.randn(from_to.shape[0]), "from-to": from_to, } } ) ``` -------------------------------- ### Create a Grid2D Object Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/objects.ipynb Define a regular 2D grid in 3D space with specific orientation and cell dimensions. ```python from geoh5py.objects import Grid2D with Workspace.create("my_grid2d.geoh5") as workspace: # Create the Surface object grid = Grid2D.create( workspace, origin=[25, -75, 50], u_cell_size=2.5, v_cell_size=2.5, u_count=64, v_count=16, rotation=90.0, dip=45.0, ) ``` -------------------------------- ### Manage Raw Files as Blob Data Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/data.ipynb Store raw files as binary blobs within geoh5 and export them back to disk. ```python with open("docs.txt", mode="w") as file: file.write("Hello world") file_data = grid.add_file("docs.txt") ``` ```python file_data.save_file(path="./temp", name="exported.txt") ``` ```python import shutil shutil.rmtree("./temp") ``` -------------------------------- ### Create geoh5py Curve Objects Source: https://context7.com/mirageoscience/geoh5py/llms.txt Demonstrates creating Curve objects with explicit cells, auto-generated cells, and multi-part geometries. ```python from geoh5py import Workspace from geoh5py.objects import Curve import numpy as np with Workspace() as ws: # Create a curve with explicit cells vertices = np.array([ [0.0, 0.0, 0.0], [1.0, 1.0, 0.0], [2.0, 0.0, 0.0], [3.0, 1.0, 0.0], ]) # Cells define connectivity (pairs of vertex indices) cells = np.array([[0, 1], [1, 2], [2, 3]], dtype="uint32") curve = Curve.create(ws, vertices=vertices, cells=cells, name="Survey Line") # Auto-generate cells from sequential vertices (no cells provided) auto_curve = Curve.create(ws, vertices=vertices, name="Auto Connected") # Multi-part curve using parts array parts = np.array([0, 0, 1, 1]) # Two separate line segments multi_curve = Curve.create(ws, vertices=vertices, parts=parts, name="Multi-Part") print(f"Unique parts: {multi_curve.unique_parts}") # Output: [0, 1] ws.save_as("curve_example.geoh5") ``` -------------------------------- ### Inspect workspace tree Source: https://github.com/mirageoscience/geoh5py/blob/develop/examples/EMAG_global_plot.ipynb Displays the structure of the geoh5 workspace. ```python workspace.tree?? ``` -------------------------------- ### Create an Octree object Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/objects.ipynb Initializes a new Octree mesh within a geoh5 workspace using specified dimensions, cell sizes, and rotation. ```python from geoh5py.objects import Octree with Workspace.create("my_octree.geoh5") as workspace: octree = Octree.create( workspace, origin=[25, -100, 50], u_count=16, # Number of cells in power 2 v_count=32, w_count=16, u_cell_size=5.0, # Base cell size (highest octree level) v_cell_size=5.0, w_cell_size=2.5, # Offsets along z (down) rotation=30, ) ``` -------------------------------- ### Create Potential Electrode Dipoles Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/direct_current.ipynb Generates potential electrode dipoles (M-N pairs) for a given set of current injections. Ensure 'currents' and 'vertices' are properly defined and that indices do not exceed array bounds. ```python N = 6 dipoles = [] current_id = [] for val in currents.ab_cell_id.values: # For each source dipole if val == 0: # Skip the unknown continue cell_id = val - 1 # Python 0 indexing line = currents.parts[currents.cells[cell_id, 0]] for m_n in range(N): dipole_ids = (currents.cells[cell_id, :] + 2 + m_n).astype( "uint32" ) # Skip two poles # Shorten the array as we get to the end of the line if any(dipole_ids > (len(vertices) - 1)) or any( currents.parts[dipole_ids] != line ): continue dipoles += [dipole_ids] # Save the receiver id current_id += [val] # Save the source id potentials = PotentialElectrode.create( workspace, vertices=vertices, cells=np.vstack(dipoles) ) ``` -------------------------------- ### Update and Sync Metadata Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/airborne_tem.ipynb Demonstrates that linked entities share metadata updates, such as changing the input type. ```python aem_transmitters.input_type = "Tx and Rx" print(aem_receivers.input_type) ``` -------------------------------- ### Add survey data components Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/tipper.ipynb Populates the survey with geophysical data components using a nested dictionary structure. ```python # Arbitrary data generator using sine functions def data_fun(c, f): return (c + 1.0) * (f + 1.0) * np.sin(f * np.pi * (x_loc * y_loc).ravel() / 400.0) # Create a nested dictionary of component and frequency data. data = { component: { f"{component}_{freq}": {"values": data_fun(cc, ff)} for ff, freq in enumerate(receivers.channels) } for cc, component in enumerate( [ "Txz (real)", "Txz (imaginary)", "Tyz (real)", "Tyz (imaginary)", ] ) } receivers.add_components_data(data) ``` -------------------------------- ### Finalize workspace Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/tipper.ipynb Saves changes to the geoh5 workspace. ```python workspace.finalize() ``` -------------------------------- ### Verify saving in-memory Workspace to disk Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/user_guide/workspace.ipynb After saving an in-memory workspace to disk, the `h5file` attribute will point to the newly created file path, confirming the operation. ```python print(bytes_ws.h5file) ``` -------------------------------- ### geoh5py.ui_json.validations Package Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/api/geoh5py.ui_json.validations.rst Package level documentation for ui_json validations. ```APIDOC ## Package: geoh5py.ui_json.validations ### Description The validations package serves as the central repository for all validation rules applied to ui_json objects. It includes submodules for specific validation tasks and general utility functions. ``` -------------------------------- ### Multi-choice String Parameter (Dropdown) Source: https://github.com/mirageoscience/geoh5py/blob/develop/docs/content/uijson_format/forms.rst Use for dropdown selections. 'choiceList' provides options. 'multiSelect' allows multiple selections. ```json { "favourites": { "choiceList": ["Northwest Territories", "Yukon", "Nunavut"], "main": true, "multiSelect": false, "label": "Favourite Canadian territory", "value": "Yukon" } } ```