Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
LSchueler committed Dec 8, 2024
1 parent 5cd930e commit f6cbbf9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
15 changes: 11 additions & 4 deletions examples/11_plurigaussian/00_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@
pgs = gs.PGS(dim, [field1, field2], L)

###############################################################################
# Finally, we can plot the PGS, but we will also show the field `L`.
# Finally, we can plot the PGS, but we will also show the field `L` and the two
# original Gaussian fields.

fig, axs = plt.subplots(1, 2)
fig, axs = plt.subplots(2, 2)

axs[0].imshow(L, cmap="copper")
axs[1].imshow(pgs.P, cmap="copper")
axs[0, 0].imshow(field1, cmap="copper")
axs[0, 1].imshow(field2, cmap="copper")
axs[1, 0].imshow(L, cmap="copper")
axs[1, 1].imshow(pgs.P, cmap="copper")

# For more information on Plurigaussian fields and how they naturally extend
# truncated Gaussian fields, we can recommend the book
# [Plurigaussian Simulations in Geosciences](https://doi.org/10.1007/978-3-642-19607-2)
32 changes: 24 additions & 8 deletions examples/11_plurigaussian/01_pgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
model2 = gs.Gaussian(dim=dim, var=1, len_scale=[1, 20], angles=np.pi / 4)
srf2 = gs.SRF(model2, seed=19970221)
field2 = srf2.structured([x, y])
field1 += 5.0

###############################################################################
# Internally, each field's values are mapped along an axis, which can be nicely
Expand Down Expand Up @@ -69,14 +70,25 @@
# First, we calculate the indices of the L field, which we need for manually
# plotting L together with the scatter plot. Normally they are computed internally.

l = np.floor(field1.min()) - 1
h = np.ceil(field1.max()) + 1
m = (h + l) / 2.0
dist = max(np.abs(h - m), np.abs(l - m))
x_mean = field1.mean()
x_l = np.linspace(
np.floor(field1[0].min()) - 1,
np.ceil(field1[0].max()) + 1,
x_mean - dist,
x_mean + dist,
L.shape[0],
)

l = np.floor(field1.min()) - 1
h = np.ceil(field1.max()) + 1
m = (h + l) / 2.0
dist = max(np.abs(h - m), np.abs(l - m))
y_mean = field2.mean()
y_l = np.linspace(
np.floor(field1[1].min()) - 1,
np.ceil(field1[1].max()) + 1,
y_mean - dist,
y_mean + dist,
L.shape[1],
)

Expand All @@ -89,10 +101,14 @@
# And now to some plotting. Unfortunately, matplotlib likes to mess around with
# the aspect ratios of the plots, so the left panel is a bit stretched.

fig, axs = plt.subplots(1, 2)
axs[0].scatter(field1.flatten(), field2.flatten(), s=0.1, color="C0")
axs[0].pcolormesh(x_l, y_l, L.T, alpha=0.3)
axs[1].imshow(pgs.P, cmap="copper")
fig, axs = plt.subplots(2, 2)
axs[0, 0].imshow(field1, cmap="copper")
axs[0, 1].imshow(field2, cmap="copper")
axs[1, 0].scatter(field1.flatten(), field2.flatten(), s=0.1, color="C0")
axs[1, 0].pcolormesh(x_l, y_l, L.T, alpha=0.3)

axs[1, 1].imshow(pgs.P, cmap="copper")
plt.show()

###############################################################################
# The black areas show the category 0 and the orange areas show category 1. We
Expand Down
10 changes: 6 additions & 4 deletions examples/11_plurigaussian/02_spatial_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@
pgs = gs.PGS(dim, [field1, field2], L)

###############################################################################
# And now the plotting of `L` and the PGS.
# And now the plotting of the two Gaussian fields, `L`, and the PGS.

fig, axs = plt.subplots(1, 2)
fig, axs = plt.subplots(2, 2)

axs[0].imshow(L, cmap="copper")
axs[1].imshow(pgs.P, cmap="copper")
axs[0, 0].imshow(field1, cmap="copper")
axs[0, 1].imshow(field2, cmap="copper")
axs[1, 0].imshow(L, cmap="copper")
axs[1, 1].imshow(pgs.P, cmap="copper")

###############################################################################
# We can see that the two upper light and medium brown rectangles both fill up
Expand Down
10 changes: 6 additions & 4 deletions examples/11_plurigaussian/03_correlations.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@
pgs = gs.PGS(dim, [field1, field2], L)

###############################################################################
# And now the plotting of `L` and the PGS.
# And now the plotting of the two Gaussian fields, `L`, and the PGS.

fig, axs = plt.subplots(1, 2)
fig, axs = plt.subplots(2, 2)

axs[0].imshow(L, cmap="copper")
axs[1].imshow(pgs.P, cmap="copper")
axs[0, 0].imshow(field1, cmap="copper")
axs[0, 1].imshow(field2, cmap="copper")
axs[1, 0].imshow(L, cmap="copper")
axs[1, 1].imshow(pgs.P, cmap="copper")
plt.show()

###############################################################################
Expand Down

0 comments on commit f6cbbf9

Please sign in to comment.