.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/02_cov_model/00_intro.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_02_cov_model_00_intro.py: Introductory example ==================== Let us start with a short example of a self defined model (Of course, we provide a lot of predefined models [See: :any:`gstools.covmodel`], but they all work the same way). Therefore we reimplement the Gaussian covariance model by defining just the "normalized" `correlation `_ function: .. GENERATED FROM PYTHON SOURCE LINES 13-25 .. code-block:: Python import numpy as np import gstools as gs # use CovModel as the base-class class Gau(gs.CovModel): def cor(self, h): return np.exp(-(h**2)) .. GENERATED FROM PYTHON SOURCE LINES 26-28 Here the parameter ``h`` stands for the normalized range ``r / len_scale``. Now we can instantiate this model: .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python model = Gau(dim=2, var=2.0, len_scale=10) .. GENERATED FROM PYTHON SOURCE LINES 32-33 To have a look at the variogram, let's plot it: .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python model.plot() .. image-sg:: /examples/02_cov_model/images/sphx_glr_00_intro_001.png :alt: 00 intro :srcset: /examples/02_cov_model/images/sphx_glr_00_intro_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-40 This is almost identical to the already provided :any:`Gaussian` model. There, a scaling factor is implemented so the len_scale coincides with the integral scale: .. GENERATED FROM PYTHON SOURCE LINES 40-45 .. code-block:: Python gau_model = gs.Gaussian(dim=2, var=2.0, len_scale=10) gau_model.plot() .. image-sg:: /examples/02_cov_model/images/sphx_glr_00_intro_002.png :alt: 00 intro :srcset: /examples/02_cov_model/images/sphx_glr_00_intro_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-60 Parameters ---------- We already used some parameters, which every covariance models has. The basic ones are: - **dim** : dimension of the model - **var** : variance of the model (on top of the subscale variance) - **len_scale** : length scale of the model - **nugget** : nugget (subscale variance) of the model These are the common parameters used to characterize a covariance model and are therefore used by every model in GSTools. You can also access and reset them: .. GENERATED FROM PYTHON SOURCE LINES 60-69 .. code-block:: Python print("old model:", model) model.dim = 3 model.var = 1 model.len_scale = 15 model.nugget = 0.1 print("new model:", model) .. rst-class:: sphx-glr-script-out .. code-block:: none old model: Gau(dim=2, var=2.0, len_scale=10.0) new model: Gau(dim=3, var=1.0, len_scale=15.0, nugget=0.1) .. GENERATED FROM PYTHON SOURCE LINES 70-76 .. note:: - The sill of the variogram is calculated by ``sill = variance + nugget`` So we treat the variance as everything **above** the nugget, which is sometimes called **partial sill**. - A covariance model can also have additional parameters. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.086 seconds) .. _sphx_glr_download_examples_02_cov_model_00_intro.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 00_intro.ipynb <00_intro.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 00_intro.py <00_intro.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 00_intro.zip <00_intro.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_