GemPy Documentation
repository·main·Indexed 23 days ago
https://github.com/gempy-project/gempyAn open-source Python library for implicit 3D structural geological modeling. GemPy enables the construction of complex models featuring folded structures, fault networks, and unconformities using a universal cokriging interpolation approach. It supports the modeling of conformal layers, magmatic bodies, and complex fault networks, with visualization capabilities via gempy_viewer (matplotlib and Pyvista). The current stable version is v3.
What's inside GemPy
- GemPy is an open-source Python library for implicit 3D structural geological modeling. It allows users to construct complex 3D geological models including fold structures, fault networks, and unconformities. The library is designed to be easily embedded in probabilistic frameworks for uncertainty analysis of subsurface structures.
Geological features supported by GemPy
mainGemPy can model various complex 3D geological scenarios, such as:
- Multiple conformal layers: Sequences of sedimentary layers.
- Layer sequences: Including conformal continuation or unconformities.
- Magmatic bodies: Of almost arbitrary shapes.
- Faults: With automatically calculated offsets based on affected geological objects.
- Fault networks: Complex networks where faults can affect other faults.
- Folds: Affecting single layers or entire layer stacks, including overturned and recumbent folds.
Interpolate petrophysical data in 3D using Kriging
mainWhile GemPy uses Kriging to interpolate scalar fields for constructing the structural model, it also provides dedicated functionality to interpolate petrophysical data within each domain in 3D. This allows you to populate domains with continuous 3D data distributions.How GemPyTensor handles backend abstraction
mainTo maintain a single graph implementation while supporting different computational backends (Numpy, Aesara, TensorFlow), GemPy uses a
GemPyTensorwrapper. This wrapper provides a unified syntax for common operations, even when the underlying package syntax differs (e.g., handlingset_subtensorwhich behaves differently in Numpy vs Aesara).class GemPyTensor: def __init__(package='numpy') if package=='numpy': _tt = np elif package=='aesara': _tt = aesara.tensor # Same numpy-aesara easy def sin(x): return _tt.sin(x) # Different def set_subtensor(x: slice, new_slice) if package=='numpy': x = new_slice return x if package == 'aesara': return _tt.set_subtensor(x , new_slice)Design principles of the GemPy Engine 3 interpolator
mainThe GemPy Engine 3 redesign focuses on creating an independent interpolator system designed for scalability and modularity. Key architectural goals include:
- Microservice Readiness: The interpolator is designed to be independent, allowing it to function as a microservice via a sync function that sets up constant values.
- Backend Compatibility: Support for multiple backends including TensorFlow, Numpy, and Aesara.
- Scalar Field Independence: Each scalar field operates without global constants (e.g., each field has its own range) and supports Scalar field injection, allowing recursive values from one field to be accessed by the next.
- Native Octrees: Octrees are natively supported; they can be deactivated by setting the number of levels to 1.
- Multiple Solvers: Support for various solvers including cuda solver, gradient solver, and sparse solver.
- Scalable Outputs: The engine uses a single interpolator capable of selecting how much of the graph to construct at compile time, improving upon the GemPy 2.1 approach of having multiple interpolator objects.
How GemPy's interpolation approach works
mainGemPy uses a universal cokriging method to interpolate a 3D scalar field, where geologically significant interfaces are represented as isosurfaces. The algorithm integrates two primary types of geological input data:
- Surface contact points: 3D coordinates marking boundaries between features (e.g., layer interfaces, fault planes, unconformities).
- Orientation measurements: The orientation of poles perpendicular to the dipping of surfaces at specific points in 3D space.
Users can also define topological elements, such as combining multiple stratigraphic sequences or complex fault networks, to guide the modeling process.
Use GemPy for forward geophysics and probabilistic inversion
mainGemPy provides built-in functionality for forward geophysics. While it is not designed as a package for classical geophysical inversion, it is optimized for probabilistic inversion. To support this, the geophysics tools are designed to be fast and differentiable, allowing for efficient estimation of geological models through probabilistic frameworks.Visualize GemPy models
mainGemPy supports multiple visualization methods:
- 2D Visualization: Direct visualization of 2D model sections or geological maps using
matplotlib. This includes support for hillshading and other intuitive representation options. - 3D Visualization: Interactive 3D plots using
Pyvista.
- 2D Visualization: Direct visualization of 2D model sections or geological maps using
Install GemPy viewer for 2D and 3D visualization
mainFor 2-D and 3-D visualization, install the
gempy-viewerpackage:$ pip install gempy-viewerNote on 3-D Visualization: 3-D visualization relies on
pyvista, which must be installed separately. Refer to the PyVista installation guide for instructions.Update documentation using Sphinx
mainGemPy documentation is built offline using Sphinx and Sphinx Gallery. To update and preview documentation locally:
- Ensure
sphinxandsphinx-galleryare installed. - Navigate to the documentation directory:
cd docs. - Build the HTML documentation:
make html. - Preview the output by opening
docs/build/html/index.htmlin a web browser.
cd docs make html- Ensure
Install GemPy via pip
mainInstall the latest stable release of GemPy using PyPI. It is highly recommended to use the
[base]extra to ensure necessary dependencies are included.Note: GemPy v3 is the current stable version. If you require workflows from previous versions, you must use
gempy_legacyinstead.$ pip install gempy[base]Release a new version of GemPy
mainTo release a new version, follow these steps to update versioning, tag the repository, and upload to PyPI:
- Update Versioning: Set the new version number in
setup.py,gempy/__init__.py, and the Sphinx documentation configuration. - Update Requirements: Ensure
requirements.txt,optional_requirements.txt, anddev_requirements.txtset minimum versions or reject incompatible versions. - GitHub Release: Tag the release and push the tag to the origin.
git tag X.X -m "Add X.X tag for PyPI" git push --tags origin master - PyPI Release: Build the distribution and upload using
twine.python -m build twine upload dist/*
# add new tag $ git tag X.X -m "Add X.X tag for PyPI" # push git tag $ git push --tags origin master # First create the dist python -m build # Second upload the distributions twine upload dist/*- Update Versioning: Set the new version number in