GemPy Documentation

repository·main·Indexed 23 days ago

https://github.com/gempy-project/gempy

An 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.

Tokens
5.1K
Snippets
12
Records
33
Agent score
79%

What's inside GemPy

  1. Overview of GemPy

    main
    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.
  2. Geological features supported by GemPy

    main

    GemPy 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.
  3. How GemPyTensor handles backend abstraction

    main

    To maintain a single graph implementation while supporting different computational backends (Numpy, Aesara, TensorFlow), GemPy uses a GemPyTensor wrapper. This wrapper provides a unified syntax for common operations, even when the underlying package syntax differs (e.g., handling set_subtensor which 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)
  4. Design principles of the GemPy Engine 3 interpolator

    main

    The 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.
  5. How GemPy's interpolation approach works

    main

    GemPy 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.

  6. Use GemPy for forward geophysics and probabilistic inversion

    main
    GemPy 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.
  7. Visualize GemPy models

    main

    GemPy 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.
  8. Update documentation using Sphinx

    main

    GemPy documentation is built offline using Sphinx and Sphinx Gallery. To update and preview documentation locally:

    1. Ensure sphinx and sphinx-gallery are installed.
    2. Navigate to the documentation directory: cd docs.
    3. Build the HTML documentation: make html.
    4. Preview the output by opening docs/build/html/index.html in a web browser.
    cd docs
    make html
  9. Install GemPy via pip

    main

    Install 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_legacy instead.

    $ pip install gempy[base]
  10. Release a new version of GemPy

    main

    To release a new version, follow these steps to update versioning, tag the repository, and upload to PyPI:

    1. Update Versioning: Set the new version number in setup.py, gempy/__init__.py, and the Sphinx documentation configuration.
    2. Update Requirements: Ensure requirements.txt, optional_requirements.txt, and dev_requirements.txt set minimum versions or reject incompatible versions.
    3. 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
    4. 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/*