-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
390 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
examples/06_conditioned_fields/01_2D_condition_ensemble.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Creating an Ensemble of conditioned 2D Fields | ||
--------------------------------------------- | ||
Let's create an ensemble of conditioned random fields in 2D. | ||
""" | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import gstools as gs | ||
|
||
|
||
# conditioning data (x, y, value) | ||
cond_pos = [[0.3, 1.9, 1.1, 3.3, 4.7], [1.2, 0.6, 3.2, 4.4, 3.8]] | ||
cond_val = [0.47, 0.56, 0.74, 1.47, 1.74] | ||
|
||
# grid definition for output field | ||
x = np.arange(0, 5, 0.1) | ||
y = np.arange(0, 5, 0.1) | ||
|
||
model = gs.Gaussian(dim=2, var=0.5, len_scale=5, anis=0.5, angles=-0.5) | ||
krige = gs.Krige(model, cond_pos=cond_pos, cond_val=cond_val) | ||
cond_srf = gs.CondSRF(krige) | ||
|
||
############################################################################### | ||
# We create a list containing the generated conditioned fields. | ||
|
||
ens_no = 4 | ||
field = [] | ||
for i in range(ens_no): | ||
field.append(cond_srf.structured([x, y], seed=i)) | ||
|
||
############################################################################### | ||
# Now let's have a look at the pairwise differences between the generated | ||
# fields. We will see, that they coincide at the given conditions. | ||
|
||
fig, ax = plt.subplots(ens_no + 1, ens_no + 1, figsize=(8, 8)) | ||
# plotting kwargs for scatter and image | ||
sc_kwargs = dict(c=cond_val, edgecolors="k", vmin=0, vmax=np.max(field)) | ||
im_kwargs = dict(extent=2 * [0, 5], origin="lower", vmin=0, vmax=np.max(field)) | ||
for i in range(ens_no): | ||
# conditioned fields and conditions | ||
ax[i + 1, 0].imshow(field[i].T, **im_kwargs) | ||
ax[i + 1, 0].scatter(*cond_pos, **sc_kwargs) | ||
ax[i + 1, 0].set_ylabel(f"Field {i+1}", fontsize=10) | ||
ax[0, i + 1].imshow(field[i].T, **im_kwargs) | ||
ax[0, i + 1].scatter(*cond_pos, **sc_kwargs) | ||
ax[0, i + 1].set_title(f"Field {i+1}", fontsize=10) | ||
# absolute differences | ||
for j in range(ens_no): | ||
ax[i + 1, j + 1].imshow(np.abs(field[i] - field[j]).T, **im_kwargs) | ||
|
||
# beautify plots | ||
ax[0, 0].axis("off") | ||
for a in ax.flatten(): | ||
a.set_xticklabels([]), a.set_yticklabels([]) | ||
a.set_xticks([]), a.set_yticks([]) | ||
fig.subplots_adjust(wspace=0, hspace=0) | ||
fig.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,46 @@ | ||
Spatio-Temporal Modeling | ||
======================== | ||
|
||
Spatio-Temporal modelling can provide insights on time depending processes | ||
like rainfall, air temperature or crop yield. | ||
|
||
GSTools provides the metric spatio-temporal model for all covariance models | ||
by enhancing the spatial model dimension with a time dimesion to result in | ||
the spatio-temporal dimension ``st_dim`` and setting a | ||
spatio-temporal anisotropy ratio ``st_anis``: | ||
|
||
.. code-block:: python | ||
import gstools as gs | ||
dim = 3 # spatial dimension | ||
st_dim = dim + 1 | ||
st_anis = 0.4 | ||
model = gs.Exponential(dim=st_dim, anis=st_anis) | ||
Since it is given in the name "spatio-temporal", | ||
we will always treat the time as last dimension. | ||
|
||
This enables to have spatial anisotropy and rotation defined as in | ||
non-temporal models, without altering the behavior in the time dimension: | ||
|
||
.. code-block:: python | ||
anis = [0.4, 0.2] # spatial anisotropy in 3D | ||
angles = [0.5, 0.4, 0.3] # spatial rotation in 3D | ||
model = gs.Exponential(dim=st_dim, anis=anis + [st_anis], angles=angles) | ||
In order to generate spatio-temporal position tuples, GSTools provides a | ||
convenient function :any:`generate_st_grid`: | ||
|
||
.. code-block:: python | ||
pos = ... | ||
time = range(10) | ||
st_pos = gs.generate_st_grid(pos, time) | ||
st_rf = SRF(st_model) | ||
st_field = st_rf(st_pos).reshape(-1, len(time)) | ||
Then you we access the different time-steps with the last index. | ||
|
||
Examples | ||
-------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.