.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/02_simple_inversion/plot_12_decouplings_1.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_02_simple_inversion_plot_12_decouplings_1.py: Gegularization decouplings 1 ============================ .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: Python import crtomo import numpy as np from shapely.geometry import Polygon .. GENERATED FROM PYTHON SOURCE LINES 13-16 Define the electrode positions and boundaries See :ref:`sphx_glr__examples_00_grids_plot_mesh_generation.py` for more information. .. GENERATED FROM PYTHON SOURCE LINES 16-39 .. code-block:: Python electrodes = np.array(( (0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), )) boundaries = np.array(( (-1, 0, 12), (0, 0, 12), (1, 0, 12), (2, 0, 12), (3, 0, 12), (4, 0, 12), (5, 0, 12), (6, 0, 12), (7, 0, 12), (7, -2, 11), (-1, -2, 11), )) .. GENERATED FROM PYTHON SOURCE LINES 40-41 Additionally, we define one extra line (x0, y0, x1, y1): .. GENERATED FROM PYTHON SOURCE LINES 41-55 .. code-block:: Python extra_lines = [ [-0, -0.20, 3, -0.45], ] # Throws error: TODO # poly1 = Polygon(( # (0, 0.0), # (5, -0.75), # (5, -3), # (0, -3), # #(-2, 0), # )) .. GENERATED FROM PYTHON SOURCE LINES 56-73 .. code-block:: Python poly1 = Polygon(( (0, -0.20), (3, -0.45), (3, -2), (-1, -2), )) """ mesh_d = crtomo.mesh_gen.gen_mesh( boundaries, electrodes, # vertical line shoudl not start on horizontal line # additional_lines=extra_lines, # polygons=[poly1], char_lengths=[0.25, 0.5, 0.5, 0.5], ) """ .. GENERATED FROM PYTHON SOURCE LINES 74-75 Generate the mesh .. GENERATED FROM PYTHON SOURCE LINES 75-88 .. code-block:: Python mesh_d, _ = crtomo.mesh_gen.gen_mesh_with_polygons( boundaries, electrodes, # vertical line should not start on horizontal line # additional_lines=extra_lines, polygons=[poly1], char_lengths=[0.15, 0.25, 0.25, 0.25], ) print(mesh_d) mesh_d.plot_grid() .. image-sg:: /_examples/02_simple_inversion/images/sphx_glr_plot_12_decouplings_1_001.png :alt: plot 12 decouplings 1 :srcset: /_examples/02_simple_inversion/images/sphx_glr_plot_12_decouplings_1_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Calling the mesh generation routines... done This grid was sorted using CutMcK. The nodes were resorted! Triangular grid found CRMod/CTRomo grid instance number of elements: 898 number of nodes: 501 number of electrodes: 7 mesh dimensions: X: -1.0 7.0 Z: -2.0 0.0 .. GENERATED FROM PYTHON SOURCE LINES 90-94 .. code-block:: Python decouplings = crtomo.mesh_decouplings.get_decouplings( mesh_d, extra_lines ) .. GENERATED FROM PYTHON SOURCE LINES 95-106 .. code-block:: Python tdm = crtomo.tdMan(grid=mesh_d) ab = tdm.configs.gen_all_current_dipoles() tdm.configs.gen_all_voltages_for_injections(ab) pid_mag, _ = tdm.add_homogeneous_model(300) tdm.parman.modify_polygon( pid_mag, poly1, 30, ) tdm.plot_forward_models() .. image-sg:: /_examples/02_simple_inversion/images/sphx_glr_plot_12_decouplings_1_002.png :alt: plot 12 decouplings 1 :srcset: /_examples/02_simple_inversion/images/sphx_glr_plot_12_decouplings_1_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 107-126 .. code-block:: Python rmag = tdm.measurements(silent=True)[:, 0] np.random.seed(2048) # absolute component in [Ohm ] noise_level_rmag_absolute = 0.01 # relative component [0, 1] noise_level_rmag_relative = 0.05 noise_rmag = np.random.normal( loc=0, scale=rmag * noise_level_rmag_relative + noise_level_rmag_absolute ) rmag_with_noise = rmag + noise_rmag tdm.register_measurements(rmag_with_noise) tdm.remove_negative_resistance_measurements() .. rst-class:: sphx-glr-script-out .. code-block:: none Deleting configurations: [] .. GENERATED FROM PYTHON SOURCE LINES 127-131 .. code-block:: Python tdm.crtomo_cfg['robust_inv'] = 'F' tdm.add_to_decouplings(decouplings) tdm.invert(cores=4, catch_output=True) .. rst-class:: sphx-glr-script-out .. code-block:: none Attempting inversion in directory: /tmp/tmpe3t1kaza Using binary: /usr/bin/CRTomo_dev Calling CRTomo Inversion attempt finished Attempting to import the results Reading inversion results is robust False Info: res_m.diag not found: /tmp/tmpe3t1kaza/inv/res_m.diag /home/runner/work/crtomo_tools/crtomo_tools/examples/02_simple_inversion Info: ata.diag not found: /tmp/tmpe3t1kaza/inv/ata.diag /home/runner/work/crtomo_tools/crtomo_tools/examples/02_simple_inversion Statistics of last iteration: iteration 4 main_iteration 4 it_type DC/IP type main dataRMS 2.17 magRMS 2.17 phaRMS NaN lambda 91.99 roughness 5.433 cgsteps 8.0 nrdata 209.0 steplength 0.001 stepsize 0.000582 l1ratio NaN Name: 19, dtype: object .. GENERATED FROM PYTHON SOURCE LINES 132-133 .. code-block:: Python _ = tdm.plot_inversion_result_rmag() .. image-sg:: /_examples/02_simple_inversion/images/sphx_glr_plot_12_decouplings_1_003.png :alt: plot 12 decouplings 1 :srcset: /_examples/02_simple_inversion/images/sphx_glr_plot_12_decouplings_1_003.png :class: sphx-glr-single-img .. _sphx_glr_download__examples_02_simple_inversion_plot_12_decouplings_1.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_12_decouplings_1.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_12_decouplings_1.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_12_decouplings_1.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_