How to use the gstools.SRF function in gstools

To help you get started, we’ve selected a few gstools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GeoStat-Framework / GSTools / tests / test_export.py View on Github external
def setUp(self):
        self.test_dir = tempfile.mkdtemp()
        # structured field with a size 100x100x100 and a grid-size of 1x1x1
        x = y = z = range(50)
        model = Gaussian(dim=3, var=0.6, len_scale=20)
        self.srf_structured = SRF(model)
        self.srf_structured((x, y, z), mesh_type="structured")
        # unstrucutred field
        seed = MasterRNG(19970221)
        rng = np.random.RandomState(seed())
        x = rng.randint(0, 100, size=1000)
        y = rng.randint(0, 100, size=1000)
        model = Exponential(
            dim=2, var=1, len_scale=[12.0, 3.0], angles=np.pi / 8.0
        )
        self.srf_unstructured = SRF(model, seed=20170519)
        self.srf_unstructured([x, y])
github GeoStat-Framework / GSTools / tests / test_srf.py View on Github external
def test_assertions(self):
        # self.cov_model.dim = 0
        # self.assertRaises(ValueError, SRF, self.cov_model, self.mean, self.mode_no)
        # self.cov_model.dim = 4
        # self.assertRaises(ValueError, SRF, self.cov_model, self.mean, self.mode_no)
        self.cov_model.dim = 3
        self.cov_model.anis = (0.25, 0.5)
        srf = SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        self.assertRaises(ValueError, srf, [self.x_tuple])
        self.assertRaises(ValueError, srf, [self.x_grid, self.y_grid])
        srf = SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        self.assertRaises(ValueError, srf, [self.x_tuple, self.y_tuple])
        self.assertRaises(
            ValueError, srf, [self.x_grid, self.y_grid, self.z_grid]
        )
        self.assertRaises(
            ValueError,
            srf,
            [self.x_tuple, self.y_tuple, self.z_tuple],
            self.seed,
            mesh_type="hyper_mesh",
        )
github GeoStat-Framework / GSTools / tests / test_srf.py View on Github external
def test_rotation_struct_3d(self):
        self.cov_model.dim = 3
        self.cov_model.anis = 0.25
        srf = SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        field = srf(
            (self.x_grid_c, self.y_grid_c, self.z_grid_c),
            seed=self.seed,
            mesh_type="structured",
        )

        self.cov_model.angles = -np.pi / 2.0
        srf = SRF(self.cov_model, mean=self.mean, mode_no=self.mode_no)
        field_rot = srf(
            (self.x_grid_c, self.y_grid_c, self.z_grid_c),
            seed=self.seed,
            mesh_type="structured",
        )

        self.assertAlmostEqual(field[0, 0, 0], field_rot[0, 7, 0])
        self.assertAlmostEqual(field[0, 0, 1], field_rot[0, 7, 1])
github GeoStat-Framework / GSTools / examples / 07_transformations / 04_bimodal.py View on Github external
bimodal fields
---------------

We provide two transformations to obtain bimodal distributions:

* `arcsin `__.
* `uquad `__.

Both transformations will preserve the mean and variance of the given field by default.
"""
import gstools as gs

# structured field with a size of 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, seed=20170519)
field = srf.structured([x, y])
gs.transform.normal_to_arcsin(srf)
srf.plot()
github GeoStat-Framework / GSTools / examples / 00_misc / 00_tpl_stable.py View on Github external
import numpy as np
import gstools as gs

x = y = np.linspace(0, 100, 100)
model = gs.TPLStable(
    dim=2,  # spatial dimension
    var=1,  # variance (C is calculated internally, so variance is actually 1)
    len_low=0,  # lower truncation of the power law
    len_scale=10,  # length scale (a.k.a. range), len_up = len_low + len_scale
    nugget=0.1,  # nugget
    anis=0.5,  # anisotropy between main direction and transversal ones
    angles=np.pi / 4,  # rotation angles
    alpha=1.5,  # shape parameter from the stable model
    hurst=0.7,  # hurst coefficient from the power law
)
srf = gs.SRF(model, mean=1.0, seed=19970221)
srf.structured([x, y])
srf.plot()
github GeoStat-Framework / GSTools / examples / 00_misc / 01_export.py View on Github external
"""
Export
------
"""

import gstools as gs

x = y = range(100)
model = gs.Gaussian(dim=2, var=1, len_scale=10)
srf = gs.SRF(model)
field = srf((x, y), mesh_type="structured")
srf.vtk_export(filename="field")
github GeoStat-Framework / GSTools / examples / 07_transformations / 03_zinn_harvey.py View on Github external
"""
Zinn & Harvey transformation
----------------------------

Here, we transform a field with the so called "Zinn & Harvey" transformation presented in
`Zinn & Harvey (2003) `__.
With this transformation, one could overcome the restriction that in ordinary
Gaussian random fields the mean values are the ones being the most connected.
"""
import gstools as gs

# structured field with a size of 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, seed=20170519)
srf.structured([x, y])
gs.transform.zinnharvey(srf, conn="high")
srf.plot()
github GeoStat-Framework / GSTools / examples / 07_transformations / 05_combinations.py View on Github external
------------

You can combine different transformations simply by successively applying them.

Here, we first force the single field realization to hold the given moments,
namely mean and variance.
Then we apply the Zinn & Harvey transformation to connect the low values.
Afterwards the field is transformed to a binary field and last but not least,
we transform it to log-values.
"""
import gstools as gs

# structured field with a size of 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, mean=-9, seed=20170519)
srf.structured([x, y])
gs.transform.normal_force_moments(srf)
gs.transform.zinnharvey(srf, conn="low")
gs.transform.binary(srf)
gs.transform.normal_to_lognormal(srf)
srf.plot()
github GeoStat-Framework / GSTools / examples / 03_variogram / 02_find_best_model.py View on Github external
"""
Finding the best fitting variogram model
----------------------------------------
"""
import numpy as np
import gstools as gs
from matplotlib import pyplot as plt

###############################################################################
# Generate a synthetic field with an exponential model.

x = np.random.RandomState(19970221).rand(1000) * 100.0
y = np.random.RandomState(20011012).rand(1000) * 100.0
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 with 40 bins and plot the result.

bins = np.arange(40)
bin_center, gamma = gs.vario_estimate_unstructured((x, y), field, bins)
plt.scatter(bin_center, gamma, label="data")
ax = plt.gca()

###############################################################################
# Define a set of models to test.

models = {
    "gaussian": gs.Gaussian,
    "exponential": gs.Exponential,
github GeoStat-Framework / GSTools / examples / 01_random_field / 02_fancier.py View on Github external
The code is very similar to the previous examples, but with a different
covariance model class :any:`Exponential`. As model parameters we a using
following

- variance :math:`\sigma^2=1`
- correlation length :math:`\lambda=(12, 3)^T`
- rotation angle :math:`\theta=\pi/8`

"""

import numpy as np
import gstools as gs

x = y = np.arange(100)
model = gs.Exponential(dim=2, var=1, len_scale=[12.0, 3.0], angles=np.pi / 8)
srf = gs.SRF(model, seed=20170519)
srf.structured([x, y])
srf.plot()

###############################################################################
# The anisotropy ratio could also have been set with

model = gs.Exponential(dim=2, var=1, len_scale=12, anis=0.25, angles=np.pi / 8)