.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01_random_field/01_srf_ensemble.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_01_random_field_01_srf_ensemble.py: Creating an Ensemble of Fields ------------------------------ Creating an ensemble of random fields would also be a great idea. Let's reuse most of the previous code. We will set the position tuple `pos` before generation to reuse it afterwards. .. GENERATED FROM PYTHON SOURCE LINES 10-22 .. code-block:: Python import matplotlib.pyplot as pt import numpy as np import gstools as gs x = y = np.arange(100) model = gs.Gaussian(dim=2, var=1, len_scale=10) srf = gs.SRF(model) srf.set_pos([x, y], "structured") .. GENERATED FROM PYTHON SOURCE LINES 23-27 This time, we did not provide a seed to :any:`SRF`, as the seeds will used during the actual computation of the fields. We will create four ensemble members, for better visualisation, save them in to srf class and in a first step, we will be using the loop counter as the seeds. .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python ens_no = 4 for i in range(ens_no): srf(seed=i, store=f"field{i}") .. GENERATED FROM PYTHON SOURCE LINES 33-35 Now let's have a look at the results. We can access the fields by name or index: .. GENERATED FROM PYTHON SOURCE LINES 35-42 .. code-block:: Python fig, ax = pt.subplots(2, 2, sharex=True, sharey=True) ax = ax.flatten() for i in range(ens_no): ax[i].imshow(srf[i].T, origin="lower") pt.show() .. image-sg:: /examples/01_random_field/images/sphx_glr_01_srf_ensemble_001.png :alt: 01 srf ensemble :srcset: /examples/01_random_field/images/sphx_glr_01_srf_ensemble_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 43-49 Using better Seeds ^^^^^^^^^^^^^^^^^^ It is not always a good idea to use incrementing seeds. Therefore GSTools provides a seed generator :any:`MasterRNG`. The loop, in which the fields are generated would then look like .. GENERATED FROM PYTHON SOURCE LINES 49-55 .. code-block:: Python from gstools.random import MasterRNG seed = MasterRNG(20170519) for i in range(ens_no): srf(seed=seed(), store=f"better_field{i}") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.417 seconds) .. _sphx_glr_download_examples_01_random_field_01_srf_ensemble.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_srf_ensemble.ipynb <01_srf_ensemble.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_srf_ensemble.py <01_srf_ensemble.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01_srf_ensemble.zip <01_srf_ensemble.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_