Spatialize: A Python/C++ library for Ensemble Spatial Analysis (ESA)
An open source library for spatial analysis that combines the simplicity of basic methods with the power of geostatistical tools.
Overview
Spatialize implements Ensemble Spatial Analysis (ESA), which encompasses two complementary approaches: Ensemble Spatial Interpolation (ESI) and Ensemble Spatial Simulation (ESS). These novel methods address the limitations of traditional geostatistical approaches by leveraging ensemble learning techniques.
ESI works by generating multiple estimates for each target location by creating different spatial partitions of the sample data and applying an interpolation algorithm within each local subset. These local estimates are then aggregated to produce robust predictions. ESS extends this framework to provide stochastic simulation capabilities.
Designed to bridge the gap between expert and non-expert users of geostatistics, Spatialize provides automated tools that eliminate the need for manual spatial analysis and extensive domain expertise.
Main features:
- Automated Spatial Estimation: Minimal user intervention required
- Stochastic Modelling & Ensemble Learning: Robust, scalable and suitable for large datasets
- Uncertainty Quantification: Provides both point estimates and empirical posterior distributions
- Flexible Data Support: Works with both gridded and non-gridded data
- Hyperparameter Optimization: Built-in grid search with cross-validation
- High Performance: C++ core with Python interface
Installation
The source code is currently hosted on GitHub at: https://github.com/alges/spatialize
Direct installers for the latest released version are available at the Python Package Index (PyPI).
PyPI
pip install spatialize
System Requirements
- Python 3.10+
- Compatible with Linux, macOS, and Windows
Dependencies
- NumPy: Powerful n-dimensional arrays and numerical computing tools
- pandas: Fast, powerful, flexible and easy to use open source data analysis and manipulation tool
- Matplotlib: Visualization with Python
- scikit-learn: Machine Learning in Python
- SciPy: Fundamental algorithms for scientific computing in Python
Core Concepts
| Function | Description |
|---|---|
esi_griddata() |
Spatial interpolation of continuous variables for points on a regular grid |
esi_nongriddata() |
Spatial interpolation of continuous variables for scattered points |
esi_hparams_search() |
Automated hyperparameter optimization with cross-validation |
esi_pareto_hparams_search() |
Balanced partitioning and interpolator parameter optimization via Pareto frontier |
cat_esi_griddata() |
Spatial interpolation of categorical variables for points on a regular grid |
cat_esi_nongriddata() |
Spatial interpolation of categorical variables for scattered points |
cat_esi_hparams_search() |
Automated hyperparameter optimization with cross-validation for categorical ESI |
ess_sample() |
Stochastic posterior simulation from an existing ESI ensemble |
Local Interpolators
- IDW (Inverse Distance Weighting): Simple yet powerful with configurable distance exponent
- Kriging: Geostatistical method with multiple variogram models (spherical, exponential, cubic and gaussian)
- Adaptive IDW: Automatically optimizes IDW parameters (exponent, anisotropy) per partition cell via leave-one-out validation — no manual tuning required
Note: Adaptive IDW is not a separate function — pass local_interpolator="adaptiveidw" to esi_griddata() / esi_nongriddata().
Local Classifiers
- knn_pca: Adaptive anisotropic k-NN, the default classifier for categorical ESI
- scikit-learn: Wraps any fitted scikit-learn estimator (e.g. SVM, Random Forest, Decision Tree)
Partition Methods
- Mondrian Forests: Uses recursive, axis-aligned partitions (supports up to 5D)
- Voronoi Forests: Uses Voronoi diagram-based partitions (supports up to 2D)
Quick Start
Here are a few examples to get you started. For further examples, please check the spatialize examples repository or the spatialize documentation.
Basic Gridded Data Estimation
import numpy as np
from spatialize.gs.esi import esi_griddata
# Generate sample data
def func(x, y): # a kind of "cubic" function
return x * (1 - x) * np.cos(4 * np.pi * x) * np.sin(4 * np.pi * y ** 2) ** 2
points = np.random.random((100, 2))
values = func(points[:, 0], points[:, 1])
# Define the estimation grid
grid_x, grid_y = np.mgrid[0:1:50j, 0:1:50j]
# Perform ESI estimation
result = esi_griddata(points, values, (grid_x, grid_y),
local_interpolator="idw",
p_process="mondrian",
n_partitions=300,
alpha=0.8,
exponent=1.0
)
# Get results
estimation = result.estimation()
precision = result.precision()
# Quick visualization
result.quick_plot()
Non-gridded Data Estimation
from spatialize.gs.esi import esi_nongriddata
# Define target locations
target_points = np.random.random((50, 2))
# Perform estimation, using Kriging as local interpolator
result = esi_nongriddata(points, values, target_points,
local_interpolator="kriging",
model="spherical",
nugget=0.1,
range=10.0,
sill=1.0
)
Automated Hyperparameter Search
from spatialize.gs.esi import esi_hparams_search
# Search for optimal parameters
search_result = esi_hparams_search(points, values, (grid_x, grid_y),
local_interpolator="idw",
griddata=True,
k=10,
exponent=[1.0, 2.0, 3.0, 4.0],
alpha=[0.7, 0.8, 0.9],
n_partitions=[100, 300, 500]
)
# Perform estimation using best parameters found
best_result = esi_griddata(points, values, (grid_x, grid_y),
local_interpolator="idw",
best_params_found=search_result.best_result()
)
# Visualize search results
search_result.plot_cv_error()
Adaptive ESI
from spatialize.gs.esi import esi_griddata
# Adaptive IDW optimizes exponent and anisotropy per partition cell automatically,
# so no exponent/alpha-per-axis tuning is required
result = esi_griddata(points, values, (grid_x, grid_y),
local_interpolator="adaptiveidw",
n_partitions=200,
alpha=0.7
)
result.quick_plot()
Categorical ESI
import numpy as np
from spatialize.gs.cat_esi import cat_esi_nongriddata
cat_points = np.array([[0.1, 0.2], [0.5, 0.6], [0.8, 0.1]])
cat_values = np.array(['A', 'B', 'A'])
cat_targets = np.array([[0.3, 0.3], [0.7, 0.7]])
result = cat_esi_nongriddata(cat_points, cat_values, cat_targets,
classifier="knn_pca",
n_partitions=300,
alpha=0.8
)
print(result.estimation()) # predicted categories
print(result.precision()) # per-location agreement ratio
Ensemble Spatial Simulation (ESS)
from spatialize.gs.ess import ess_sample
from spatialize.empirical import FittedModelFactory
# ess_sample draws posterior simulations from an existing ESI ensemble
sim_result = ess_sample(esi_result=result,
n_sims=1000,
fitted_model_factory=FittedModelFactory(
point_model_name="kde",
kernel="tophat"
)
)
License
Citing Spatialize
Please refer to the following articles when publishing work relating to this library or the ESI model:
@article{spatialize2026,
author = {Navarro, Felipe and Ega{\~n}a, {\'A}lvaro F. and Ehrenfeld, Alejandro and Garrido, Felipe and Valenzuela, Mar{\'i}a Jes{\'u}s and S{\'a}nchez-P{\'e}rez, Juan F. },
title = {Spatialize v1.0: a Python/C++ library for ensemble spatial interpolation},
journal = {Geoscientific Model Development},
year = {2026},
volume = {19},
number = {10},
pages = {4633--4660},
doi = {https://doi.org/10.5194/gmd-19-4633-2026},
url = {https://gmd.copernicus.org/articles/19/4633/2026/},
issn = {}
}
@article{
title = {Spatial distributional estimation via ensemble spatial analysis},
journal = {AIMS Mathematics},
volume = {10},
number = {11},
pages = {26351-26388},
year = {2025},
issn = {2473-6988},
doi = {10.3934/math.20251159},
url = {https://www.aimspress.com/article/doi/10.3934/math.20251159},
author = {Alvaro F. Ega{\~n}a and Gonzalo D{\'i}az and Felipe Navarro and Mohammad Maleki and Juan F. S{\'a}nchez-P{\'e}rez},
keywords = {geostatistics, computational geostatistics, generative geostatistics, non-linear geostatistics, distributional geostatistics, geostatistical simulation, empirical copula, data-driven methods},
}
@article{AdaptiveESI2025,
author = {Ega{\~n}a, {\'A}lvaro F. and Valenzuela, María Jesús and Maleki, Mohammad and S{\'a}nchez-P{\'e}rez, Juan F. and Díaz, Gonzalo},
title = {Adaptive ensemble spatial analysis},
journal = {Scientific Reports},
year = {2025},
volume = {15},
number = {1},
pages = {26599},
doi = {10.1038/s41598-025-08844-z},
url = {https://doi.org/10.1038/s41598-025-08844-z},
issn = {2045-2322}
}
@article{ESI2021,
author = {Ega{\~n}a, {\'A}lvaro F. and Navarro, Felipe and Maleki, Mohammad and Grand{\'o}n, Francisca and Carter, Francisco and Soto, Fabi{\'a}n},
title = {Ensemble Spatial Interpolation: A New Approach to Natural or Anthropogenic Variable Assessment},
journal = {Natural Resources Research},
volume = {30},
number = {5},
pages = {3777--3793},
year = {2021},
doi = {https://doi.org/10.1007/s11053-021-09860-2},
url = {https://link.springer.com/article/10.1007/s11053-021-09860-2}
}
Metadata
Release files for spatialize 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spatialize-1.3.0.tar.gz | 58.1 MB | With provenance | Details for spatialize-1.3.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| spatialize-1.3.0-cp314-cp314-win_amd64.whl | CPython 3.14 | CPython 3.14 | Windows x86-64 | Details for spatialize-1.3.0-cp314-cp314-win_amd64.whl |
| spatialize-1.3.0-cp314-cp314-musllinux_1_2_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux musl 1.2+ x86-64 | Details for spatialize-1.3.0-cp314-cp314-musllinux_1_2_x86_64.whl |
| spatialize-1.3.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details for spatialize-1.3.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
| spatialize-1.3.0-cp314-cp314-macosx_26_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 26.0+ ARM64 | Details for spatialize-1.3.0-cp314-cp314-macosx_26_0_arm64.whl |
| spatialize-1.3.0-cp313-cp313-macosx_14_0_x86_64.whl | CPython 3.13 | CPython 3.13 | macOS 14.0+ x86-64 | Details for spatialize-1.3.0-cp313-cp313-macosx_14_0_x86_64.whl |
Total release size: 354.2 MB
Release files / spatialize-1.3.0.tar.gz
| Download URL | spatialize-1.3.0.tar.gz |
|---|---|
| Size | 58.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c38662e09bf2bfdd1e65d0a4fdb29d0e785f3e56a929cd506ee8d9c659c5fba
|
|
BLAKE2b-256 checksum How to use checksums |
16c9c8aaae368f72845cf9b1606c9356972091882ba4fcd958086fe7d527b9d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 23, 2026.
Transparency logRelease files / spatialize-1.3.0-cp314-cp314-win_amd64.whl
| Download URL | spatialize-1.3.0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 58.7 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1c94bf1b08b51e25c1e62c6c69df789f9840dc87d81b64827f82009133f18e61
|
|
BLAKE2b-256 checksum How to use checksums |
f1e47ddb48c57309f8ae97a5578c14cee540a38740f7cc478128471861e668c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 23, 2026.
Transparency logRelease files / spatialize-1.3.0-cp314-cp314-musllinux_1_2_x86_64.whl
| Download URL | spatialize-1.3.0-cp314-cp314-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 60.1 MB |
| Tags | CPython 3.14 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
f591add3408fc75c4d55206640397067cd6bf7480ef1bf60394447bb77ba9336
|
|
BLAKE2b-256 checksum How to use checksums |
046671161e251a4b3a28fb034e11b418f69913d5549bfe17134fda9c3fb18611
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 23, 2026.
Transparency logRelease files / spatialize-1.3.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | spatialize-1.3.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 59.0 MB |
| Tags | CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
3f773b6a2a2a18ed08fd3045b89bd546f55b846b78947056f731442c746e912d
|
|
BLAKE2b-256 checksum How to use checksums |
a476b0aad6d228dccc8727d41b451a8ee9e66cf871925549ccfcf1ab53dd28b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 23, 2026.
Transparency logRelease files / spatialize-1.3.0-cp314-cp314-macosx_26_0_arm64.whl
| Download URL | spatialize-1.3.0-cp314-cp314-macosx_26_0_arm64.whl |
|---|---|
| Size | 59.1 MB |
| Tags | CPython 3.14 macOS 26.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8dd3d687d2a1b4c195388d8908312a91e245539cad12f9fb13598911241192b3
|
|
BLAKE2b-256 checksum How to use checksums |
946e89e4c08d01bbf1558b20ea904dbf56d2df2febe36a0e492e56927219609a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 23, 2026.
Transparency logRelease files / spatialize-1.3.0-cp313-cp313-macosx_14_0_x86_64.whl
| Download URL | spatialize-1.3.0-cp313-cp313-macosx_14_0_x86_64.whl |
|---|---|
| Size | 59.2 MB |
| Tags | CPython 3.13 macOS 14.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
6dbb0e11a44355a6101eb622952bd8d22db5db6762345ee57cf4f3483fe60969
|
|
BLAKE2b-256 checksum How to use checksums |
328fb750c84ccab217e9d39a03b2df814b999f0c275a37657bda90f26e584c85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 23, 2026.
Transparency logSecurity for spatialize 1.3.0
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.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for spatialize-1.3.0.tar.gz
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 Oct 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.