.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/12_sum_model/00_simple_sum_model.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_12_sum_model_00_simple_sum_model.py: Creating a Sum Model -------------------- This tutorial demonstrates how to create and use sum models in GSTools. We'll combine a Spherical and a Gaussian covariance model to construct a sum model, visualize its variogram, and generate spatial random fields. Let's start with importing GSTools and setting up the domain size. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: Python import gstools as gs x = y = range(100) .. GENERATED FROM PYTHON SOURCE LINES 17-21 First, we create two individual covariance models: a :any:`Spherical` model and a :any:`Gaussian` model. The Spherical model with its short length scale will emphasize small-scale variability, while the Gaussian model with a larger length scale captures larger-scale patterns. .. GENERATED FROM PYTHON SOURCE LINES 21-25 .. code-block:: Python m0 = gs.Spherical(dim=2, var=2.0, len_scale=5.0) m1 = gs.Gaussian(dim=2, var=1.0, len_scale=10.0) .. GENERATED FROM PYTHON SOURCE LINES 26-28 Next, we create a sum model by adding these two models together. Let's visualize the resulting variogram alongside the individual models. .. GENERATED FROM PYTHON SOURCE LINES 28-34 .. code-block:: Python model = m0 + m1 ax = model.plot(x_max=20) m0.plot(x_max=20, ax=ax) m1.plot(x_max=20, ax=ax) .. image-sg:: /examples/12_sum_model/images/sphx_glr_00_simple_sum_model_001.png :alt: 00 simple sum model :srcset: /examples/12_sum_model/images/sphx_glr_00_simple_sum_model_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-41 As shown, the Spherical model controls the behavior at shorter distances, while the Gaussian model dominates at longer distances. The ratio of influence is thereby controlled by the provided variances of the individual models. Using the sum model, we can generate a spatial random field. Let's visualize the field created by the sum model. .. GENERATED FROM PYTHON SOURCE LINES 41-46 .. code-block:: Python srf = gs.SRF(model, seed=20250107) srf.structured((x, y)) srf.plot() .. image-sg:: /examples/12_sum_model/images/sphx_glr_00_simple_sum_model_002.png :alt: Field 2D structured: (100, 100) :srcset: /examples/12_sum_model/images/sphx_glr_00_simple_sum_model_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-49 For comparison, we generate random fields using the individual models to observe their contributions more clearly. .. GENERATED FROM PYTHON SOURCE LINES 49-58 .. code-block:: Python srf0 = gs.SRF(m0, seed=20250107) srf0.structured((x, y)) srf0.plot() srf1 = gs.SRF(m1, seed=20250107) srf1.structured((x, y)) srf1.plot() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/12_sum_model/images/sphx_glr_00_simple_sum_model_003.png :alt: Field 2D structured: (100, 100) :srcset: /examples/12_sum_model/images/sphx_glr_00_simple_sum_model_003.png :class: sphx-glr-multi-img * .. image-sg:: /examples/12_sum_model/images/sphx_glr_00_simple_sum_model_004.png :alt: Field 2D structured: (100, 100) :srcset: /examples/12_sum_model/images/sphx_glr_00_simple_sum_model_004.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 59-62 As seen, the Gaussian model introduces large-scale structures, while the Spherical model influences the field's roughness. The sum model combines these effects, resulting in a field that reflects multi-scale variability. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.023 seconds) .. _sphx_glr_download_examples_12_sum_model_00_simple_sum_model.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 00_simple_sum_model.ipynb <00_simple_sum_model.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 00_simple_sum_model.py <00_simple_sum_model.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 00_simple_sum_model.zip <00_simple_sum_model.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_