.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/ch3-Interpolations/ch3_1_kriging_interpolation_and_simulation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_ch3-Interpolations_ch3_1_kriging_interpolation_and_simulation.py: 3.1: Simple example of kriging in gempy ======================================= .. GENERATED FROM PYTHON SOURCE LINES 8-13 In this notebook it will be shown how to create a kriged or simulated field in a simple geological model in gempy. We start by creating a simple model with three horizontally layered units, as shown in the gempy examples. .. GENERATED FROM PYTHON SOURCE LINES 15-16 Importing GemPy .. GENERATED FROM PYTHON SOURCE LINES 16-27 .. code-block:: python3 import gempy as gp # Importing auxiliary libraries import numpy as np import matplotlib.pyplot as plt # new for this from gempy.assets import kriging np.random.seed(5555) .. GENERATED FROM PYTHON SOURCE LINES 28-30 Creating the model by importing the input data and displaying it: .. GENERATED FROM PYTHON SOURCE LINES 32-37 .. code-block:: python3 data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/' geo_data = gp.create_data('kriging', extent=[0, 1000, 0, 50, 0, 1000], resolution=[50, 1, 50], path_o=data_path + "/data/input_data/jan_models/model1_orientations.csv", path_i=data_path + "/data/input_data/jan_models/model1_surface_points.csv") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Active grids: ['regular'] .. GENERATED FROM PYTHON SOURCE LINES 38-40 Setting and ordering the units and series: .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. code-block:: python3 gp.map_stack_to_surfaces(geo_data, {"Strat_Series": ('rock2', 'rock1'), "Basement_Series": ('basement')}) .. raw:: html
surface series order_surfaces color id
0 rock2 Strat_Series 1 #015482 1
1 rock1 Strat_Series 2 #9f0052 2
2 basement Basement_Series 1 #ffbe00 3


.. GENERATED FROM PYTHON SOURCE LINES 46-48 Calculating the model: .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: python3 interp_data = gp.set_interpolator(geo_data, compile_theano=True, theano_optimizer='fast_compile') .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Setting kriging parameters to their default values. Compiling theano function... Level of Optimization: fast_compile Device: cpu Precision: float64 Number of faults: 0 Compilation Done! Kriging values: values range 1415.1 $C_o$ 47678.57 drift equations [3, 3] .. GENERATED FROM PYTHON SOURCE LINES 54-55 no mesh computed as basically 2D model .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: python3 sol = gp.compute_model(geo_data, compute_mesh=False) .. GENERATED FROM PYTHON SOURCE LINES 58-60 So here is the very simple, basically 2D model that we created: .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: python3 gp.plot_2d(geo_data, cell_number=0, show_data=False) .. image:: /tutorials/ch3-Interpolations/images/sphx_glr_ch3_1_kriging_interpolation_and_simulation_001.png :alt: Cell Number: 0 Direction: y :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 65-75 1) Creating domain ------------------ Let us assume we have a couple of measurements in a domain of interest within our model. In our case the unit of interest is the central rock layer (rock1). In the kriging module we can define the domain by handing over a number of surfaces by id - in this case the id of rock1 is 2. In addition we define four input data points in cond_data, each defined by x,y,z coordinate and a measurement value. .. GENERATED FROM PYTHON SOURCE LINES 77-78 conditioning data (data measured at locations) .. GENERATED FROM PYTHON SOURCE LINES 78-81 .. code-block:: python3 cond_data = np.array([[100, .5, 500, 2], [900, .5, 500, 1], [500, .5, 550, 1], [300, .5, 400, 5]]) .. GENERATED FROM PYTHON SOURCE LINES 82-83 creating a domain object from the gempy solution, a defined domain conditioning data .. GENERATED FROM PYTHON SOURCE LINES 83-85 .. code-block:: python3 domain = kriging.domain(model=sol, domain=[2], data=cond_data) .. GENERATED FROM PYTHON SOURCE LINES 86-89 2) Creating a variogram model ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 91-94 .. code-block:: python3 variogram_model = kriging.variogram_model(theoretical_model='exponential', range_=200, sill=np.var(cond_data[:, 3])) .. GENERATED FROM PYTHON SOURCE LINES 95-98 .. code-block:: python3 variogram_model.plot(type_='both', show_parameters=True) plt.show() .. image:: /tutorials/ch3-Interpolations/images/sphx_glr_ch3_1_kriging_interpolation_and_simulation_002.png :alt: Models of spatial correlation :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 99-102 3) Kriging interpolation ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 105-108 In the following we define an object called kriging_model and set all input parameters. Finally we generate the kriged field. .. GENERATED FROM PYTHON SOURCE LINES 110-112 .. code-block:: python3 solution = kriging.create_kriged_field(domain, variogram_model) .. GENERATED FROM PYTHON SOURCE LINES 113-117 The result of our calculation is saved in the following dataframe, containing an estimated value and the kriging variance for each point in the grid: .. GENERATED FROM PYTHON SOURCE LINES 119-121 .. code-block:: python3 solution.results_df.head() .. raw:: html
X Y Z estimated value estimation variance
0 10.0 25.0 410.0 2.24 2.13
1 10.0 25.0 430.0 2.20 2.01
2 10.0 25.0 450.0 2.15 1.90
3 10.0 25.0 470.0 2.10 1.81
4 10.0 25.0 490.0 2.07 1.77


.. GENERATED FROM PYTHON SOURCE LINES 122-125 It is also possible to plot the results in cross section similar to the way gempy models are plotted. .. GENERATED FROM PYTHON SOURCE LINES 127-132 .. code-block:: python3 solution.plot_results(geo_data=geo_data, prop='val', contour=False, direction='y', cell_number=0, alpha=0.7, show_data=False, legend=True) plt.show() .. image:: /tutorials/ch3-Interpolations/images/sphx_glr_ch3_1_kriging_interpolation_and_simulation_003.png :alt: ch3 1 kriging interpolation and simulation :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /WorkSSD/PythonProjects/gempy/gempy/assets/kriging.py:265: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("viridis")) cmap.set_bad(color='w', alpha=alpha) #define color and alpha for nan values .. GENERATED FROM PYTHON SOURCE LINES 133-137 .. code-block:: python3 solution.plot_results(geo_data=geo_data, prop='both', contour=False, direction='y', cell_number=0, alpha=0, interpolation='bilinear', show_data=False) plt.show() .. image:: /tutorials/ch3-Interpolations/images/sphx_glr_ch3_1_kriging_interpolation_and_simulation_004.png :alt: Estimated value, Variance :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /WorkSSD/PythonProjects/gempy/gempy/assets/kriging.py:265: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("viridis")) cmap.set_bad(color='w', alpha=alpha) #define color and alpha for nan values .. GENERATED FROM PYTHON SOURCE LINES 138-145 4) Simulated field ------------------ Based on the same objects (domain and varigoram model) also a simulated field (stationary Gaussian Field) can be generated. A Sequential Gaussian Simulation approach is applied in this module: .. GENERATED FROM PYTHON SOURCE LINES 147-149 .. code-block:: python3 solution_sim = kriging.create_gaussian_field(domain, variogram_model) .. GENERATED FROM PYTHON SOURCE LINES 150-152 .. code-block:: python3 solution_sim.results_df.head() .. raw:: html
X Y Z estimated value estimation variance
16 10.0 25.0 410.0 2.61 1.48
157 10.0 25.0 430.0 2.38 0.28
276 10.0 25.0 450.0 3.98 0.24
25 10.0 25.0 470.0 2.54 0.53
267 10.0 25.0 490.0 0.76 0.28


.. GENERATED FROM PYTHON SOURCE LINES 153-155 .. code-block:: python3 solution_sim.results_df['estimated value'] .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 16 2.61 157 2.38 276 3.98 25 2.54 267 0.76 ... 55 3.76 165 3.32 427 2.01 303 1.96 187 2.04 Name: estimated value, Length: 500, dtype: float64 .. GENERATED FROM PYTHON SOURCE LINES 156-157 sphinx_gallery_thumbnail_number = 3 .. GENERATED FROM PYTHON SOURCE LINES 157-161 .. code-block:: python3 solution_sim.plot_results(geo_data=geo_data, prop='val', contour=False, direction='y', cell_number=0, alpha=0.7, show_data=True, legend=True) plt.show() .. image:: /tutorials/ch3-Interpolations/images/sphx_glr_ch3_1_kriging_interpolation_and_simulation_005.png :alt: ch3 1 kriging interpolation and simulation :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /WorkSSD/PythonProjects/gempy/gempy/assets/kriging.py:265: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("viridis")) cmap.set_bad(color='w', alpha=alpha) #define color and alpha for nan values .. GENERATED FROM PYTHON SOURCE LINES 162-164 .. code-block:: python3 solution_sim.plot_results(geo_data=geo_data, prop='both', contour=False, direction='y', cell_number=0, alpha=0, interpolation='bilinear', show_data=False) plt.show() .. image:: /tutorials/ch3-Interpolations/images/sphx_glr_ch3_1_kriging_interpolation_and_simulation_006.png :alt: Estimated value, Variance :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /WorkSSD/PythonProjects/gempy/gempy/assets/kriging.py:265: MatplotlibDeprecationWarning: You are modifying the state of a globally registered colormap. In future versions, you will not be able to modify a registered colormap in-place. To remove this warning, you can make a copy of the colormap first. cmap = copy.copy(mpl.cm.get_cmap("viridis")) cmap.set_bad(color='w', alpha=alpha) #define color and alpha for nan values .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 7.495 seconds) .. _sphx_glr_download_tutorials_ch3-Interpolations_ch3_1_kriging_interpolation_and_simulation.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ch3_1_kriging_interpolation_and_simulation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ch3_1_kriging_interpolation_and_simulation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_