Skip to content

ewencai/gravtools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gravtools — Python Gravity Exploration Toolkit

Python License

gravtools is a Python library for gravity and magnetic exploration geophysics. Forward modeling, terrain correction, full tensor gravity gradiometry (FTG), and GPU acceleration — all in one package.

Why gravtools?

  • Physics-first: Proper Nagy (1966) prism formulas, not approximations
  • GPU-ready: Batch forward modeling on GPU via PyTorch — 100x speedup
  • Complete workflow: From raw gravity → Free-air → Bouguer → Terrain → CBA
  • FTG support: Full tensor gravity gradiometry (Txx, Txy, Txz, Tyy, Tyz, Tzz)

Installation

pip install gravtools
pip install gravtools[torch]   # GPU acceleration
pip install gravtools[viz]     # visualization

Quick Start

import gravtools as gt
import numpy as np

# Forward model: a dense ore body
x = np.linspace(0, 1000, 101)
y = np.linspace(0, 1000, 101)
X, Y = np.meshgrid(x, y)
prism = (300, 700, 300, 700, 50, 200)  # x1,x2,y1,y2,z1,z2 (m)
gz = gt.gravity_prism(X.ravel(), Y.ravel(), 0, prism, density=500)

# Plot
gt.gravity_map(X, Y, gz.reshape(101, 101), title="Ore Body Gravity")

Components

Forward Modeling

gz = gt.gravity_prism(x, y, z, prism, density)           # Vertical gravity
gx = gt.gravity_prism(x, y, z, prism, density, "gx")     # Horizontal
txx = gt.gravity_prism(x, y, z, prism, density, "txx")   # FTG: Txx
tzz = gt.gravity_prism(x, y, z, prism, density, "tzz")   # FTG: Tzz
gz = gt.gravity_sphere(x, y, z, x0, y0, z0, r, density)  # Sphere

Gravity Corrections

fa = gt.free_air_correction(elevation)
ba = gt.bouguer_correction(elevation, density=2670)
tc = gt.terrain_correction(x, y, elev, dem_x, dem_y, dem_z)
cba = gt.complete_bouguer_anomaly(gobs, elev, lat)
gt_norm = gt.theoretical_gravity(latitude)

GPU Acceleration

gz = gt.gravity_prisms_batch(
    x, y, z,
    prisms=prisms_array,     # (N, 6)
    densities=densities,      # (N,)
    device="cuda"             # or "cpu"
)

Supported Body Types

Shape Formula FTG
Rectangular prism Nagy (1966, 2002) ✅ Txx-Tzz
Sphere Point mass -
Horizontal cylinder 2D line source -

License

GPL v2 — see LICENSE


Built for exploration geophysicists who code.

Releases

No releases published

Packages

 
 
 

Contributors

Languages