Juyter Logo

Using an Unstructured Grid

%matplotlib widget
import matplotlib.pyplot as plt
# turn of warnings
import warnings

For many applications, the random fields are needed on an unstructured grid. Normally, such a grid would be read in, but we can simply generate one and then create a random field at those coordinates.

import numpy as np
import gstools as gs

Creating our own unstructured grid

seed = gs.random.MasterRNG(20220425)
rng = np.random.RandomState(seed())
x = rng.randint(0, 100, size=10000)
y = rng.randint(0, 100, size=10000)

model = gs.Exponential(dim=2, var=1, len_scale=[12, 3], angles=np.pi / 8)
srf = gs.SRF(model, seed=20220425)
field = srf((x, y))
ax = srf.plot(contour_plot=True)

Comparing this image to the previous one, you can see that be using the same seed, the same field can be computed on different grids.

mesh = srf.to_pyvista()