.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/c_advanced/a01_cell_selection.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_tutorials_c_advanced_a01_cell_selection.py: Centered Grids for Geophysics ================================ Precomputing the gravity kernel of a measurement-centered grid This tutorial explains the concept of a centered grid and uses it to precompute the tz kernel needed for GemPy's forward gravity computation. .. GENERATED FROM PYTHON SOURCE LINES 12-18 Concept of a measurement-centered grid """""""""""""""""""""""""""""""""""""" Geophysics preprocessing builds on the centered grid (see the Grids tutorial in the Advanced section) to precompute the constant part of forward physical computations, such as gravity: .. GENERATED FROM PYTHON SOURCE LINES 18-39 .. code-block:: Python # .. 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 and keeping the grid constant, we can compute the forward # gravity with a single operation: # .. math:: # F_z = G_{\rho} \cdot t_z .. GENERATED FROM PYTHON SOURCE LINES 40-52 .. code-block:: Python # Importing gempy import gempy as gp # Aux imports import numpy as np import pandas as pd import matplotlib.pyplot as plt np.random.seed(1515) pd.set_option('display.precision', 2) .. GENERATED FROM PYTHON SOURCE LINES 53-59 .. code-block:: Python from gempy_engine.core.data.centered_grid import CenteredGrid centered_grid = CenteredGrid( centers=np.array([0,0,0]), resolution=[10, 10, 20], radius=100 ) .. GENERATED FROM PYTHON SOURCE LINES 60-63 Instantiating ``CenteredGrid`` creates a constant kernel around the point (0, 0, 0). This kernel will be what we use for each device. .. GENERATED FROM PYTHON SOURCE LINES 65-67 .. code-block:: Python centered_grid.kernel_grid_centers .. rst-class:: sphx-glr-script-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. ]], shape=(2541, 3)) .. GENERATED FROM PYTHON SOURCE LINES 68-71 :math:`t_z` is only dependent on distance and therefore we can use the kernel created in the previous cell .. GENERATED FROM PYTHON SOURCE LINES 73-76 .. code-block:: Python gravity_gradient = gp.calculate_gravity_gradient(centered_grid) gravity_gradient .. rst-class:: sphx-glr-script-out .. code-block:: none array([-8.71768928e-05, -6.45647022e-05, -3.41579985e-05, ..., -1.09610058e-02, -1.41543038e-02, -1.51096613e-02], shape=(2541,)) .. GENERATED FROM PYTHON SOURCE LINES 77-81 To compute tz we also need the edges of each voxel. The distances to the edges are stored in ``left_voxel_edges`` and ``right_voxel_edges``. We can plot all the data as follows: .. GENERATED FROM PYTHON SOURCE LINES 83-86 .. code-block:: Python a, b, c = centered_grid.kernel_grid_centers, centered_grid.left_voxel_edges, centered_grid.right_voxel_edges tz = gravity_gradient .. GENERATED FROM PYTHON SOURCE LINES 87-116 .. code-block:: Python 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-sg:: /tutorials/c_advanced/images/sphx_glr_a01_cell_selection_001.png :alt: a01 cell selection :srcset: /tutorials/c_advanced/images/sphx_glr_a01_cell_selection_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 117-119 Just the quiver: .. GENERATED FROM PYTHON SOURCE LINES 121-129 .. code-block:: Python 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-sg:: /tutorials/c_advanced/images/sphx_glr_a01_cell_selection_002.png :alt: a01 cell selection :srcset: /tutorials/c_advanced/images/sphx_glr_a01_cell_selection_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 130-132 Remember this is happening always in 3D: .. GENERATED FROM PYTHON SOURCE LINES 134-142 .. code-block:: Python 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-sg:: /tutorials/c_advanced/images/sphx_glr_a01_cell_selection_003.png :alt: a01 cell selection :srcset: /tutorials/c_advanced/images/sphx_glr_a01_cell_selection_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.444 seconds) .. _sphx_glr_download_tutorials_c_advanced_a01_cell_selection.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: a01_cell_selection.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: a01_cell_selection.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: a01_cell_selection.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_