GSTools: A geostatistical toolbox.
Project description
Welcome to GSTools
Get in Touch!
Purpose
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
- (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
- 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.
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. Discuss. [preprint], https://doi.org/10.5194/gmd-2021-301, in review, 2021.
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
- Random Field Generation
- The Covariance Model
- Variogram Estimation
- Random Vector Field Generation
- Kriging
- Conditioned random field generation
- Field transformations
- Geographic Coordinates
- Spatio-Temporal Modelling
- Normalizing Data
- Miscellaneous examples
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.
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, len_scale=10)
srf = gs.SRF(model)
srf((x, y), mesh_type='structured')
srf.plot()
GSTools also provides support for geographic coordinates. This works perfectly well with cartopy.
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, len_scale=777, rescale=gs.EARTH_RADIUS)
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)
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:
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, len_scale=[16, 8, 4], angles=(0.8, 0.4, 0.2))
srf = gs.SRF(model)
srf((x, y, z), mesh_type='structured')
srf.vtk_export('3d_field') # Save to a VTK file for ParaView
mesh = srf.to_pyvista() # Create a PyVista mesh for plotting in Python
mesh.contour(isosurfaces=8).plot()
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
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
bin_center, gamma = gs.vario_estimate((x, y), field)
# fit the variogram with a stable model. (no nugget fitted)
fit_model = gs.Stable(dim=2)
fit_model.fit_variogram(bin_center, gamma, nugget=False)
# output
ax = fit_model.plot(x_max=max(bin_center))
ax.scatter(bin_center, gamma)
print(fit_model)
Which gives:
Stable(dim=2, var=1.85, len_scale=7.42, nugget=0.0, anis=[1.0], angles=[0.0], alpha=1.09)
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:
import numpy as np
import matplotlib.pyplot as plt
import gstools as gs
# conditions
cond_pos = [0.3, 1.9, 1.1, 3.3, 4.7]
cond_val = [0.47, 0.56, 0.74, 1.47, 1.74]
# conditioned spatial random field class
model = gs.Gaussian(dim=1, var=0.5, len_scale=2)
krige = gs.krige.Ordinary(model, cond_pos, cond_val)
cond_srf = gs.CondSRF(krige)
# same output positions for all ensemble members
grid_pos = np.linspace(0.0, 15.0, 151)
cond_srf.set_pos(grid_pos)
# seeded ensemble generation
seed = gs.random.MasterRNG(20170519)
for i in range(100):
field = cond_srf(seed=seed(), store=f"field_{i}")
plt.plot(grid_pos, field, color="k", alpha=0.1)
plt.scatter(cond_pos, cond_val, color="k")
plt.show()
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
:
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
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
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:
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.
Requirements:
Optional
Contact
You can contact us via info@geostat-framework.org.
License
LGPLv3 © 2018-2021
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for gstools-1.3.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2da826cbe15524ab699c1b7f1395a2c0d09d712e01138fbdc9bc943ed5dd8006 |
|
MD5 | b5505fe376d64fef4f40d8023c743728 |
|
BLAKE2b-256 | 7dd7c93c834c85e46c6ac9b9a396210d119e7d4e4cc0764887c4414b3a1671be |
Hashes for gstools-1.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5be7b6f772cdc8696b1f4fa2160e1f53c6eedecb332009ceab3bb54657cd0d91 |
|
MD5 | 4177ffc13849f2971e9e851f46df5f72 |
|
BLAKE2b-256 | d006ae4d1dd5d490e93b795ef0ce0a9736ac0e2757fd2fd65ae412a60290a278 |
Hashes for gstools-1.3.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b0cdc7cc54a05604ce9378f63dd70b5b5ecaf9f215dadd0eb4274c6c23052ab |
|
MD5 | 1ce80f409699abcc9ec8e8ef59203272 |
|
BLAKE2b-256 | 2a84445dceb69fbedb9c3486f1c38a48d3836bddea8b33f491b4a618015cef2c |
Hashes for gstools-1.3.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e04f1cead1c340b9128021374b20a36546fa2963e17af4c6aa838dbd2a88469d |
|
MD5 | f9909311f515a550b25b1e47e0c41c64 |
|
BLAKE2b-256 | 2c865c050d3ee4ec96b5bad421d86d6c88dfd0d61c910b3038dd2043d05aa56f |
Hashes for gstools-1.3.4-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e551dfcf57979afc9b9fb6ee45a7dfd508387c517e4277949ba02d0e0b50e457 |
|
MD5 | 31f8acea4e77ca7e1c0fd75276a4817d |
|
BLAKE2b-256 | dda3d5e8fc25a4ab79b4d7addca16d4e5e58220dc5df51d45f63415f5456f18a |
Hashes for gstools-1.3.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2123b7846671587965045dce3ad6e365b951fa890922a2fdf2b96af2e1d3ad7 |
|
MD5 | 74032013c554d9b39c58f860257f85fe |
|
BLAKE2b-256 | 09cae6b6a726cbf75f5a07352e2d46032752e915d6ef79480f2eb8007fe0e23c |
Hashes for gstools-1.3.4-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54b2998347c979c6207f386786b60c6641c3304f8b63e6a46828fd8522605090 |
|
MD5 | ae892c15f4761af9c77ac399a1c6ab82 |
|
BLAKE2b-256 | d6148785b7a94df0bcaf7df9b22a9e6e7477653149692bb1b536433ecebf0d8b |
Hashes for gstools-1.3.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c24e234bf5fd0c33c189ae668d8af789ed672fe5da8e5597e3daca345129e0 |
|
MD5 | 0c5561e47ca66c8681ecce44d517b5b5 |
|
BLAKE2b-256 | 7fe82de53e645d55e056469c77da39c8639f975954317b5400d887b63ecb6163 |
Hashes for gstools-1.3.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77dbbc203cdb651393bc5c7f36f8b687904f2cec60c513c00eed04df41a78cb0 |
|
MD5 | 14d6368cd43ac76dc274505bedc2a372 |
|
BLAKE2b-256 | 931b263d7df2f34e220baca23d2dfd17c42c2f82f6030c4112643dbc484d6b01 |
Hashes for gstools-1.3.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8417aaa0c09fc4c3934d78f21278d6465dd99964642174c8bc165a7b5d29ea61 |
|
MD5 | 15727eebea18c7fe5234fbaa429c208c |
|
BLAKE2b-256 | 3a5f3008676577ca644e91357fc25c084a343bb7bb5007c6f9fdb87a0fd853c0 |
Hashes for gstools-1.3.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60b3289719640ecc75bca9e6ef8a14538e1cc9a04d6c5879aed2aa8afa239b6f |
|
MD5 | 6e3efb6643ca0300a1efd06e99e992cf |
|
BLAKE2b-256 | 4b5997388a628b97013a169bc177f535bef67073777d1b8c3a8251ad5140cf87 |
Hashes for gstools-1.3.4-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 388152f36e3c54e19ff686ae91f4b6bc82350dc81978e37a2e053ad02fc9eacc |
|
MD5 | 692ab1bcb5fe192b9dc5528a31dc0412 |
|
BLAKE2b-256 | 21b044bd9a2009cc909e56316440d48d2cce7873f00781ebe81710de39029b97 |
Hashes for gstools-1.3.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f747f393eed759b083f6b2a9de061fedf81bd208dc434b35169ca1b1923024ed |
|
MD5 | 7886d6c0a6960fde15b0602026175d99 |
|
BLAKE2b-256 | 96a4cd1a2248c1473aaaa93aabb7b8ca2f13fc832da9f99e73f2110f7c65ec24 |
Hashes for gstools-1.3.4-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26fa50cfb0bee310cda7040a68eab6f9adf333a526e93370695a0fc99d0706a3 |
|
MD5 | 9dbd9e40c9d2b1f3009e2290948b6330 |
|
BLAKE2b-256 | b5c17b3b442a46721f7119c971926a6130adf3896ae49550608c3151863e6417 |
Hashes for gstools-1.3.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fea85306d322f0050710698dbd0e1ab841789a4ae8b90fcf1f2298d24c470f1 |
|
MD5 | 921ef4950192161445a2efb7ab719a73 |
|
BLAKE2b-256 | 9ac1ef5b16ce7e0a2ef04c8c539f810ac78aaec3d95c00d9ebd30f9e1732c9dc |
Hashes for gstools-1.3.4-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5220a02aa8c36e8014f8274daaef040dbe4c222b855385e42706bd5e481641c0 |
|
MD5 | 668734c19926373698660671ffc66bca |
|
BLAKE2b-256 | 1349da3bb0f43bf8d415259d0a8de65741eda7a336e97bff54787099786c2d4a |
Hashes for gstools-1.3.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5b32d88cff156e8cff801928eec2902806217a333b0e01d7843f7df392b6897 |
|
MD5 | 25b1a3d14b878d4cf21cf6e12f7ceb27 |
|
BLAKE2b-256 | 2bac9dbdd1040971fb5bed63f61e278a0411f57ca6cbe4a5a0535924dafcbd86 |
Hashes for gstools-1.3.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5201c790704887a7aade1aed4faeef6f40422381a24f9753b4b44502c5225ec |
|
MD5 | 9adde775f4d0d14ba013f10af1666b78 |
|
BLAKE2b-256 | bc4679b2ecd7fece0cd12aaa90601b4d7d8fff5a10d045921cac3f5cc86b77cb |
Hashes for gstools-1.3.4-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d44637bd934c115d33a26e1a5bdd6a2ca0fe33dfb711498d3debb71b96d57bc |
|
MD5 | 125f1f550f8c81b8060d3b476f94b06a |
|
BLAKE2b-256 | e18d92cbfd96326989aba243a4fb5e9f39ced6dcbc67e95580e1e50ab92bfb4f |
Hashes for gstools-1.3.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 446712184f6a3d1f35ac0618966f12fbe912b4dde5044b0273ef1c4c8e57bbd7 |
|
MD5 | 4c59a8bfe5ee0f70b3b63f330ee479db |
|
BLAKE2b-256 | 521dc683183c9178ca2a9b6f0d7c89dc70ba4b14d0555a5b4e833cbca5a43a9d |
Hashes for gstools-1.3.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25e544ee93b5397ec04d44652f4e6e27053299d31eb6c84e00ac30201091e2dc |
|
MD5 | 83e0639a43500389f433cef63d412543 |
|
BLAKE2b-256 | aa9e456f3909f9c4fa73d53818f8e329a6d45f4632cfeb4099b8634cd8e504d6 |
Hashes for gstools-1.3.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d79d803ab4c698eebb47ce20378314d0da42a9636c1d3551fbc9b798ad23b5a3 |
|
MD5 | 88a2efd7cf62dbc7a884f73c9291bf38 |
|
BLAKE2b-256 | 456a5d1d313e976ed0e885ec2540ef2be3f895dbf49ac90d9779d7a417ed8c1c |
Hashes for gstools-1.3.4-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 683c02873276772e7ecea06513dd9ea2dbedb34b987a3ff0f60cfbb4fcf38368 |
|
MD5 | 610256253d4444daf915407101390cd8 |
|
BLAKE2b-256 | fb4ad239a924c606a9399c4b1487287d2774f85cd5948edfa81b49d1fb2bf3c4 |
Hashes for gstools-1.3.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0660a0ddb3305df0ae6876b871b7df981d9f347c28a3572a526138ef14413b3 |
|
MD5 | 3d7a787e36422090443b82abc50ea9f4 |
|
BLAKE2b-256 | 01d2c71721c61e1efa7b724bea3ee804f2c66d78f67f1ce4f3f161418b09d0a2 |
Hashes for gstools-1.3.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c7033e28844491caea4ee799d468aa0db72ad77693757c34aee3b47b25fa39f |
|
MD5 | 4de849d8a35008d5f4c2fcdde464b17e |
|
BLAKE2b-256 | 5aa0bdc3dfdf1fa76e8fbc6f9416042c0aadc740a3b96a6760351ac91ae92495 |
Hashes for gstools-1.3.4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e6b9188d4eeb2354cc28dc2dc0b9ee3c3fbc06cf7e04edcda144fb66b27aa28 |
|
MD5 | dda6729b07ea433658dcdc9b7f7d6dec |
|
BLAKE2b-256 | fb791989ea1dae3ad6bd809d92ff3ca0ef8a384549fdb85321db22b873fa810a |
Hashes for gstools-1.3.4-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d84485b001e5d92cdaf29161fe60e35ee615255b6bef2c95898208b82790c1d0 |
|
MD5 | ae6096af24fc267ebfb544f3207cdb29 |
|
BLAKE2b-256 | aa7c6e42d0c60a1486a47f55a8afc060fedd46f68c01d58dcbbe7d1f6a64d634 |
Hashes for gstools-1.3.4-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3df437c7f4e71032997e9f729aec2ef0512c0717c372e2aa96c760d1736bb10 |
|
MD5 | dfc3e122aad45f6a1edf636b5bba566a |
|
BLAKE2b-256 | 352c025a4bdf25d9f20a0888ef041e08f0ffd9f7e01c89cc08433109b645eed4 |
Hashes for gstools-1.3.4-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d059a12c125c2f56e90116d582e9794538af39249cf96af2402fefba7b2c9a57 |
|
MD5 | 0536dd6392c3fe9d0f390d47604374a8 |
|
BLAKE2b-256 | 38326196f88f80b10929f28b0030bb08955833b41e74c51ba0a8de4dd044a34d |