GSTools: A geostatistical toolbox.

# Welcome to GSTools

## Purpose

GeoStatTools provides geostatistical tools for various purposes:

• random field generation
• conditioned field generation
• incompressible random vector field generation
• simple and ordinary kriging
• variogram estimation and fitting
• many readily provided and even user-defined covariance models
• plotting and exporting routines

## Installation

The package can be installed via pip on Windows, Linux and Mac. On Windows you can install WinPython to get Python and pip running. Also conda provides pip support. Install GSTools by typing the following into the command prompt:

pip install gstools


To get the latest development version you can install it directly from GitHub:

pip install https://github.com/GeoStat-Framework/GSTools/archive/master.zip


To enable the OpenMP support, you have to provide a C compiler, Cython and OpenMP. Then use the following command:

pip install --global-option="--openmp" https://github.com/GeoStat-Framework/GSTools/archive/master.zip


If something went wrong during installation, try the -I flag from pip.

## Citation

At the moment you can cite the Zenodo code publication of GSTools:

Sebastian Müller, & Lennart Schüler. (2019, January 18). GeoStat-Framework/GSTools: Bouncy Blue (Version v1.0.1). Zenodo. http://doi.org/10.5281/zenodo.2543658

A publication for the GeoStat-Framework is in preperation.

## 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

Some more examples 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.

from gstools import SRF, Gaussian
import matplotlib.pyplot as plt
# structured field with a size 100x100 and a grid-size of 1x1
x = y = range(100)
model = Gaussian(dim=2, var=1, len_scale=10)
srf = SRF(model)
srf((x, y), mesh_type='structured')
srf.plot()


A similar example but for a three dimensional field is exported to a VTK file, which can be visualized with ParaView.

from gstools import SRF, Gaussian
import matplotlib.pyplot as pt
# structured field with a size 100x100x100 and a grid-size of 1x1x1
x = y = z = range(100)
model = Gaussian(dim=3, var=0.6, len_scale=20)
srf = SRF(model)
srf((x, y, z), mesh_type='structured')
srf.vtk_export('3d_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.

import numpy as np
from gstools import SRF, Exponential, Stable, vario_estimate_unstructured
# 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 = Exponential(dim=2, var=2, len_scale=8)
srf = SRF(model, mean=0, seed=19970221)
field = srf((x, y))
# estimate the variogram of the field with 40 bins
bins = np.arange(40)
bin_center, gamma = vario_estimate_unstructured((x, y), field, bins)
# fit the variogram with a stable model. (no nugget fitted)
fit_model = Stable(dim=2)
fit_model.fit_variogram(bin_center, gamma, nugget=False)
# output
ax = fit_model.plot(x_max=40)
ax.plot(bin_center, gamma)
print(fit_model)


Which gives:

Stable(dim=2, var=1.92, len_scale=8.15, nugget=0.0, anis=[1.], angles=[0.], alpha=1.05)


## 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:

from gstools import CovModel
import numpy as np
# use CovModel as the base-class
class Gau(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

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


yielding

## VTK Export

After you have created a field, you may want to save it to file, so we provide a handy VTK export routine:

from gstools import SRF, Gaussian
x = y = range(100)
model = Gaussian(dim=2, var=1, len_scale=10)
srf = SRF(model)
srf((x, y), mesh_type='structured')
srf.vtk_export("field")


Which gives a RectilinearGrid VTK file field.vtr.

## Project details

### Source Distribution

gstools-1.1.0rc1.tar.gz (4.7 MB view hashes)

Uploaded Source

### Built Distributions

gstools-1.1.0rc1-cp37-cp37m-win_amd64.whl (685.0 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

gstools-1.1.0rc1-cp37-cp37m-win32.whl (636.9 kB view hashes)

Uploaded CPython 3.7m Windows x86

gstools-1.1.0rc1-cp37-cp37m-manylinux1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.7m

gstools-1.1.0rc1-cp37-cp37m-manylinux1_i686.whl (1.4 MB view hashes)

Uploaded CPython 3.7m

gstools-1.1.0rc1-cp37-cp37m-macosx_10_6_intel.whl (961.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.6+ intel

gstools-1.1.0rc1-cp36-cp36m-win_amd64.whl (685.2 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

gstools-1.1.0rc1-cp36-cp36m-win32.whl (637.3 kB view hashes)

Uploaded CPython 3.6m Windows x86

gstools-1.1.0rc1-cp36-cp36m-manylinux1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.6m

gstools-1.1.0rc1-cp36-cp36m-manylinux1_i686.whl (1.4 MB view hashes)

Uploaded CPython 3.6m

gstools-1.1.0rc1-cp36-cp36m-macosx_10_6_intel.whl (960.6 kB view hashes)

Uploaded CPython 3.6m macOS 10.6+ intel

gstools-1.1.0rc1-cp35-cp35m-win_amd64.whl (682.4 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

gstools-1.1.0rc1-cp35-cp35m-win32.whl (634.7 kB view hashes)

Uploaded CPython 3.5m Windows x86

gstools-1.1.0rc1-cp35-cp35m-manylinux1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.5m

gstools-1.1.0rc1-cp35-cp35m-manylinux1_i686.whl (1.4 MB view hashes)

Uploaded CPython 3.5m

gstools-1.1.0rc1-cp35-cp35m-macosx_10_6_intel.whl (950.1 kB view hashes)

Uploaded CPython 3.5m macOS 10.6+ intel

gstools-1.1.0rc1-cp34-cp34m-win_amd64.whl (679.2 kB view hashes)

Uploaded CPython 3.4m Windows x86-64

gstools-1.1.0rc1-cp34-cp34m-win32.whl (639.1 kB view hashes)

Uploaded CPython 3.4m Windows x86

gstools-1.1.0rc1-cp34-cp34m-manylinux1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.4m

gstools-1.1.0rc1-cp34-cp34m-manylinux1_i686.whl (1.4 MB view hashes)

Uploaded CPython 3.4m

gstools-1.1.0rc1-cp34-cp34m-macosx_10_6_intel.whl (975.1 kB view hashes)

Uploaded CPython 3.4m macOS 10.6+ intel

gstools-1.1.0rc1-cp27-cp27mu-manylinux1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 2.7mu

gstools-1.1.0rc1-cp27-cp27mu-manylinux1_i686.whl (1.4 MB view hashes)

Uploaded CPython 2.7mu

gstools-1.1.0rc1-cp27-cp27m-win_amd64.whl (699.4 kB view hashes)

Uploaded CPython 2.7m Windows x86-64

gstools-1.1.0rc1-cp27-cp27m-win32.whl (648.6 kB view hashes)

Uploaded CPython 2.7m Windows x86

gstools-1.1.0rc1-cp27-cp27m-manylinux1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 2.7m

gstools-1.1.0rc1-cp27-cp27m-manylinux1_i686.whl (1.4 MB view hashes)

Uploaded CPython 2.7m

gstools-1.1.0rc1-cp27-cp27m-macosx_10_6_intel.whl (1.0 MB view hashes)

Uploaded CPython 2.7m macOS 10.6+ intel