.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/05_kriging/02_pykrige_interface.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_05_kriging_02_pykrige_interface.py: Interface to PyKrige -------------------- To use fancier methods like `regression kriging `__, we provide an interface to `PyKrige `__ (>v1.5), which means you can pass a GSTools covariance model to the kriging routines of PyKrige. To demonstrate the general workflow, we compare ordinary kriging of PyKrige with the corresponding GSTools routine in 2D: .. GENERATED FROM PYTHON SOURCE LINES 14-30 .. code-block:: Python import numpy as np from matplotlib import pyplot as plt from pykrige.ok import OrdinaryKriging import gstools as gs # conditioning data cond_x = [0.3, 1.9, 1.1, 3.3, 4.7] cond_y = [1.2, 0.6, 3.2, 4.4, 3.8] cond_val = [0.47, 0.56, 0.74, 1.47, 1.74] # grid definition for output field gridx = np.arange(0.0, 5.5, 0.1) gridy = np.arange(0.0, 6.5, 0.1) .. GENERATED FROM PYTHON SOURCE LINES 31-32 A GSTools based :any:`Gaussian` covariance model: .. GENERATED FROM PYTHON SOURCE LINES 32-37 .. code-block:: Python model = gs.Gaussian( dim=2, len_scale=1, anis=0.2, angles=-0.5, var=0.5, nugget=0.1 ) .. GENERATED FROM PYTHON SOURCE LINES 38-45 Ordinary Kriging with PyKrige ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ One can pass the defined GSTools model as variogram model, which will `not` be fitted to the given data. By providing the GSTools model, rotation and anisotropy are also automatically defined: .. GENERATED FROM PYTHON SOURCE LINES 45-51 .. code-block:: Python OK1 = OrdinaryKriging(cond_x, cond_y, cond_val, variogram_model=model) z1, ss1 = OK1.execute("grid", gridx, gridy) plt.imshow(z1, origin="lower") plt.show() .. image-sg:: /examples/05_kriging/images/sphx_glr_02_pykrige_interface_001.png :alt: 02 pykrige interface :srcset: /examples/05_kriging/images/sphx_glr_02_pykrige_interface_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-60 Ordinary Kriging with GSTools ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The :any:`Ordinary` kriging class is provided by GSTools as a shortcut to define ordinary kriging with the general :any:`Krige` class. PyKrige's routines are using exact kriging by default (when given a nugget). To reproduce this behavior in GSTools, we have to set ``exact=True``. .. GENERATED FROM PYTHON SOURCE LINES 60-65 .. code-block:: Python OK2 = gs.krige.Ordinary(model, [cond_x, cond_y], cond_val, exact=True) OK2.structured([gridx, gridy]) ax = OK2.plot() ax.set_aspect("equal") .. image-sg:: /examples/05_kriging/images/sphx_glr_02_pykrige_interface_002.png :alt: Field 2D structured: (55, 65) :srcset: /examples/05_kriging/images/sphx_glr_02_pykrige_interface_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.151 seconds) .. _sphx_glr_download_examples_05_kriging_02_pykrige_interface.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_pykrige_interface.ipynb <02_pykrige_interface.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_pykrige_interface.py <02_pykrige_interface.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02_pykrige_interface.zip <02_pykrige_interface.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_