Skip to main content

Python bindings for the petra_grid crate

Project description

petra_grid

petra_grid is a Python library for reading grid data in the .GRD file format produced by the Petra™ geological interpretation application

petra_grid is implemented as a set of bindings to the corresponding Rust crate


This library is based on a lot of time spent in a hex editor looking at grid files and poring over publicly-available documentation. It is by necessity incomplete and incorrect, and will remain so until the file format is properly and publicly specified.

However, the library is able to successfully read rectangular and triangulated grids and a good portion of their metadata. Please open an issue if you have trouble reading a grid and are able to share the grid (in GRD and exported form) with the developer.


Example usage

This library can be used to read .GRD grid data from a file or file-like object. Here's a short program for dumping "debug" representations of grid files provided on the command line:

import sys

import petra_grid


def main(argv: list[str]) -> int:
    if len(argv) <= 1:
        print(f'Usage: {argv[0] if argv else "read_grid"} <grd-files>',
          file=sys.stderr)
        return 2

    for path in argv[1:]:
        with open(path, 'rb') as f:
            grid = petra_grid.read_grid(f)
            if grid.is_rectangular:
                print(f'{grid.name}: {grid.rows} x {grid.columns} rectangular grid')
            elif grid.is_triangular:
                print(f'{grid.name}: {grid.n_triangles}-triangle triangular grid')
            print(f'Details: {grid}')

    return 0


if __name__ == '__main__':
    sys.exit(main(sys.argv))

As another example, we can use matplotlib to render images of rectangular or triangular grids.

import sys

import petra_grid

import numpy as np

from matplotlib.tri import Triangulation # type: ignore
import matplotlib.pyplot as plt # type: ignore


def plot_rectangular(grid: petra_grid.Grid) -> None:
    plt.imshow(grid.data, extent=(grid.xmin, grid.xmax, grid.ymin, grid.ymax),
      origin='lower')
    plt.title(f'{grid.name}')
    plt.colorbar()
    plt.show()


def plot_triangular(grid: petra_grid.Grid) -> None:
    triangles = grid.data
    xs = np.ravel(triangles[:, :, 0])
    ys = np.ravel(triangles[:, :, 1])
    ixs = np.reshape(np.indices(xs.shape)[0], (triangles.shape[0], 3))
    triangulation = Triangulation(xs, ys, ixs)
    zs = np.ravel(triangles[:, :, 2])
    fig, ax = plt.subplots()
    ax.set_aspect('equal')
    tc = ax.tripcolor(triangulation, zs)
    ax.set_title(f'{grid.name}')
    fig.colorbar(tc)
    plt.show()


def main(argv: list[str]) -> int:
    if len(argv) <= 1:
        print(f'Usage: {argv[0] if argv else "render_grid"} <grd-files>',
          file=sys.stderr)
        return 2

    for path in argv[1:]:
        with open(path, 'rb') as f:
            grid = petra_grid.read_grid(f)
            if grid.is_rectangular:
                plot_rectangular(grid)
            elif grid.is_triangular:
                plot_triangular(grid)
            print(f'Details: {grid}')

    return 0


if __name__ == '__main__':
    sys.exit(main(sys.argv))

Documentation

Documentation strings and type annotations are provided for all public types, functions, and methods. We recommend viewing "nice" documentation pages using pdoc; e.g. in the same environment as the petra_grid package is installed, install pdoc with pip install pdoc, then run pdoc petra_grid.

Available under the MIT license

(c) 2023 dwt | terminus, LLC

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

petra_grid-1.0.0.tar.gz (11.9 kB view hashes)

Uploaded Source

Built Distributions

petra_grid-1.0.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

petra_grid-1.0.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

petra_grid-1.0.0-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

petra_grid-1.0.0-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

petra_grid-1.0.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

petra_grid-1.0.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

petra_grid-1.0.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

petra_grid-1.0.0-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

petra_grid-1.0.0-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

petra_grid-1.0.0-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

petra_grid-1.0.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

petra_grid-1.0.0-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

petra_grid-1.0.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

petra_grid-1.0.0-pp37-pypy37_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

petra_grid-1.0.0-pp37-pypy37_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

petra_grid-1.0.0-pp37-pypy37_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

petra_grid-1.0.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

petra_grid-1.0.0-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

petra_grid-1.0.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

petra_grid-1.0.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

petra_grid-1.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

petra_grid-1.0.0-cp311-none-win_amd64.whl (173.9 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

petra_grid-1.0.0-cp311-none-win32.whl (170.3 kB view hashes)

Uploaded CPython 3.11 Windows x86

petra_grid-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

petra_grid-1.0.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

petra_grid-1.0.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

petra_grid-1.0.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

petra_grid-1.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

petra_grid-1.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

petra_grid-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (296.5 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

petra_grid-1.0.0-cp311-cp311-macosx_10_7_x86_64.whl (304.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

petra_grid-1.0.0-cp310-none-win_amd64.whl (173.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

petra_grid-1.0.0-cp310-none-win32.whl (170.3 kB view hashes)

Uploaded CPython 3.10 Windows x86

petra_grid-1.0.0-cp310-cp310-manylinux_2_34_x86_64.whl (252.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

petra_grid-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

petra_grid-1.0.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

petra_grid-1.0.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

petra_grid-1.0.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

petra_grid-1.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

petra_grid-1.0.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

petra_grid-1.0.0-cp310-cp310-macosx_11_0_arm64.whl (296.5 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

petra_grid-1.0.0-cp310-cp310-macosx_10_7_x86_64.whl (304.6 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

petra_grid-1.0.0-cp39-none-win_amd64.whl (174.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

petra_grid-1.0.0-cp39-none-win32.whl (170.5 kB view hashes)

Uploaded CPython 3.9 Windows x86

petra_grid-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

petra_grid-1.0.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

petra_grid-1.0.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

petra_grid-1.0.0-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

petra_grid-1.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

petra_grid-1.0.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

petra_grid-1.0.0-cp38-none-win_amd64.whl (173.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

petra_grid-1.0.0-cp38-none-win32.whl (170.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

petra_grid-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

petra_grid-1.0.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

petra_grid-1.0.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

petra_grid-1.0.0-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

petra_grid-1.0.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

petra_grid-1.0.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

petra_grid-1.0.0-cp37-none-win_amd64.whl (173.8 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

petra_grid-1.0.0-cp37-none-win32.whl (170.3 kB view hashes)

Uploaded CPython 3.7 Windows x86

petra_grid-1.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

petra_grid-1.0.0-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.3 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ s390x

petra_grid-1.0.0-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ppc64le

petra_grid-1.0.0-cp37-cp37m-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARMv7l

petra_grid-1.0.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

petra_grid-1.0.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ i686

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page