.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/03_variogram/03_directional_2d.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_03_variogram_03_directional_2d.py: Directional variogram estimation and fitting in 2D -------------------------------------------------- In this example, we demonstrate how to estimate a directional variogram by setting the direction angles in 2D. Afterwards we will fit a model to this estimated variogram and show the result. .. GENERATED FROM PYTHON SOURCE LINES 10-16 .. code-block:: Python import numpy as np from matplotlib import pyplot as plt import gstools as gs .. GENERATED FROM PYTHON SOURCE LINES 17-18 Generating synthetic field with anisotropy and a rotation of 22.5 degree. .. GENERATED FROM PYTHON SOURCE LINES 18-25 .. code-block:: Python angle = np.pi / 8 model = gs.Exponential(dim=2, len_scale=[10, 5], angles=angle) x = y = range(101) srf = gs.SRF(model, seed=123456) field = srf((x, y), mesh_type="structured") .. GENERATED FROM PYTHON SOURCE LINES 26-28 Now we are going to estimate a directional variogram with an angular tolerance of 11.25 degree and a bandwith of 8. .. GENERATED FROM PYTHON SOURCE LINES 28-39 .. code-block:: Python bins = range(0, 40, 2) bin_center, dir_vario, counts = gs.vario_estimate( *((x, y), field, bins), direction=gs.rotated_main_axes(dim=2, angles=angle), angles_tol=np.pi / 16, bandwidth=8, mesh_type="structured", return_counts=True, ) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Afterwards we can use the estimated variogram to fit a model to it: .. GENERATED FROM PYTHON SOURCE LINES 41-48 .. code-block:: Python print("Original:") print(model) model.fit_variogram(bin_center, dir_vario) print("Fitted:") print(model) .. rst-class:: sphx-glr-script-out .. code-block:: none Original: Exponential(dim=2, var=1.0, len_scale=10.0, anis=[0.5], angles=[0.393]) Fitted: Exponential(dim=2, var=0.942, len_scale=9.14, anis=[0.529], angles=[0.393]) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Plotting. .. GENERATED FROM PYTHON SOURCE LINES 50-64 .. code-block:: Python fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[10, 5]) ax1.scatter(bin_center, dir_vario[0], label="emp. vario: pi/8") ax1.scatter(bin_center, dir_vario[1], label="emp. vario: pi*5/8") ax1.legend(loc="lower right") model.plot("vario_axis", axis=0, ax=ax1, x_max=40, label="fit on axis 0") model.plot("vario_axis", axis=1, ax=ax1, x_max=40, label="fit on axis 1") ax1.set_title("Fitting an anisotropic model") srf.plot(ax=ax2) plt.show() .. image-sg:: /examples/03_variogram/images/sphx_glr_03_directional_2d_001.png :alt: Fitting an anisotropic model, Field 2D structured: (101, 101) :srcset: /examples/03_variogram/images/sphx_glr_03_directional_2d_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 65-67 Without fitting a model, we see that the correlation length in the main direction is greater than the transversal one. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.912 seconds) .. _sphx_glr_download_examples_03_variogram_03_directional_2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03_directional_2d.ipynb <03_directional_2d.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03_directional_2d.py <03_directional_2d.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 03_directional_2d.zip <03_directional_2d.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_