|
| 1 | +""" |
| 2 | +Generating a Transformed Periodic Random Field |
| 3 | +---------------------------------------------- |
| 4 | +
|
| 5 | +Building on the precious example, we are now going to generate periodic |
| 6 | +spatial random fields with a transformation applied, resulting in a level set. |
| 7 | +""" |
| 8 | + |
| 9 | +import numpy as np |
| 10 | + |
| 11 | +import gstools as gs |
| 12 | + |
| 13 | +# We start off by defining the spatial grid. As in the previous example, we do |
| 14 | +# not want to include the endpoints. |
| 15 | +L = np.array((500, 400)) |
| 16 | +x = np.linspace(0, L[0], 300, endpoint=False) |
| 17 | +y = np.linspace(0, L[1], 200, endpoint=False) |
| 18 | + |
| 19 | +# Instead of using a Gaussian covariance model, we will use the much rougher |
| 20 | +# exponential model and we will introduce an anisotropy by using two different |
| 21 | +# length scales in the x- and y-directions |
| 22 | +model = gs.Exponential(dim=2, var=2, len_scale=[80, 20]) |
| 23 | + |
| 24 | +# Same as before, we set up the spatial random field. But this time, we will |
| 25 | +# use a periodicity which is equal to the domain size in x-direction, but |
| 26 | +# half the domain size in y-direction. And we will use different `mode_no` for |
| 27 | +# the different dimensions. |
| 28 | +srf = gs.SRF( |
| 29 | + model, |
| 30 | + generator="Fourier", |
| 31 | + period=[L[0], L[1] / 2], |
| 32 | + mode_no=[30, 20], |
| 33 | + seed=1681903, |
| 34 | +) |
| 35 | +# and compute it on our spatial domain |
| 36 | +srf((x, y), mesh_type="structured") |
| 37 | + |
| 38 | +# With the field generated, we can now apply transformations starting with a |
| 39 | +# discretization of the field into 4 different values |
| 40 | +thresholds = np.linspace(np.min(srf.field), np.max(srf.field), 4) |
| 41 | +srf.transform("discrete", store="transform_discrete", values=thresholds) |
| 42 | +srf.plot("transform_discrete") |
| 43 | + |
| 44 | +# This is already a nice result, but we want to pronounce the peaks of the |
| 45 | +# field. We can do this by applying a log-normal transformation on top |
| 46 | +srf.transform( |
| 47 | + "lognormal", field="transform_discrete", store="transform_lognormal" |
| 48 | +) |
| 49 | +srf.plot("transform_lognormal") |
0 commit comments