GSTools: A geostatistical toolbox.
Project description
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/develop.zip
To enable the OpenMP support, you have to provide a C compiler, Cython and OpenMP. To get all other dependencies, it is recommended to first install gstools once in the standard way just decribed. Then use the following command:
pip install --global-option="--openmp" gstools
Or for the development version:
pip install --global-option="--openmp" https://github.com/GeoStat-Framework/GSTools/archive/develop.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, October 1). GeoStat-Framework/GSTools: Reverberating Red (Version v1.1.0). Zenodo. http://doi.org/10.5281/zenodo.3468230
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
- Random Field Generation
- The Covariance Model
- Variogram Estimation
- Random Vector Field Generation
- Kriging
- Conditioned random field generation
- Field transformations
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 or PyVista in Python:
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') # Save to a VTK file for ParaView
mesh = srf.to_pyvista() # Create a PyVista mesh for plotting in Python
mesh.threshold_percent(0.5).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
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)
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
from gstools import Gaussian, SRF
import matplotlib.pyplot as plt
# 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]
gridx = np.linspace(0.0, 15.0, 151)
# spatial random field class
model = Gaussian(dim=1, var=0.5, len_scale=2)
srf = SRF(model)
srf.set_condition(cond_pos, cond_val, "ordinary")
# generate the ensemble of field realizations
fields = []
for i in range(100):
fields.append(srf(gridx, seed=i))
plt.plot(gridx, fields[i], 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
:
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/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:
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") # 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-2019
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.1.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0053a38ff60546c9f6175b41f791b357571d20ce84bdab3b3ec43a89be753ec9 |
|
MD5 | aa68a33a374b4f741ab99f02902ba9f1 |
|
BLAKE2b-256 | 855eb205f9172743aac19fe6e6fb8521949a5486731a326805a3f3659f7b2e47 |
Hashes for gstools-1.1.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e2838e1c33d70cbcf5e05422843ec8fe73131f195e30d59a92362ad84bdb7c |
|
MD5 | 01836a0d749f9b4365338b270383a25e |
|
BLAKE2b-256 | 3ed962b5ccb7d865fb103741ca3804e79f95ad49cf46b6a6e1c8b15316e7f385 |
Hashes for gstools-1.1.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7069242bf8acf18c6337c821db669757c14709474241087cf25d65149595740 |
|
MD5 | b38df83eea68479dd08cd293354a062d |
|
BLAKE2b-256 | bd7d1066232cbc05296c42ef410fb2437b76f441236573f33647d3769aa61a92 |
Hashes for gstools-1.1.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d5078c7cf5eef0ae27b5c130c1fb9d5eaf115cf573ff05cc80b7c35817416ed |
|
MD5 | 2bf409c0dac7399cddd78a3ef38b757c |
|
BLAKE2b-256 | 280a857e33764e3378b6d883c9c8143bf85a5a34605a24c6cf237a8664aa51af |
Hashes for gstools-1.1.1-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 035f4291bb98445afc7e8ef930678bd19e6fc88021756a19e04691a0018e45c3 |
|
MD5 | 9728076ad137a05cf2c4947875d5bb40 |
|
BLAKE2b-256 | dfd3ba921046b4888896cf1a1bf98b3a7e492a2c9100e742dfbb48e5647ad4e8 |
Hashes for gstools-1.1.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e71d3366b8fe1409a905e6688ab015bd20c52d970e4dc9c3de6571010524af4 |
|
MD5 | ed11e7bd817e8faa358d602716d08478 |
|
BLAKE2b-256 | 180ce5a0b0e1185a1a1b6fc7bc1f1b0e8f7d28acb4460646efa17e00c6096ac5 |
Hashes for gstools-1.1.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab94f92331eee8a70f808862614adc521e46b05be6e408c8d7ff27647a90dbc7 |
|
MD5 | e00ddea419d934c8ba9ae5fbd7d6ee08 |
|
BLAKE2b-256 | d41e521f941c757315ec0f8ee1a5d36546eef1213b13c67cb3741f64cbc25418 |
Hashes for gstools-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed531c5fedbf384692977ca069bd18533a9dbfa7335b72f1ac61db003a2133f5 |
|
MD5 | 0b418d2e734ddee31dc7f4328d34cec3 |
|
BLAKE2b-256 | 4f8b5ffe4c1bab923aa7d23f086a2331c686431cb45dd1cb1bba0b79f6daaf4c |
Hashes for gstools-1.1.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 523ebdaaf72febed122c09465d6710c51289f7f884101c3debe568d1875c7d9d |
|
MD5 | 39ebebcb3ea0d3992e9c698e20326a1b |
|
BLAKE2b-256 | 21a51635a967bd5175b23c25e0b23c96e0ae79d7effd6a2c2964d6f072ebf55a |
Hashes for gstools-1.1.1-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51f4422dcd48b968129a06da4920c734b4d3899675ef1fb796e724ca1153d588 |
|
MD5 | 1b7be353e9a4e9d72b11db5547a5899d |
|
BLAKE2b-256 | da295281afbfb8cda991f49fb8c46e861922482134972651badc5e60d3bef594 |
Hashes for gstools-1.1.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ffa92820d97053d516ca71166590c43c982ab4c7413714357149dd6a8ae1c29 |
|
MD5 | 6bb0bb83c5ca01e1a9e41e358b18f73f |
|
BLAKE2b-256 | fd406171a397b2adea7881ad5d0d193975003bf1f9a9ea940a26a489029d4838 |
Hashes for gstools-1.1.1-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1533ed9d96ee98f086f357f876272a57167c2a37579a7380f1e8f26fa409d5f3 |
|
MD5 | cf598791c5405e0fd82db9813a0af3be |
|
BLAKE2b-256 | 7105c3603ee4081b35a1ea98cc6b2d0f3654bbbee2718b76fa5582c6567a1d33 |
Hashes for gstools-1.1.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69eb8d19f0362f8a1eea1448380374f73fbae095dee8930c9ab8444a85ce72b8 |
|
MD5 | e4ee119d16b6c7baceae8ff02e919bbd |
|
BLAKE2b-256 | 39c66f4d766a4b2f3da6117cd9a7663e7691339ace524f9e5343595a8dbc5d6b |
Hashes for gstools-1.1.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3611f082f8fc175e87a607661317dc5e90089f802a47abdd508c0e730e752f3 |
|
MD5 | 06f71b3ed034efc3515cfd6c8b88cad2 |
|
BLAKE2b-256 | 4579356c06ae4657f7805efcc94a2f9d6e5234d8bd353dbbcfb90c43b3c492b7 |
Hashes for gstools-1.1.1-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30554b98b34c24db68fa7b31a8b5202701d9f9012c51419a8ad78543e38068a4 |
|
MD5 | 2a1dc6360f8dae414de53e3db2613056 |
|
BLAKE2b-256 | dd36ae440784b8ebb60f1be1b8deb81b22ee73f5d57ad9c5b2ba48f003243a2a |
Hashes for gstools-1.1.1-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a2895d26170c7d7c5f6c70a093308a2078738cd3d81689f2c782cd7ecf9c7bd |
|
MD5 | cf3a5fc11b2800fe2c96bc9f487283d1 |
|
BLAKE2b-256 | 22166179efcf7ba4da485e21ba73a94081f94cd1075021d8437303736bf21a22 |
Hashes for gstools-1.1.1-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4017343ecef1a5e11accddec6fad5c05335291f46f38ef4fd986828c2c4464ed |
|
MD5 | b0309adb3ec8c8ec9b36c6c692c718eb |
|
BLAKE2b-256 | 3ae8c1b31f59b5c64c01b1df4e437786a4f297ac82bcb1c51a713954b756758b |
Hashes for gstools-1.1.1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4b757c82913340eb7780fbe053d85a60ab20b8f7c275129649e3d95edc4727c |
|
MD5 | 9861d079a4c3a008d2a290847fb0925c |
|
BLAKE2b-256 | 3bac88ef2e5e0a9cf4e05795a590a0a4e222db0881def5d9d6b4520413647d3e |
Hashes for gstools-1.1.1-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d280b1a53b64d0e60865b99d01d327135a78d266dfdd7e8ab27f4f6b51b674b3 |
|
MD5 | e707d7b1c5b2de3901c5b65dc5ae898c |
|
BLAKE2b-256 | cfce90528fe550f542fec639e684fdc9679ee8f3255d76e336356b6184696de8 |
Hashes for gstools-1.1.1-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4d9e6035fbd4d98a4ce8abe8ac5d4b0c1c7ebeb6381c3648faba10913df7d9a |
|
MD5 | f5fbdfde1576b3ff8dd7b376d5f28f89 |
|
BLAKE2b-256 | 9657d760bc485d44eae4a3cf2a7ced9e2d0532d8a11b0c3cb8afdc9606156d75 |
Hashes for gstools-1.1.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fd16418cde631638a92cc51a63324c3a8e7cb82db60cacd8429184dca26687b |
|
MD5 | 4ec02212631912742b9a0bae4605f5ee |
|
BLAKE2b-256 | acbc4b59c7d6e829950d80a121a4e5dbbf4db3cd0408058fc0f8e7f0aa4ebf65 |
Hashes for gstools-1.1.1-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eb403a84d3a46661830102aa07c4cb1582d555969525acbc84dc33642380cf2 |
|
MD5 | 678fc8831db69709b722fba95121429d |
|
BLAKE2b-256 | 24c5c9c2797f93a90a7c6d685ad0753aad5aad72f8b89ed9cf7365dcdce624c5 |
Hashes for gstools-1.1.1-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 725e734f5a8f032b35caa4508d070a6b7c0c4238b69566c7a39e31c0131546ed |
|
MD5 | ad4f518affb3333d134f90b3d1728bdf |
|
BLAKE2b-256 | bb79e0c0556d3afdc2e30fd4b722d717fbb9ee6d4ae11cb2ecd024042d92fbe5 |
Hashes for gstools-1.1.1-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80939108726438e92190a24ce2f86dfd6274bffea12781b96d62c67f2028cea8 |
|
MD5 | e2cd5fa368ac0bce41fde69e57a08422 |
|
BLAKE2b-256 | f484e3246d6fb858a74be76e281041ca4d184e99686511444576943cf28782d1 |
Hashes for gstools-1.1.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b66fe4dda26b0a4b11281167e22478ddcbfe447da9ded795b49492cdb2cff907 |
|
MD5 | 641ec6b118f19c14b213ace5c779ea23 |
|
BLAKE2b-256 | d198ed3e0e8c12d89c713b22632f04e5b91f36f5dc8fdc9a33fc36cfe02312c7 |
Hashes for gstools-1.1.1-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bbe85741dfa07733cb6f87dbf98c2cfdea11751b596800b453d471f0a31b68e |
|
MD5 | 01163f08845c937a0980bf49a6c6e9b9 |
|
BLAKE2b-256 | 443a43360cc30f3b61bffe9dff6fc690cd385ceb8ae85cb0474fb7e8a459a508 |
Hashes for gstools-1.1.1-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35ec37d7ca11255481872bd55309ae57f3447827cd6ac30f0e3416062b63cfe1 |
|
MD5 | 505e4602ba2702f220cd51f2b515c294 |
|
BLAKE2b-256 | 328a581470bcb50411650f738865e2bee7cfb111fd116114dc1502341c1617e8 |