Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
LSchueler committed May 28, 2024
1 parent 1c755e4 commit 7c07f6e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
42 changes: 33 additions & 9 deletions examples/00_misc/06_fourier.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,52 @@
import gstools as gs

# We start off by defining the spatial grid.
x = np.linspace(0, 500, 256)
y = np.linspace(0, 500, 128)
L = np.array((500, 500))
x = np.linspace(0, L[0], 256)
y = np.linspace(0, L[1], 128)

# And by setting up a Gaussian covariance model with a correlation length
# scale which is roughly half the size of the grid.
model = gs.Gaussian(dim=2, var=1, len_scale=200)

# Next, we hand the cov. model to the spatial random field class
# and set the generator to `Fourier`. The higher the modes_no, the better
# the quality of the generated field, but also the computing time increases.
# The modes_truncation are the cut-off values of the Fourier modes and finally,
# the seed ensures that we generate the same random field each time.
# and set the generator to `Fourier`. We will let the class figure out the
# modes internally, by handing over `period` and `mode_rel_cutoff` which is the cutoff
# value of the spectral density, relative to the maximum spectral density at
# the origin. Simply put, we will use `mode_rel_cutoff`% of the spectral
# density for the calculations. The argument `period` is set to the domain
# size.
srf = gs.SRF(
model,
generator="Fourier",
modes_no=[16, 8],
modes_truncation=[16, 8],
mode_rel_cutoff=0.99,
period=L,
seed=1681903,
)

# Now, we can finally calculate the field with the given parameters.
# Now, we can calculate the field with the given parameters.
srf((x, y), mesh_type='structured')

# GSTools has a few simple visualization methods built in.
srf.plot()

# Alternatively, we could calculate the modes ourselves and hand them over to
# GSTools. Therefore, we set the cutoff values to absolut values in Fourier
# space. But always check, if you cover enough of the spectral density to not
# run into numerical problems.
modes_cutoff = [1., 1.]

# Next, we have to compute the numerical step size in Fourier space. This choice
# influences the periodicity, which we want to set to the domain size by
modes_delta = 2 * np.pi / L

# Now, we calculate the modes with
modes = [np.arange(0, modes_cutoff[d], modes_delta[d]) for d in 2]

# And we can create a new instance of the SRF class with our own modes.
srf_modes = gs.SRF(
model,
generator="Fourier",
modes=modes,
seed=494754,
)
13 changes: 7 additions & 6 deletions examples/00_misc/07_fourier_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@
import gstools as gs

# We start off by defining the spatial grid.
x = np.linspace(0, 500, 300)
y = np.linspace(0, 500, 200)
L = np.array((500, 500))
x = np.linspace(0, L[0], 300)
y = np.linspace(0, L[1], 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
# Same as before, we set up the spatial random field
srf = gs.SRF(
model,
generator="Fourier",
modes_no=[30, 20],
modes_truncation=[30, 20],
mode_rel_cutoff=0.999,
period=L,
seed=1681903,
)
# and computing it
# and compute it on our spatial domain
srf((x, y), mesh_type='structured')

# With the field generated, we can now apply transformations
Expand Down

0 comments on commit 7c07f6e

Please sign in to comment.