Skip to main content

gstlearn: The Geostatistics & Machine Learning Python Package

License DOI

The gstlearn Python package is a cross-platform Python package wrapping the gstlearn C++ Library. It offers to Python users all famous Geostatistical methodologies developed and/or invented by the Geostatistic Team of the Geosciences Research Center!

More details for gstlearn are available here: https://gstlearn.org

If you need to plot gstlearn outputs, you can import gstlearn.plot module which is based on matplotlib.

References

The gstlearn Python package is a Python wrapper of the gstlearn C++ Library.

This package contains a copy of doxy2swig python script (see LICENSE.doxy2swig in doc folder).

The gstlearn Python package is a derivative work based on the swigex0 project: https://github.com/fabien-ors/swigex0

How to cite

When using the gstlearn Python Package, please, use this to cite us in any publication or results for which gstlearn has been used:

DOI

You may be interested in the citation file gstlearn.bib

Installation

For using this Python package you only need Python 3.8 (or higher) (with numpy, pandas and matplotlib) and execute the following command:

pip install gstlearn

For installing a prerelease version:

pip install --pre --force-reinstall gstlearn

The gstlearn.plot Python module requires additional dependencies, those can be installed alongside gstlearn with the following command:

pip install gstlearn[plot]

Converting several gstlearn C++ types through toTL methods to, e.g., Pandas DataFrames also require additional dependencies. These are available through the conv optional dependency group:

pip install gstlearn[conv]

All optional dependencies can be installed with the following command:

pip install gstlearn[all]

Usage

We refer the reader to this course page for an introduction and important information about Python gstlearn package.

Simply import the gstlearn Python package and its plot module, then enjoy:

# Import packages
import numpy as np
import matplotlib.pyplot as plt
import gstlearn as gl
import gstlearn.plot as gp
# Grid size
nx = 60
ny = 30
mygrid = gl.DbGrid.create([nx,ny],[1,1])
# Add a gaussian random field
var = np.random.randn(nx * ny)
mygrid.addColumns(var, "var1", gl.ELoc.Z)
# Display the field
gp.raster(mygrid)
gp.decoration(title="Gaussian random field")
plt.show()

Some tutorials (Jupyter Notebooks) are provided in the demo directory here and their HTML rendering is provided here.

Some tests (Python scripts) are available in the tests directory of the gstlearn github repository.

Known caveats

If you experience the following error while importing gstlearn package under Python:

RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xe

... you may need to upgrade numpy:

python -m pip install --upgrade numpy

Documentation

The classes and functions documentation is provided with the gstlearn C++ library as html files generated by Doxygen. Please, refer to gstlearn C++ library API See here for more details. Only the public methods are exported by SWIG and must be considered in the Python package.

Changelog

Please, look at CHANGES file.

Development

Requirements

For building the gstlearn Python package, the requirements for compiling gstlearn C++ library must be installed beforehand. Then, the following additional tools must be also available:

  • SWIG 4 or higher
  • Python 3 or higher with uv and numpy modules installed

If you modified your system, you must reinstall the requirements from scratch following next instructions. You must delete 'gstlearn' existing source folders (if so).

Note :

Linux (Ubuntu)

  1. Install gstlearn C++ library requirements for Linux here

  2. Then, execute the following commands:

sudo apt install python3
sudo apt install python3-pip
sudo apt install swig
python3 -m pip install numpy uv

MacOS

  1. Install gstlearn C++ library requirements for MacOS here

  2. Then, execute the following commands (Not tested):

brew install python3
brew install swig
python3 -m pip install numpy uv

Notes:

  • These instructions for MacOS are currently not tested - above packages may not exist

Windows

Install all tools
  1. Install gstlearn C++ library requirements for Windows (Microsoft Visual Studio) here

  2. Then, download and install the following tools using default options during installation:

  • Python 3+ from here (Windows installer [exe] - check 'Add python.exe to PATH' in the first panel)
  • SWIG 4+ from here (swigwin archive [zip], archive file to be extracted in a folder of your choice, but not in the gstlearn source folder - remind the installation folder, assume it is C:\swigwin-4.1.0))
  1. Then, install additional Python modules by running following instructions in a command prompt:
python -m pip install numpy uv
Update the Path environment variable

The Path environment variable (System variables) must be updated to make swig.exe available in the batch command line:

  1. Follow this guide to add SWIG installation folders in the Path System variable (i.e: C:\swigwin-4.1.0)
  2. Restart Windows

Installation from Source

  1. For getting the gstlearn Python package sources files, just clone the github repository:
git clone https://github.com/gstlearn/gstlearn.git
cd gstlearn

Next time, you will only need to pull the repository (If you have some local undesirable modifications, you have to revert them and execute the pull, otherwise do not execute git reset):

cd gstlearn
git reset --hard
git pull
  1. Then, these instructions will compile and install the gstlearn Python package in your usual Python site-packages directory.

GCC, Clang, ...

...or any other single configuration compilers:

cmake -Bbuild -S. -DBUILD_PYTHON=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --target python_install

or for those who prefer a single command line:

mkdir -p build & cd build & cmake .. -DBUILD_PYTHON=ON & make python_install

or even faster:

make python_install

Microsoft Visual Studio, ...

...or any other multiple configurations compilers:

cmake -Bbuild -S. -DBUILD_PYTHON=ON
cmake --build build --target python_install --config Release

Execute Non-regression Tests

The check* targets bring some required runtime customization, so do not use the standard ctest command for triggering the non-regression tests.

To build and launch non-regression Python tests, you need to execute the following command:

GCC, Clang, MinGW, ...

...or any other single configuration compiler:

cmake --build build --target check_py
cmake --build build --target check_ipynb

or even faster:

make check_py
make check_ipynb

Microsoft Visual Studio, ...

...or any other multiple configurations compiler:

cmake --build build --target check_py --config Release
cmake --build build --target check_ipynb --config Release

Important Notes

  • If your system distribution repository doesn't provide minimum required versions, please install the tools manually (see provider website)
  • You may need to reconnect to your session after installing some requirements
  • If you plan to generate the documentation, add -DBUILD_DOC=ON to the first cmake command above.
  • If you don't know how to execute github commands, you may read this.
  • Using Visual Studio on a Windows where MinGW is also installed may need to add -G "Visual Studio 16 2019" in the first command (adapt version).
  • The Windows C++ Compiler used must be the same that the one used for compiling Python (Visual C++). Using another compiler than Visual C++ is not supported.
  • If you want to build and install the Debug version, you must replace Release by Debug above
  • You may need to precise the location of Boost, Eigen3, SWIG, Doxygen, HDF5 or NLopt installation directory. In that case, add the following variables in the first cmake command above:
    • -DBoost_ROOT="path/to/boost"
    • -DEigen3_ROOT="path/to/eigen3"
    • -DSWIG_ROOT="path/to/swig"
    • -DDoxygen_ROOT="path/to/doxygen"
    • -DHDF5_ROOT="path/to/hdf5"
    • -DNLopt_ROOT="path/to/nlopt"

Remove Installed Package

To uninstall the gstlearn Python package, execute following command:

python3 -m pip uninstall gstlearn

Note : You may need to directly modify your site-packages folder by:

  • Removing the reference to the old gstlearn package version (see this topic)
  • Removing a line which contains gstlearn in the ./easy-install.pth file of the site-packages folder
  • Removing all directories starting with '~stlearn from the site-packages folder

License

BSD 3-clause

2025 Team gstlearn

Metadata

Release files for gstlearn 1.11.1

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

Built distributions (wheels)

Table of built distributions (wheels) for gstlearn 1.11.1
File
gstlearn-1.11.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
gstlearn-1.11.1-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details
gstlearn-1.11.1-cp310-abi3-macosx_15_0_x86_64.whl CPython 3.10 abi3 macOS 15.0+ x86-64 Details
gstlearn-1.11.1-cp310-abi3-macosx_14_0_arm64.whl CPython 3.10 abi3 macOS 14.0+ ARM64 Details

Total release size: 36.2 MB

Release files / gstlearn-1.11.1-cp310-abi3-win_amd64.whl

Download URL gstlearn-1.11.1-cp310-abi3-win_amd64.whl
Size 8.7 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
bf0fa230bb2384b6d8eca830a059351ee05714f9b2c16348a1a4ab27c4fdfcc9
BLAKE2b-256 checksum
How to use checksums
9426615f36a77964df559947242924c167772e431052b836aadf0a4a35ed1ce3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / gstlearn-1.11.1-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL gstlearn-1.11.1-cp310-abi3-manylinux_2_28_x86_64.whl
Size 10.5 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
635fb13585af1cfc42791ffa66d578446f0183d8450504c54fb38c01015c4ac2
BLAKE2b-256 checksum
How to use checksums
bbde87b9d360f454ee3bb80239603b051f6698fd284615a93dbc1298583549e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / gstlearn-1.11.1-cp310-abi3-macosx_15_0_x86_64.whl

Download URL gstlearn-1.11.1-cp310-abi3-macosx_15_0_x86_64.whl
Size 8.9 MB
Tags CPython 3.10 abi3 macOS 15.0+ x86-64
SHA-256 checksum
How to use checksums
a991b044d2af06964511544de98b5ede7428b3f555986b7b09e1cfd0395d2b65
BLAKE2b-256 checksum
How to use checksums
6461650dde1c63b25cf26344411f04efa0351da0cbeaf265fe0b13fadd08a2e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / gstlearn-1.11.1-cp310-abi3-macosx_14_0_arm64.whl

Download URL gstlearn-1.11.1-cp310-abi3-macosx_14_0_arm64.whl
Size 8.0 MB
Tags CPython 3.10 abi3 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
5f6a7f524e9bf6c171def663e78f90778956964f66f16319cafeebf290bb7bef
BLAKE2b-256 checksum
How to use checksums
0088544e7c44c8fb5e4f14147482b91ca8e46321ac189b84720b5a4fe547259c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3
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