Skip to content

Commit 7849284

Browse files
committed
Improve Fourier examples
1 parent 29d0ea6 commit 7849284

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

examples/01_random_field/08_fourier.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,29 @@
1111

1212
import gstools as gs
1313

14-
# We start off by defining the spatial grid.
15-
L = np.array((500, 500))
16-
x = np.linspace(0, L[0], 256)
17-
y = np.linspace(0, L[1], 128)
18-
19-
# And by setting up a Gaussian covariance model with a correlation length
20-
# scale which is roughly half the size of the grid.
14+
# We start off by defining the spatial grid. For the sake of simplicity, we
15+
# use a square domain. We set the optional argument `endpoint` to `False`, to
16+
# not make the domain in each dimension one grid cell larger than the
17+
# periodicity.
18+
L = 500.0
19+
x = np.linspace(0, L, 256, endpoint=False)
20+
y = np.linspace(0, L, 128, endpoint=False)
21+
22+
Now, we create a Gaussian covariance model with a correlation length which is
23+
# roughly half the size of the grid.
2124
model = gs.Gaussian(dim=2, var=1, len_scale=200)
2225

23-
# Next, we hand the cov. model to the spatial random field class
24-
# and set the generator to `Fourier`. The `mode_no` argument sets the number of
25-
# Fourier modes per dimension. The argument `period` is set to the domain size.
26+
# Next, we hand the cov. model to the spatial random field class `SRF`
27+
# and set the generator to `"Fourier"`. The argument `period` is set to the
28+
# domain size. If only a single number is given, the same periodicity is
29+
# applied in each dimension, as shown in this example. The `mode_no` argument
30+
# sets the number of Fourier modes. If only an integer is given, that number
31+
# of modes is used for all dimensions.
2632
srf = gs.SRF(
2733
model,
2834
generator="Fourier",
29-
mode_no=[32, 32],
3035
period=L,
36+
mode_no=32,
3137
seed=1681903,
3238
)
3339

examples/01_random_field/09_fourier_trans.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,33 @@
1010

1111
import gstools as gs
1212

13-
# We start off by defining the spatial grid.
14-
L = np.array((500, 500))
15-
x = np.linspace(0, L[0], 300)
16-
y = np.linspace(0, L[1], 200)
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)
1718

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

23-
# Same as before, we set up the spatial random field
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.
2428
srf = gs.SRF(
2529
model,
2630
generator="Fourier",
27-
mode_no=[32, 32],
28-
period=L,
31+
period=[L[0], L[1]/2],
32+
mode_no=[30, 20],
2933
seed=1681903,
3034
)
3135
# and compute it on our spatial domain
3236
srf((x, y), mesh_type="structured")
3337

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

0 commit comments

Comments
 (0)