.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/09_spatio_temporal/02_precip_2d.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_09_spatio_temporal_02_precip_2d.py: Creating a 2D Synthetic Precipitation Field ------------------------------------------- In this example we'll create a time series of a 2D synthetic precipitation field. Very similar to the previous tutorial, we'll start off by creating a Gaussian random field with an exponential variogram, which seems to reproduce the spatial correlations of precipitation fields quite well. We'll create a daily timeseries over a two dimensional domain of 50km x 40km. This workflow is suited for sub daily precipitation time series. .. GENERATED FROM PYTHON SOURCE LINES 14-53 .. code-block:: Python import matplotlib.animation as animation import matplotlib.pyplot as plt import numpy as np import gstools as gs # fix the seed for reproducibility seed = 20170521 # 1st spatial axis of 50km with a resolution of 1km x = np.arange(0, 50, 1.0) # 2nd spatial axis of 40km with a resolution of 1km y = np.arange(0, 40, 1.0) # half daily timesteps over three months t = np.arange(0.0, 90.0, 0.5) # space-time anisotropy ratio given in units d / km st_anis = 0.4 # an exponential variogram with a corr. lengths of 5km, 5km, and 2d model = gs.Exponential( temporal=True, spatial_dim=2, var=1, len_scale=5, anis=st_anis ) # create a spatial random field instance srf = gs.SRF(model, seed=seed) pos, time = [x, y], [t] # the Gaussian random field srf.structured(pos + time) # account for the skewness and the dry periods cutoff = 0.55 gs.transform.boxcox(srf, lmbda=0.5, shift=-1.0 / cutoff) # adjust the amount of precipitation amount = 4.0 srf.field *= amount .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/gstools/envs/v1.7.0/lib/python3.11/site-packages/gstools/transform/array.py:137: UserWarning: Box-Cox: Some values will be cut off! warn("Box-Cox: Some values will be cut off!") .. GENERATED FROM PYTHON SOURCE LINES 54-55 plot the 2d precipitation field over time as an animation. .. GENERATED FROM PYTHON SOURCE LINES 55-77 .. code-block:: Python def _update_ani(time_step): im.set_array(srf.field[:, :, time_step].T) return (im,) fig, ax = plt.subplots() im = ax.imshow( srf.field[:, :, 0].T, cmap="Blues", interpolation="bicubic", origin="lower", ) cbar = fig.colorbar(im) cbar.ax.set_ylabel(r"Precipitation $P$ / mm") ax.set_xlabel(r"$x$ / km") ax.set_ylabel(r"$y$ / km") ani = animation.FuncAnimation( fig, _update_ani, len(t), interval=100, blit=True ) .. container:: sphx-glr-animation .. raw:: html
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 48.715 seconds) .. _sphx_glr_download_examples_09_spatio_temporal_02_precip_2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_precip_2d.ipynb <02_precip_2d.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_precip_2d.py <02_precip_2d.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02_precip_2d.zip <02_precip_2d.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_