.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01_random_field/08_fourier.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_08_fourier.py: Generating a Simple Periodic Random Field ----------------------------------------- In this simple example we are going to learn how to generate periodic spatial random fields. The Fourier method comes naturally with the property of periodicity, so we'll use it to create the random field. .. GENERATED FROM PYTHON SOURCE LINES 9-45 .. image-sg:: /examples/01_random_field/images/sphx_glr_08_fourier_001.png :alt: Field 2D structured: (256, 128) :srcset: /examples/01_random_field/images/sphx_glr_08_fourier_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import gstools as gs # We start off by defining the spatial grid. For the sake of simplicity, we # use a square domain. We set the optional argument `endpoint` to `False`, to # not make the domain in each dimension one grid cell larger than the # periodicity. L = 500.0 x = np.linspace(0, L, 256, endpoint=False) y = np.linspace(0, L, 128, endpoint=False) # Now, we create a Gaussian covariance model with a correlation length which is # roughly half the size of the grid. model = gs.Gaussian(dim=2, var=1, len_scale=200) # Next, we hand the cov. model to the spatial random field class `SRF` # and set the generator to `"Fourier"`. The argument `period` is set to the # domain size. If only a single number is given, the same periodicity is # applied in each dimension, as shown in this example. The `mode_no` argument # sets the number of Fourier modes. If only an integer is given, that number # of modes is used for all dimensions. srf = gs.SRF( model, generator="Fourier", period=L, mode_no=32, seed=1681903, ) # Now, we can calculate the field with the given parameters. srf((x, y), mesh_type="structured") # GSTools has a few simple visualization methods built in. srf.plot() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.737 seconds) .. _sphx_glr_download_examples_01_random_field_08_fourier.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 08_fourier.ipynb <08_fourier.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 08_fourier.py <08_fourier.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 08_fourier.zip <08_fourier.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_