Registry / analytics / pykrige

pykrige

JSON →
library1.7.3pypypi✓ verified 84d ago

PyKrige is a Kriging Toolkit for Python that supports 2D and 3D ordinary and universal kriging, as well as simple kriging, regression kriging, and conditional realizations. It provides a scikit-learn compatible interface and is developed by the GeoStat Framework project. Current version: 1.7.3. Release cadence: irregular, with several updates per year.

pip install pykrige
INSTALL
IMPORT
SIG · PYKRIGE
P
pykrige
analyticspythonv1.7.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OrdinaryKriging
from pykrige.ok import OrdinaryKriging
from pykrige import OrdinaryKriging
Subpackages ok, uk, etc. must be explicit; top-level import raises AttributeError.
UniversalKriging
from pykrige.uk import UniversalKriging
from pykrige import UniversalKriging
Same as above; use subpackage import.
Krige
from pykrige.rk import RegressionKriging
RegressionKriging replaces older Krige; always use RegressionKriging.

Perform ordinary kriging on 2D synthetic data with a linear variogram model.

import numpy as np from pykrige.ok import OrdinaryKriging # Synthetic data np.random.seed(42) X = np.random.rand(20, 2) * 10 Z = np.sin(X[:, 0]) + np.cos(X[:, 1]) # Grid for prediction gridx = np.linspace(0, 10, 20) gridy = np.linspace(0, 10, 20) # Ordinary Kriging OK = OrdinaryKriging(X[:, 0], X[:, 1], Z, variogram_model='linear') z, ss = OK.execute('grid', gridx, gridy) print(z.shape, ss.shape)
Debug
Known issues
gotchaDo not use variogram_model='exponential' or 'gaussian' without checking data sparsity; they may produce singular matrix errors.
fix
Use 'linear' or 'spherical' as default; test other models on small datasets first.
affects: all
deprecatedThe old pykrige.kriging_tools module is deprecated. Use pykrige.tools instead.
fix
Replace 'from pykrige.kriging_tools import ...' with 'from pykrige.tools import ...'.
affects: >=1.6.0
gotchaWhen using the scikit-learn API, the fit() method requires additional keyword arguments beyond X, y (e.g., coordinates). Incorrect usage leads to unexpected errors.
fix
Always pass coordinate_data keyword: model.fit(X, y, coordinate_data=coords).
affects: all
Errors
Common errors & fixes
LinAlgError: Matrix is singular.
The kriging matrix (covariance matrix) is singular, often due to duplicate points or poorly chosen variogram model.
fix
Remove duplicate points using numpy.unique or adjust the variogram model (try 'linear').
AttributeError: module 'pykrige' has no attribute 'OrdinaryKriging'
Direct import from top-level pykrige, not from subpackage.
fix
Use 'from pykrige.ok import OrdinaryKriging'.
ValueError: The number of coordinates does not match the number of points.
Mismatch between coordinate array shape and data array shape in sklearn API.
fix
Ensure X is 2D (n_samples, n_features) and coordinate_data is 2D (n_samples, n_dims).
Upgrade
Version history
1.7.3latest on PyPI · released Oct 16, 2025
Audit
Dependencies
numpyrequiredArray operations and mathematical computations.
scipyrequiredSpatial distance calculations and optimization routines.
scikit-learnrequiredFor the sklearn-compatible Kriging interface.
Agent activity
37 hits · last 30 days
node
34
Resources
pykrige — pip install pykrige · libregistry