.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/ch2-Geophysics/ch2_2_cell_selection.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_ch2-Geophysics_ch2_2_cell_selection.py: 2.2: Centered Grid. ^^^^^^^^^^^^^^^^^^^ Geophysics Preprocessing builds on the centered grid (https://github.com/cgre-aachen/gempy/blob/master/notebooks/tutorials/ch1-3-Grids.ipynb) to precompute the constant part of forward physical computations as for example gravity: .. math:: F_z = G_{\rho} ||| x \ln(y+r) + y \ln (x+r) - z \arctan (\frac{x y}{z r}) |^{x_2}_{x_1}|^{y_2}_{y_1}|^{ z_2}_{z_1} where we can compress the grid dependent terms as .. math:: t_z = ||| x \ln (y+r) + y \ln (x+r)-z \arctan ( \frac{x y}{z r} ) |^{x_2}_{x_1}|^{y_2}_{y_1}|^{z_2}_{z_1} By doing this decomposition an keeping the grid constant we can compute the forward gravity by simply operate: .. math:: F_z = G_{\rho} \cdot t_z .. GENERATED FROM PYTHON SOURCE LINES 33-45 .. code-block:: python3 # Importing gempy from gempy.assets.geophysics import GravityPreprocessing # Aux imports import numpy as np import pandas as pd import matplotlib.pyplot as plt np.random.seed(1515) pd.set_option('precision', 2) .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: python3 g = GravityPreprocessing() .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: python3 kernel_centers, kernel_dxyz_left, kernel_dxyz_right = g.create_irregular_grid_kernel(resolution=[10, 10, 20], radius=100) .. GENERATED FROM PYTHON SOURCE LINES 53-56 ``create_irregular_grid_kernel`` will create a constant kernel around the point 0,0,0. This kernel will be what we use for each device. .. GENERATED FROM PYTHON SOURCE LINES 58-60 .. code-block:: python3 kernel_centers .. rst-class:: sphx-glr-script-out Out: .. code-block:: none array([[-100. , -100. , -6. ], [-100. , -100. , -7.2 ], [-100. , -100. , -7.52912998], ..., [ 100. , 100. , -79.90178533], [ 100. , 100. , -100.17119644], [ 100. , 100. , -126. ]]) .. GENERATED FROM PYTHON SOURCE LINES 61-64 :math:`t_z` is only dependent on distance and therefore we can use the kerenel created on the previous cell .. GENERATED FROM PYTHON SOURCE LINES 66-69 .. code-block:: python3 tz = g.set_tz_kernel(resolution=[10, 10, 20], radius=100) tz .. rst-class:: sphx-glr-script-out Out: .. code-block:: none array([-8.71768928e-05, -6.45647022e-05, -3.41579985e-05, ..., -1.09610058e-02, -1.41543038e-02, -1.51096613e-02]) .. GENERATED FROM PYTHON SOURCE LINES 70-74 To compute tz we also need the edges of each voxel. The distance to the edges are stored on ``kernel_dxyz_left`` and ``kernel_dxyz_right``. We can plot all the data as follows: .. GENERATED FROM PYTHON SOURCE LINES 76-78 .. code-block:: python3 a, b, c = kernel_centers, kernel_dxyz_left, kernel_dxyz_right .. GENERATED FROM PYTHON SOURCE LINES 79-108 .. code-block:: python3 fig = plt.figure(figsize=(13, 7)) plt.quiver(a[:, 0].reshape(11, 11, 21)[5, :, :].ravel(), a[:, 2].reshape(11, 11, 21)[:, 5, :].ravel(), np.zeros(231), tz.reshape(11, 11, 21)[5, :, :].ravel(), label='$t_z$', alpha=.3 ) plt.plot(a[:, 0].reshape(11, 11, 21)[5, :, :].ravel(), a[:, 2].reshape(11, 11, 21)[:, 5, :].ravel(), 'o', alpha=.3, label='Centers') plt.plot(a[:, 0].reshape(11, 11, 21)[5, :, :].ravel() - b[:, 0].reshape(11, 11, 21)[5, :, :].ravel(), a[:, 2].reshape(11, 11, 21)[:, 5, :].ravel(), '.', alpha=.3, label='Lefts') plt.plot(a[:, 0].reshape(11, 11, 21)[5, :, :].ravel(), a[:, 2].reshape(11, 11, 21)[:, 5, :].ravel() - b[:, 2].reshape(11, 11, 21)[:, 5, :].ravel(), '.', alpha=.6, label='Ups') plt.plot(a[:, 0].reshape(11, 11, 21)[5, :, :].ravel() + c[:, 0].reshape(11, 11, 21)[5, :, :].ravel(), a[:, 2].reshape(11, 11, 21)[:, 5, :].ravel(), '.', alpha=.3, label='Rights') plt.plot(a[:, 0].reshape(11, 11, 21)[5, :, :].ravel(), a[:, 2].reshape(11, 11, 21)[:, 5, :].ravel() + c[:, 2].reshape(11, 11, 21)[5, :, :].ravel(), '.', alpha=.3, label='Downs') plt.xlim(-200, 200) plt.ylim(-200, 0) plt.legend() plt.show() .. image:: /tutorials/ch2-Geophysics/images/sphx_glr_ch2_2_cell_selection_001.png :alt: ch2 2 cell selection :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 109-111 Just the quiver: .. GENERATED FROM PYTHON SOURCE LINES 113-121 .. code-block:: python3 fig = plt.figure(figsize=(13, 7)) plt.quiver(a[:, 0].reshape(11, 11, 21)[5, :, :].ravel(), a[:, 2].reshape(11, 11, 21)[:, 5, :].ravel(), np.zeros(231), tz.reshape(11, 11, 21)[5, :, :].ravel() ) plt.show() .. image:: /tutorials/ch2-Geophysics/images/sphx_glr_ch2_2_cell_selection_002.png :alt: ch2 2 cell selection :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 122-124 Remember this is happening always in 3D: .. GENERATED FROM PYTHON SOURCE LINES 126-134 .. code-block:: python3 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(a[:, 0], a[:, 1], a[:, 2], c=tz) ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label') plt.show() .. image:: /tutorials/ch2-Geophysics/images/sphx_glr_ch2_2_cell_selection_003.png :alt: ch2 2 cell selection :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.369 seconds) .. _sphx_glr_download_tutorials_ch2-Geophysics_ch2_2_cell_selection.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: ch2_2_cell_selection.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ch2_2_cell_selection.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_