gstools

GSTools - A geostatistical toolbox: random fields, variogram estimation, covariance models, kriging and much more

https://github.com/geostat-framework/gstools

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 15 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.3%) to scientific vocabulary

Keywords

covariance-model geospatial geostatistics kriging python science spatio-temporal srf statistics variogram variogram-estimation
Last synced: 6 months ago · JSON representation ·

Repository

GSTools - A geostatistical toolbox: random fields, variogram estimation, covariance models, kriging and much more

Basic Info
  • Host: GitHub
  • Owner: GeoStat-Framework
  • License: lgpl-3.0
  • Language: Python
  • Default Branch: main
  • Homepage: https://geostat-framework.org
  • Size: 17.7 MB
Statistics
  • Stars: 612
  • Watchers: 16
  • Forks: 75
  • Open Issues: 24
  • Releases: 29
Topics
covariance-model geospatial geostatistics kriging python science spatio-temporal srf statistics variogram variogram-estimation
Created about 8 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog Contributing License Citation Authors Zenodo

README.md

Welcome to GSTools

GMD DOI PyPI version Conda Version Build Status Coverage Status Documentation Status Code style: black

GSTools-LOGO

Get in Touch!

GH-Discussions Email

Youtube Tutorial on GSTools

GSTools Transform 22 tutorial

Purpose

GSTools provides geostatistical tools for various purposes: - random field generation, including periodic boundaries - simple, ordinary, universal and external drift kriging - conditioned field generation - incompressible random vector field generation - (automated) variogram estimation and fitting - directional variogram estimation and modelling - data normalization and transformation - many readily provided and even user-defined covariance models - metric spatio-temporal modelling - plurigaussian field simulations (PGS) - plotting and exporting routines

Installation

conda

GSTools can be installed via conda on Linux, Mac, and Windows. Install the package by typing the following command in a command terminal:

conda install gstools

In case conda forge is not set up for your system yet, see the easy to follow instructions on conda forge. Using conda, the parallelized version of GSTools should be installed.

pip

GSTools can be installed via pip on Linux, Mac, and Windows. On Windows you can install WinPython to get Python and pip running. Install the package by typing the following command in a command terminal:

pip install gstools

To install the latest development version via pip, see the documentation. One thing to point out is that this way, the non-parallel version of GSTools is installed. In case you want the parallel version, follow these easy steps.

Citation

If you are using GSTools in your publication please cite our paper:

Müller, S., Schüler, L., Zech, A., and Heße, F.: GSTools v1.3: a toolbox for geostatistical modelling in Python, Geosci. Model Dev., 15, 3161–3182, https://doi.org/10.5194/gmd-15-3161-2022, 2022.

You can cite the Zenodo code publication of GSTools by:

Sebastian Müller & Lennart Schüler. GeoStat-Framework/GSTools. Zenodo. https://doi.org/10.5281/zenodo.1313628

If you want to cite a specific version, have a look at the Zenodo site.

Documentation for GSTools

You can find the documentation under geostat-framework.readthedocs.io.

Tutorials and Examples

The documentation also includes some tutorials, showing the most important use cases of GSTools, which are

The associated python scripts are provided in the examples folder.

Spatial Random Field Generation

The core of this library is the generation of spatial random fields. These fields are generated using the randomisation method, described by Heße et al. 2014.

Examples

Gaussian Covariance Model

This is an example of how to generate a 2 dimensional spatial random field with a gaussian covariance model.

```python import gstools as gs

structured field with a size 100x100 and a grid-size of 1x1

x = y = range(100) model = gs.Gaussian(dim=2, var=1, lenscale=10) srf = gs.SRF(model) srf((x, y), meshtype='structured') srf.plot() ```

Random field

GSTools also provides support for geographic coordinates. This works perfectly well with cartopy.

```python import matplotlib.pyplot as plt import cartopy.crs as ccrs import gstools as gs

define a structured field by latitude and longitude

lat = lon = range(-80, 81) model = gs.Gaussian(latlon=True, lenscale=777, geoscale=gs.KM_SCALE) srf = gs.SRF(model, seed=12345) field = srf.structured((lat, lon))

Orthographic plotting with cartopy

ax = plt.subplot(projection=ccrs.Orthographic(-45, 45)) cont = ax.contourf(lon, lat, field, transform=ccrs.PlateCarree()) ax.coastlines() ax.set_global() plt.colorbar(cont) ```

lat-lon random field

A similar example but for a three dimensional field is exported to a VTK file, which can be visualized with ParaView or PyVista in Python:

```python import gstools as gs

structured field with a size 100x100x100 and a grid-size of 1x1x1

x = y = z = range(100) model = gs.Gaussian(dim=3, lenscale=[16, 8, 4], angles=(0.8, 0.4, 0.2)) srf = gs.SRF(model) srf((x, y, z), meshtype='structured') srf.vtkexport('3dfield') # Save to a VTK file for ParaView

mesh = srf.to_pyvista() # Create a PyVista mesh for plotting in Python mesh.contour(isosurfaces=8).plot() ```

3d Random field

Estimating and Fitting Variograms

The spatial structure of a field can be analyzed with the variogram, which contains the same information as the covariance function.

All covariance models can be used to fit given variogram data by a simple interface.

Example

This is an example of how to estimate the variogram of a 2 dimensional unstructured field and estimate the parameters of the covariance model again.

```python import numpy as np import gstools as gs

generate a synthetic field with an exponential model

x = np.random.RandomState(19970221).rand(1000) * 100. y = np.random.RandomState(20011012).rand(1000) * 100. model = gs.Exponential(dim=2, var=2, len_scale=8) srf = gs.SRF(model, mean=0, seed=19970221) field = srf((x, y))

estimate the variogram of the field

bincenter, gamma = gs.varioestimate((x, y), field)

fit the variogram with a stable model. (no nugget fitted)

fitmodel = gs.Stable(dim=2) fitmodel.fitvariogram(bincenter, gamma, nugget=False)

output

ax = fitmodel.plot(xmax=max(bincenter)) ax.scatter(bincenter, gamma) print(fit_model) ```

Which gives:

python Stable(dim=2, var=1.85, len_scale=7.42, nugget=0.0, anis=[1.0], angles=[0.0], alpha=1.09)

Variogram

Kriging and Conditioned Random Fields

An important part of geostatistics is Kriging and conditioning spatial random fields to measurements. With conditioned random fields, an ensemble of field realizations with their variability depending on the proximity of the measurements can be generated.

Example

For better visualization, we will condition a 1d field to a few "measurements", generate 100 realizations and plot them:

```python import numpy as np import matplotlib.pyplot as plt import gstools as gs

conditions

condpos = [0.3, 1.9, 1.1, 3.3, 4.7] condval = [0.47, 0.56, 0.74, 1.47, 1.74]

conditioned spatial random field class

model = gs.Gaussian(dim=1, var=0.5, lenscale=2) krige = gs.krige.Ordinary(model, condpos, condval) condsrf = gs.CondSRF(krige)

same output positions for all ensemble members

gridpos = np.linspace(0.0, 15.0, 151) condsrf.setpos(gridpos)

seeded ensemble generation

seed = gs.random.MasterRNG(20170519) for i in range(100): field = condsrf(seed=seed(), store=f"field{i}") plt.plot(gridpos, field, color="k", alpha=0.1) plt.scatter(condpos, cond_val, color="k") plt.show() ```

Conditioned

User Defined Covariance Models

One of the core-features of GSTools is the powerful CovModel class, which allows to easy define covariance models by the user.

Example

Here we re-implement the Gaussian covariance model by defining just a correlation function, which takes a non-dimensional distance h = r/l:

```python import numpy as np import gstools as gs

use CovModel as the base-class

class Gau(gs.CovModel): def cor(self, h): return np.exp(-h**2) ```

And that's it! With Gau you now have a fully working covariance model, which you could use for field generation or variogram fitting as shown above.

Have a look at the documentation for further information on incorporating optional parameters and optimizations.

Incompressible Vector Field Generation

Using the original Kraichnan method, incompressible random spatial vector fields can be generated.

Example

python import numpy as np import gstools as gs x = np.arange(100) y = np.arange(100) model = gs.Gaussian(dim=2, var=1, len_scale=10) srf = gs.SRF(model, generator='VectorField', seed=19841203) srf((x, y), mesh_type='structured') srf.plot()

yielding

vector field

Plurigaussian Field Simulation (PGS)

With PGS, more complex categorical (or discrete) fields can be created.

Example

```python import gstools as gs import numpy as np import matplotlib.pyplot as plt

N = [180, 140]

x, y = range(N[0]), range(N[1])

we need 2 SRFs

model = gs.Gaussian(dim=2, var=1, len_scale=5) srf = gs.SRF(model) field1 = srf.structured([x, y], seed=20170519) field2 = srf.structured([x, y], seed=19970221)

with lithotypes, we prescribe the categorical data and its relations

here, we use 2 categories separated by a rectangle.

rect = [40, 32] lithotypes = np.zeros(N) lithotypes[ N[0] // 2 - rect[0] // 2 : N[0] // 2 + rect[0] // 2, N[1] // 2 - rect[1] // 2 : N[1] // 2 + rect[1] // 2, ] = 1

pgs = gs.PGS(2, [field1, field2]) P = pgs(lithotypes)

fig, axs = plt.subplots(1, 2) axs[0].imshow(lithotypes, cmap="copper") axs[1].imshow(P, cmap="copper") plt.show() ```

PGS

VTK/PyVista Export

After you have created a field, you may want to save it to file, so we provide a handy VTK export routine using the .vtk_export() or you could create a VTK/PyVista dataset for use in Python with to .to_pyvista() method:

python import gstools as gs x = y = range(100) model = gs.Gaussian(dim=2, var=1, len_scale=10) srf = gs.SRF(model) srf((x, y), mesh_type='structured') srf.vtk_export("field") # Saves to a VTK file mesh = srf.to_pyvista() # Create a VTK/PyVista dataset in memory mesh.plot()

Which gives a RectilinearGrid VTK file field.vtr or creates a PyVista mesh in memory for immediate 3D plotting in Python.

pyvista export

Requirements:

Optional

Contact

You can contact us via info@geostat-framework.org.

License

LGPLv3 © 2018-2025

Owner

  • Name: GeoStat Framework
  • Login: GeoStat-Framework
  • Kind: organization
  • Email: info@geostat-framework.org
  • Location: UFZ Leipzig

Python framework for geostatistical simulations

Citation (CITATION.bib)

@Article{gmd-15-3161-2022,
AUTHOR = {M\"uller, S. and Sch\"uler, L. and Zech, A. and He{\ss}e, F.},
TITLE = {\texttt{GSTools} v1.3: a toolbox for geostatistical modelling in Python},
JOURNAL = {Geoscientific Model Development},
VOLUME = {15},
YEAR = {2022},
NUMBER = {7},
PAGES = {3161--3182},
URL = {https://gmd.copernicus.org/articles/15/3161/2022/},
DOI = {10.5194/gmd-15-3161-2022}
}

GitHub Events

Total
  • Create event: 12
  • Release event: 2
  • Issues event: 17
  • Watch event: 50
  • Delete event: 10
  • Issue comment event: 39
  • Push event: 62
  • Pull request event: 18
  • Pull request review event: 23
  • Pull request review comment event: 22
  • Fork event: 5
Last Year
  • Create event: 12
  • Release event: 2
  • Issues event: 17
  • Watch event: 50
  • Delete event: 10
  • Issue comment event: 39
  • Push event: 62
  • Pull request event: 18
  • Pull request review event: 23
  • Pull request review comment event: 22
  • Fork event: 5

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 1,641
  • Total Committers: 9
  • Avg Commits per committer: 182.333
  • Development Distribution Score (DDS): 0.238
Past Year
  • Commits: 63
  • Committers: 2
  • Avg Commits per committer: 31.5
  • Development Distribution Score (DDS): 0.159
Top Committers
Name Email Commits
MuellerSeb m****b@p****e 1,250
LSchueler l****r@u****e 201
LSchueler m****m@p****e 164
banesullivan b****i@g****m 12
Dominic Jodoin d****c@t****m 4
Lennart Schüler L****r 4
Ryan Russell g****t@r****g 3
Mike Taves m****s@g****m 2
Tobias Glaubach 3****h 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 74
  • Total pull requests: 92
  • Average time to close issues: 4 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 29
  • Total pull request authors: 9
  • Average comments per issue: 1.95
  • Average comments per pull request: 2.4
  • Merged pull requests: 67
  • Bot issues: 0
  • Bot pull requests: 2
Past Year
  • Issues: 10
  • Pull requests: 22
  • Average time to close issues: 5 days
  • Average time to close pull requests: 2 months
  • Issue authors: 6
  • Pull request authors: 5
  • Average comments per issue: 1.1
  • Average comments per pull request: 1.68
  • Merged pull requests: 8
  • Bot issues: 0
  • Bot pull requests: 2
Top Authors
Issue Authors
  • MuellerSeb (37)
  • LSchueler (4)
  • MatusGasparik (3)
  • mmaelicke (2)
  • donhalmina (2)
  • flydream0428 (2)
  • rkenko (2)
  • LanPeng-94 (2)
  • rlsandovalp (1)
  • Jimmy-KL (1)
  • rhugonnet (1)
  • jwtxwd (1)
  • tkschuler (1)
  • peter-pazak (1)
  • Michael-P-Crisp (1)
Pull Request Authors
  • MuellerSeb (63)
  • LSchueler (26)
  • dependabot[bot] (2)
  • EJRicketts (2)
  • mwtoews (2)
  • eumiro (1)
  • ibkvictor (1)
  • joshua-benabou (1)
  • ryanrussell (1)
Top Labels
Issue Labels
enhancement (19) bug (15) Refactoring (10) external problem (10) Documentation (9) CI/CD (6) Performance (4) wontfix (4) Installation (3) question (3) FutureWarning (2) organization (2) help wanted (2) duplicate (1)
Pull Request Labels
enhancement (31) Documentation (20) bug (20) CI/CD (16) Refactoring (13) external problem (6) dependencies (6) help wanted (5) Installation (4) Performance (4)

Packages

  • Total packages: 4
  • Total downloads:
    • pypi 13,459 last-month
  • Total docker downloads: 610
  • Total dependent packages: 9
    (may contain duplicates)
  • Total dependent repositories: 17
    (may contain duplicates)
  • Total versions: 95
  • Total maintainers: 3
pypi.org: gstools

GSTools: A geostatistical toolbox.

  • Versions: 38
  • Dependent Packages: 9
  • Dependent Repositories: 14
  • Downloads: 13,459 Last month
  • Docker Downloads: 610
Rankings
Dependent packages count: 2.2%
Stargazers count: 2.9%
Average: 3.6%
Downloads: 3.7%
Dependent repos count: 3.9%
Forks count: 5.4%
Last synced: 6 months ago
proxy.golang.org: github.com/GeoStat-Framework/GSTools
  • Versions: 23
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 2.8%
Forks count: 3.3%
Average: 4.3%
Dependent packages count: 5.4%
Dependent repos count: 5.7%
Last synced: 6 months ago
proxy.golang.org: github.com/geostat-framework/gstools
  • Versions: 23
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.7%
Last synced: 6 months ago
conda-forge.org: gstools

GeoStatTools provides geostatistical tools for various purposes: - random field generation - simple, ordinary, universal and external drift kriging - conditioned field generation - incompressible random vector field generation - (automatted) variogram estimation and fitting - directional variogram estimation and modelling - data normalization and transformation - many readily provided and even user-defined covariance models - metric spatio-temporal modelling - plotting and exporting routines

  • Versions: 11
  • Dependent Packages: 0
  • Dependent Repositories: 3
Rankings
Dependent repos count: 17.9%
Stargazers count: 19.3%
Forks count: 22.8%
Average: 27.9%
Dependent packages count: 51.5%
Last synced: 6 months ago

Dependencies

.github/workflows/main.yml actions
  • actions/checkout v2 composite
  • actions/download-artifact v2 composite
  • actions/setup-python v2 composite
  • actions/upload-artifact v2 composite
  • pypa/cibuildwheel v2.11.2 composite
  • pypa/gh-action-pypi-publish release/v1 composite