Skip to main content

Apply the LLNL-G3D-JPS resolution matrix to velocity models.

Project description

llnltofi

A Python package for tomographic filtering of seismic mantle structure ($v_S$ or $v_P$) using the resolution matrix $R$ of the LLNL-G3D-JPS model by Simmons et al. (2015). Given a velocity model on the LLNL grid, llnltofi applies the resolution operator via a single sparse matrix-vector multiply $Rm = m'$ and returns the filtered result.

Author: Sia Ghelichkhan (sia.ghelichkhani@anu.edu.au)

Installation

pip install -e .

Dependencies are just numpy and scipy. For running the example scripts you will also need matplotlib, seaborn, pandas, xarray, and netCDF4, which can be installed with:

pip install -e ".[examples]"

Quick start

import llnltofi

model = llnltofi.ResolutionModel()

# Get grid coordinates as (lon, gc_lat, depth_km)
coords = model.coordinates_in_lonlatdepth  # shape (1_003_608, 3)

# Or as Cartesian (x, y, z) in metres
xyz = model.coordinates_in_xyz  # shape (1_003_608, 3)

# Evaluate your model at these points and compute slowness perturbation
# du = 1/v_3D - 1/v_1D at each grid point
model.values = ...  # shape (1_003_608,)

# Apply the resolution matrix
du_filtered = model.apply()  # shape (1_003_608,)

An interpolation helper is also provided for projecting an arbitrary point cloud onto the LLNL grid:

from llnltofi.interpolation import project_onto_grid

du = project_onto_grid(source_points, source_values, model)  # shape (1_003_608,)

Correctness note

This package is a modern reimplementation of LLNL_ToFi by Bernhard Schuberth (LMU Munich). The original code performed the filtering by looping over the sparse matrix entries element by element, converting each 1-based global column index back to a (layer, coordinate) pair using integer division and modulo arithmetic:

c_index = np.mod(cj, np_UM_TZ) - 1
l_index = cj // np_UM_TZ

This mapping has a boundary bug. Whenever cj is an exact multiple of the layer size (40,962 for upper-mantle/transition-zone layers, 10,242 for lower-mantle layers), the modulo returns zero, c_index becomes $-1$, and l_index is off by one. Python silently wraps the $-1$ to the last array element, so the code reads a value from the wrong depth layer without raising any error. Cross-validation against the original text files shows that 2,357 out of 75,508,775 R-matrix entries fall on these boundary columns, producing errors in 1,107 output grid points (0.11 % of the model vector) with absolute differences up to $\approx 0.15$.

llnltofi avoids the problem entirely by pre-converting the 44 layer text files into a single scipy.sparse CSR matrix with straightforward 0-based indexing (col = cj - 1). The filtering step becomes a single call to scipy.sparse.csr_matrix @ numpy.ndarray, delegating all index arithmetic to well-tested library code. A cross-validation test suite (tests/test_equivalence.py) confirms that the bundled R.npz is bit-for-bit identical to one freshly assembled from the original text files and that model.apply() reproduces the correct matrix-vector product.

Data

All required data files, including the grid coordinates and the resolution matrix, are hosted on S3 and downloaded automatically on first use. There is nothing to configure — just pip install the package and everything is fetched lazily when you first access model.R or the coordinate properties. Downloaded files are cached locally so subsequent runs are instant.

References

Simmons, N. A., Myers, S. C., Johannesson, G., Matzel, E., & Grand, S. P. (2015). Evidence for long-lived subduction of an ancient tectonic plate beneath the southern Indian Ocean. Geophysical Research Letters, 42(21), 9270-9278. https://doi.org/10.1002/2015GL066237

Simmons, N. A., Schuberth, B. S. A., Myers, S. C., & Knapp, D. R. (2019). Resolution and covariance of the LLNL-G3D-JPS global seismic tomography model: applications to travel time uncertainty and tomographic filtering of geodynamic models. Geophysical Journal International, 217(3), 1543-1557. https://doi.org/10.1093/gji/ggz102

License

License: GPL v3

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

llnltofi-0.1.0.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llnltofi-0.1.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file llnltofi-0.1.0.tar.gz.

File metadata

  • Download URL: llnltofi-0.1.0.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for llnltofi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e4571e6d918c946435a115c0f007b07325771be8dda67f49dced58127b8a6027
MD5 1311ea869daba9759e1ee55e52986c56
BLAKE2b-256 dad794fc1fd59e557e5ad4f09de6781c54f4cb1de5fbbfaaca15dbe9a707be34

See more details on using hashes here.

Provenance

The following attestation bundles were made for llnltofi-0.1.0.tar.gz:

Publisher: release.yml on sghelichkhani/llnltofi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llnltofi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llnltofi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for llnltofi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ecd5ec53e622512ebfaf12659b8354a65ca60783726d35da79bef44aada4c03e
MD5 0ecebdb2005fd826018ff0c2d8791580
BLAKE2b-256 03f63d794e6b12de8ebef32d415655be9dac9bfee2d54dc9a203b1b1ad7d5532

See more details on using hashes here.

Provenance

The following attestation bundles were made for llnltofi-0.1.0-py3-none-any.whl:

Publisher: release.yml on sghelichkhani/llnltofi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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