Skip to content

Commit

Permalink
Add another example, including field transf.
Browse files Browse the repository at this point in the history
  • Loading branch information
LSchueler committed Nov 10, 2023
1 parent d55e52b commit 362f501
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/00_misc/06_fourier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Generating a Periodic Random Field
----------------------------------
Generating a Simple Periodic Random Field
-----------------------------------------
In this simple example we are going to learn how to generate periodic spatial
random fields. The Fourier method comes naturally with the property of
Expand Down
41 changes: 41 additions & 0 deletions examples/00_misc/07_fourier_trans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Generating a Transformed Periodic Random Field
----------------------------------------------
Building on the precious example, we are now going to generate periodic
spatial random fields with a transformation applied, resulting in a level set.
"""

import numpy as np
import gstools as gs

# We start off by defining the spatial grid.
x = np.linspace(0, 500, 300)
y = np.linspace(0, 500, 200)

# Instead of using a Gaussian covariance model, we will use the much rougher
# exponential model and we will introduce an anisotropy by using two different
# length scales in the x- and y-axes
model = gs.Exponential(dim=2, var=2, len_scale=[30, 20])

# Very similar as before, setting up the spatial random field
srf = gs.SRF(
model,
generator="Fourier",
modes_no=[30, 20],
modes_truncation=[30, 20],
seed=1681903,
)
# and computing it
srf((x, y), mesh_type='structured')

# With the field generated, we can now apply transformations
# starting with a discretization of the field into 4 different values
thresholds = np.linspace(np.min(srf.field), np.max(srf.field), 4)
srf.transform("discrete", store="transform_discrete", values=thresholds)
srf.plot("transform_discrete")

# This is already a nice result, but we want to pronounce the peaks of the
# field. We can do this by applying a log-normal transformation on top
srf.transform("lognormal", field="transform_discrete", store="transform_lognormal")
srf.plot("transform_lognormal")

0 comments on commit 362f501

Please sign in to comment.