.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/01_modelling/plot_01_modifying_models.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_01_modelling_plot_01_modifying_models.py: Modify a subsurface model ^^^^^^^^^^^^^^^^^^^^^^^^^ A subsurface model is basically an array of the same length as the number of model cells in the finite-element mesh. We refer to such an array as a parameter set (or **parset**), and the numeric (integer) id that refers to such as parset in the parameter manager as a *pid*. For DC forward modeling you only need one resistivity model (with M resistivity values for the M model cells), while for complex resistivity modeling you need a resistivity and a phase array. Parameter sets are usually manager using the parameter manger class :py:class:`crtomo.parManager.ParMan`, which also has an alias to `crtomo.ParMan`. If you are using a single-frequency tomodir object `tdm` (:py:class:`crtomo.tdMan`), one parameter manager is already initialized as `tdm.parman`. There are various ways to modify such an array * modify by index: :py:meth:`crtomo.parManager.ParMan.modify_pixels` * modify rectangular area: :py:meth:`crtomo.parManager.ParMan.modify_area` * modify by polygon :py:meth:`crtomo.parManager.ParMan.modify_polygon` * add Gaussian anomalies. See this example here: :ref:`sphx_glr__examples_01_modelling_plot_02_anomalies.py` * there is also the possibility to generate meshes that incorporate certain subsurface structures. See this example: :ref:`sphx_glr__examples_00_grids_plot_triag_with_internal_structure_inkscape.py` .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: Python import crtomo import matplotlib.pylab as plt .. GENERATED FROM PYTHON SOURCE LINES 39-40 load a mesh file that we want to create a model for .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python grid = crtomo.crt_grid('grid_surface/elem.dat', 'grid_surface/elec.dat') # create a parameter manager parman = crtomo.ParMan(grid) .. rst-class:: sphx-glr-script-out .. code-block:: none This grid was sorted using CutMcK. The nodes were resorted! Triangular grid found .. GENERATED FROM PYTHON SOURCE LINES 45-47 we need a plot manager to plot our mesh/model parameters notice that we link the parameter manager to the plot manager .. GENERATED FROM PYTHON SOURCE LINES 47-48 .. code-block:: Python plotman = crtomo.pltMan(grid=grid, pm=parman) .. GENERATED FROM PYTHON SOURCE LINES 49-50 create an empty parameter set .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python pid_mag = parman.add_empty_dataset(value=100) .. GENERATED FROM PYTHON SOURCE LINES 53-68 Modify by polygon ----------------- Probably the most versatile method to modify a subsurface model is by selecting cells using a polygon outline. The relevant function for this is :py:meth:`crtomo.parManager.ParMan.modify_polygon` Note that only cells are selected whose center ob mass is located within the polygon! It is advisable to create meshes that include the relevant polygon lines in the mesh. Note that those meshes should only be used for forward modeling, not for inverse modeling. For advanced grid creating, please refer to :ref:`grid_creation:irregular grids`, especially the inclusion of extra lines: :ref:`grid_creation:extra_lines.dat (optional)`. .. GENERATED FROM PYTHON SOURCE LINES 68-77 .. code-block:: Python from shapely.geometry import Polygon # noqa:402 poly = Polygon([ [0, 0], [2, 0], [2, -1], [0, -1.5], ]) parman.modify_polygon(pid_mag, poly, 66) .. GENERATED FROM PYTHON SOURCE LINES 78-100 .. code-block:: Python fig, ax = plt.subplots(figsize=(15 / 2.54, 7 / 2.54)) plotman.plot_elements_to_ax( pid_mag, ax=ax, plot_colorbar=True, cblabel=r'$\rho~[\Omega m]$', title='Resistivity model' ) # lets draw the original polygon from shapely.plotting import plot_polygon # noqa: 402 plot_polygon(poly, ax=ax, color='k') # lets plot the center of masses ax.scatter( grid.get_element_centroids()[:, 0], grid.get_element_centroids()[:, 1], color='r', label='centroids', ) ax.legend() fig.tight_layout() fig.savefig('out_03_model.jpg', dpi=300) .. image-sg:: /_examples/01_modelling/images/sphx_glr_plot_01_modifying_models_001.png :alt: Resistivity model :srcset: /_examples/01_modelling/images/sphx_glr_plot_01_modifying_models_001.png :class: sphx-glr-single-img .. _sphx_glr_download__examples_01_modelling_plot_01_modifying_models.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_modifying_models.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_modifying_models.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_modifying_models.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_