-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy path00_simple_sum_model.py
61 lines (47 loc) · 2.26 KB
/
00_simple_sum_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
r"""
Creating a Sum Model
--------------------
This tutorial demonstrates how to create and use sum models in GSTools.
We'll combine a Spherical and a Gaussian covariance model to construct
a sum model, visualize its variogram, and generate spatial random fields.
Let's start with importing GSTools and setting up the domain size.
"""
import gstools as gs
x = y = range(100)
###############################################################################
# First, we create two individual covariance models: a :any:`Spherical` model and a
# :any:`Gaussian` model. The Spherical model with its short length scale
# will emphasize small-scale variability, while the Gaussian model with a larger length scale
# captures larger-scale patterns.
m0 = gs.Spherical(dim=2, var=2.0, len_scale=5.0)
m1 = gs.Gaussian(dim=2, var=1.0, len_scale=10.0)
###############################################################################
# Next, we create a sum model by adding these two models together.
# Let's visualize the resulting variogram alongside the individual models.
model = m0 + m1
ax = model.plot(x_max=20)
m0.plot(x_max=20, ax=ax)
m1.plot(x_max=20, ax=ax)
###############################################################################
# As shown, the Spherical model controls the behavior at shorter distances,
# while the Gaussian model dominates at longer distances. The ratio of influence
# is thereby controlled by the provided variances of the individual models.
#
# Using the sum model, we can generate a spatial random field. Let's visualize
# the field created by the sum model.
srf = gs.SRF(model, seed=20250107)
srf.structured((x, y))
srf.plot()
###############################################################################
# For comparison, we generate random fields using the individual models
# to observe their contributions more clearly.
srf0 = gs.SRF(m0, seed=20250107)
srf0.structured((x, y))
srf0.plot()
srf1 = gs.SRF(m1, seed=20250107)
srf1.structured((x, y))
srf1.plot()
###############################################################################
# As seen, the Gaussian model introduces large-scale structures, while the
# Spherical model influences the field's roughness. The sum model combines
# these effects, resulting in a field that reflects multi-scale variability.