.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/02_simple_inversion/plot_10_generating_decouplings.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_10_generating_decouplings.py: Generating regularization decouplins ==================================== .. GENERATED FROM PYTHON SOURCE LINES 8-9 Imports .. GENERATED FROM PYTHON SOURCE LINES 9-15 .. code-block:: Python import crtomo import numpy as np import matplotlib.pylab as plt # this import is only required to plot directly into the output directory import reda .. GENERATED FROM PYTHON SOURCE LINES 16-19 .. code-block:: Python mesh = crtomo.crt_grid.create_surface_grid(20, spacing=1, debug=True) tdm = crtomo.tdMan(grid=mesh) .. 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 20-37 .. code-block:: Python path_info1 = tdm.grid.determine_path_along_nodes( [0, 0], [20, -2], ) decouplings1 = np.hstack( (path_info1[:, 2:4], np.ones(path_info1.shape[0])[:, np.newaxis]) ) path_info2 = tdm.grid.determine_path_along_nodes( [-6, -4], [20, -8], ) decouplings2 = np.hstack( (path_info2[:, 2:4], np.ones(path_info2.shape[0])[:, np.newaxis] * 0.5) ) tdm.add_to_decouplings(decouplings1) tdm.add_to_decouplings(decouplings2) .. GENERATED FROM PYTHON SOURCE LINES 38-39 Decouplings can now be accessed as a numpy array: .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python print(tdm.decouplings.shape) .. rst-class:: sphx-glr-script-out .. code-block:: none (210, 3) .. GENERATED FROM PYTHON SOURCE LINES 42-57 .. code-block:: Python fig, ax = plt.subplots() mesh.plot_grid_to_ax(ax) tdm.plot_decouplings_to_ax(ax, True) ax.plot([0, 20], [0, -2], color='yellow', label='input polygon 1') ax.plot([-6, 20], [-4, -8], color='yellow', label='input polygon 2') ax.set_title( 'Generating decouplings from polygons', loc='left', ) ax.legend( facecolor='white', framealpha=1, ) with reda.CreateEnterDirectory('out_10'): fig.savefig('decouplings_from_polygon.jpg', dpi=300, bbox_inches='tight') .. image-sg:: /_examples/02_simple_inversion/images/sphx_glr_plot_10_generating_decouplings_001.png :alt: Generating decouplings from polygons :srcset: /_examples/02_simple_inversion/images/sphx_glr_plot_10_generating_decouplings_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/crtomo_tools/crtomo_tools/examples/02_simple_inversion/plot_10_generating_decouplings.py:56: UserWarning: Creating legend with loc="best" can be slow with large amounts of data. fig.savefig('decouplings_from_polygon.jpg', dpi=300, bbox_inches='tight') /home/runner/work/crtomo_tools/crtomo_tools/examples/02_simple_inversion/plot_10_generating_decouplings.py:56: UserWarning: Creating legend with loc="best" can be slow with large amounts of data. fig.savefig('decouplings_from_polygon.jpg', dpi=300, bbox_inches='tight') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 18.075 seconds) .. _sphx_glr_download__examples_02_simple_inversion_plot_10_generating_decouplings.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_10_generating_decouplings.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_10_generating_decouplings.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_10_generating_decouplings.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_