Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pygeostats

Geostatistics for Python with a Rust-accelerated core. Variograms, kriging, point-pattern analysis and spatial autocorrelation, behind a familiar fit / predict API that accepts NumPy arrays, pandas DataFrames and GeoPandas GeoDataFrames.

PyPI Python versions Development status License: MIT CI Docs Rust core: PyO3 Ruff Code style: black

Documentation · Quickstart · API reference · Known limitations · Changelog · Issues

Alpha release. 0.1.0a2 is on PyPI as a pre-release. The API may still change, and some features are unfinished or unreliable: read the known limitations before relying on anisotropy analysis.

Highlights

  • A compiled core. Distances, empirical variograms, model fitting and kriging run in Rust, built with PyO3 and maturin.
  • The full workflow. Estimate a variogram, fit a model, krige with prediction variance, and cross-validate the result, all in one package.
  • Honest fits. When the data does not constrain a variogram model, fit() says so through converged_ and warnings_, instead of returning a range as though it were reliable.
  • Beyond kriging. Point-pattern statistics, spatial clustering and spatial autocorrelation share the same inputs.
  • Wheels for every major platform. One stable-ABI wheel per platform covers Python 3.11 to 3.14, with no Rust toolchain needed to install.
  • Tested documentation. Every example in the documentation and in this README runs as part of the test suite.

Installation

pip install pygeostats

pygeostats needs Python 3.11 or newer. While no stable release exists, pip installs the pre-release; after one does, use pip install --pre pygeostats to get pre-releases.

Optional extras:

Extra Adds For
plotting plotly interactive plots, with backend="plotly"
progress tqdm progress bars in the parallel executor
approx annoy approximate neighbour search
pip install "pygeostats[plotting]"

Wheels are published for:

Platform Architectures
Linux (manylinux2014) x86_64, aarch64
macOS x86_64 (10.12+), arm64 (11+)
Windows x86_64

Elsewhere, pip builds from the source distribution, which needs a Rust toolchain.

Quick start

Estimate a variogram from scattered samples, fit a model, and krige onto a grid:

import numpy as np
from pygeostats.kriging import OrdinaryKriging
from pygeostats.variogram import EmpiricalVariogram, Variogram

rng = np.random.default_rng(0)
coords = rng.uniform(0, 10, size=(100, 2))
values = np.sin(coords[:, 0]) + np.cos(coords[:, 1]) + rng.normal(0, 0.1, 100)

# 1. Empirical variogram: semivariance by distance bin
empirical = EmpiricalVariogram(coords, values, n_bins=12).compute()

# 2. Fit a model, and check that the fit can be trusted
model = Variogram(model="exponential")
model.fit(empirical.distances_, empirical.gamma_, weights=empirical.counts_)
print(model.converged_, model.nugget_, model.sill_, model.range_)

# 3. Krige onto a grid, with the prediction variance
xs = np.linspace(0, 10, 40)
grid_x, grid_y = np.meshgrid(xs, xs)
targets = np.column_stack([grid_x.ravel(), grid_y.ravel()])

kriging = OrdinaryKriging(model).fit(coords, values)
predictions, variance = kriging.predict(targets, return_variance=True)

Check how well the workflow predicts, holding out whole regions at a time:

from pygeostats.validation import (
    default_kriging_builder,
    default_variogram_builder,
    spatial_kfold_cross_validation,
)

cv = spatial_kfold_cross_validation(
    coords,
    values,
    default_variogram_builder("exponential"),
    default_kriging_builder(),
    n_splits=5,
    random_state=0,
)
print(cv.summary())  # {"rmse": ..., "r2": ...}

Point patterns and spatial autocorrelation work directly on coordinates and values:

from pygeostats import (
    morans_i,
    ripley_l_function,
    simulate_poisson_process,
    spatial_weights_knn,
)

# Ripley's L for a random pattern: close to r at every radius
points = simulate_poisson_process(200, bounds=(0.0, 1.0, 0.0, 1.0), random_state=0)
radii = np.linspace(0.01, 0.15, 15)
l_values = ripley_l_function(points, radii, area=1.0)

# Moran's I for the samples above, with a permutation test
weights = spatial_weights_knn(coords, k=8)
print(morans_i(values, weights, permutations=999, random_state=0))

The Quickstart walks through a complete workflow, including plots, and examples/basic_kriging.py, examples/variogram_fitting.py and examples/anisotropic_kriging_example.py are complete scripts.

Features

Module What it covers Guide
pygeostats.variogram Empirical and directional variograms; exponential, spherical and Gaussian models with a fit report; anisotropy detection; streaming and memory-mapped variograms Variograms, Anisotropy
pygeostats.kriging Ordinary, simple, universal and anisotropic kriging, with prediction variance; neighbour search Kriging, Large datasets
pygeostats.point_patterns Nearest neighbours; Ripley's K and L; G, F and pair correlation functions; DBSCAN; kernel density; Gi* hot spots; Poisson, Cox and marked process simulation; segregation indices Point patterns
pygeostats.spatial_autocorrelation Moran's I and Geary's C, global and local; Getis-Ord G and Gi*; k-nearest-neighbour, distance-band and inverse-distance weights Spatial autocorrelation
pygeostats.validation Leave-one-out, spatial k-fold and block cross-validation; model selection by AIC, BIC or leave-one-out; residual diagnostics Validation
pygeostats.utils matplotlib and plotly plots of variograms, kriging surfaces and diagnostics Plotting

Status and known limitations

pygeostats is alpha software. The variogram, kriging, point-pattern, autocorrelation and validation workflows are tested and documented, but:

  • Fitting an anisotropic model from directional variograms is not implemented. AnisotropicKriging works with parameters set by hand, and measures its rotation angle clockwise, unlike DirectionalVariogram.
  • Anisotropy estimates are rough. The ratio from detect_anisotropy() runs low, and on a few hundred samples the estimated axis can be tens of degrees off.
  • Matérn models cannot be fitted, only exponential, spherical and Gaussian ones.
  • Type annotations are incomplete, and mypy runs as an advisory CI step.

The known limitations page has the details and workarounds.

Development

A Rust toolchain is needed to build from source. The compiler version is pinned in rust-toolchain.toml, and rustup fetches it automatically.

git clone https://github.com/DiogoRibeiro7/pygeostats.git
cd pygeostats
pip install -e ".[dev,test]"

pytest tests/
black --check src/python/ tests/
ruff check src/python/ tests/
cargo test --no-default-features --features parallel

The development guide explains the checks and how to build the documentation.

Contributing

Bug reports, questions and pull requests are welcome in the issue tracker. See CONTRIBUTING.md for the workflow, and the Code of Conduct.

Name

This project was previously called pyspatialstats. It was renamed because that name belongs to an existing, actively maintained package on PyPI by Jasper Roebroek. The two are unrelated.

License

MIT. See LICENSE.

Release files for pygeostats 0.1.0a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygeostats 0.1.0a2
File Size Uploaded
pygeostats-0.1.0a2.tar.gz 203.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pygeostats 0.1.0a2
File
pygeostats-0.1.0a2-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
pygeostats-0.1.0a2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details
pygeostats-0.1.0a2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details
pygeostats-0.1.0a2-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
pygeostats-0.1.0a2-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size:2.7 MB

Release files / pygeostats-0.1.0a2.tar.gz

Download URL pygeostats-0.1.0a2.tar.gz
Size 203.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4844908b25da00eb879ed14b1732c59430a46b4cd780e28d4d8a0e8c67201ffb
BLAKE2b-256 checksum
How to use checksums
76c72f0f6853824f9905b423d0f7763830b7b429be5a511ed5198142ab17f012
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pygeostats-0.1.0a2-cp311-abi3-win_amd64.whl

Download URL pygeostats-0.1.0a2-cp311-abi3-win_amd64.whl
Size 457.6 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
91d6b9f8496c6d342a682b2139a62163d216fba97a462f023af0627b27f76a91
BLAKE2b-256 checksum
How to use checksums
c60384f95c3432b352b3a13c77226a99b781e1a717d4f4b0fddd12afc98c10d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pygeostats-0.1.0a2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pygeostats-0.1.0a2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 524.9 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
4afa6365c1630cbb802354d6dfcdc1de908af645469ccdcf419479bf4d959560
BLAKE2b-256 checksum
How to use checksums
91b907ac9df3d2fc2f01368864a37e50dc0c2ada73a51934a8c68614a2354f1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pygeostats-0.1.0a2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pygeostats-0.1.0a2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 496.7 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
f66e8a550c06fbbd6ec36e7e0759ef54d1071d4c5f127d59562ff9ff6b5e640f
BLAKE2b-256 checksum
How to use checksums
2f7a35762bc13b64c35cc6f3464775c72925f5975de780100feb64f6bc143581
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pygeostats-0.1.0a2-cp311-abi3-macosx_11_0_arm64.whl

Download URL pygeostats-0.1.0a2-cp311-abi3-macosx_11_0_arm64.whl
Size 476.3 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
79a4e1a6c8723266f2789111832e509c155225afbf20a49d1bf5b79ea8904a35
BLAKE2b-256 checksum
How to use checksums
dbe3535edd4faa8ee6ac5a9ced13340b9443b622ace53a38d45374724bc32fc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pygeostats-0.1.0a2-cp311-abi3-macosx_10_12_x86_64.whl

Download URL pygeostats-0.1.0a2-cp311-abi3-macosx_10_12_x86_64.whl
Size 492.1 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d3ba62a2484d091aad9a3a15cfb924a663a1795f7a875bd11ae1e697e975430a
BLAKE2b-256 checksum
How to use checksums
ac837ccaa2dc3ed69c8eec1f5259af04ccb032f121bf267a2ba26704ad5ba054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0a2 This release

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page