Interactive integration of one dimensional signal#

This example shows how to integrate a signal using an interactive ROI.

import hyperspy.api as hs

Create a signal:

/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/rsciio/utils/rgb_tools.py:62: VisibleDeprecationWarning: The module `rsciio.utils.rgb_tools` has been renamed to `rsciio.utils.rgb` and it will be removed in version 1.0. Use `RGB_DTYPES` instead
  warnings.warn(
/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/rsciio/utils/rgb_tools.py:62: VisibleDeprecationWarning: The module `rsciio.utils.rgb_tools` has been renamed to `rsciio.utils.rgb` and it will be removed in version 1.0.
  warnings.warn(

Create SpanROI:

roi = hs.roi.SpanROI(left=10, right=20)

Slice signal with roi with the ROI. By using the interactive() function, the output signal s_roi will update automatically. The ROI will be added automatically on the signal figure:

s.plot()
sliced_signal = roi.interactive(s, axes=s.axes_manager.signal_axes)
# Choose the second figure as gallery thumbnail:
# sphinx_gallery_thumbnail_number = 2
  • Two Gaussians Navigator
  • Two Gaussians Signal
/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/rsciio/utils/rgb_tools.py:62: VisibleDeprecationWarning: The module `rsciio.utils.rgb_tools` has been renamed to `rsciio.utils.rgb` and it will be removed in version 1.0.
  warnings.warn(

Create a placeholder signal for the integrated signal and set metadata:

integrated_sliced_signal = sliced_signal.sum(axis=-1).T
integrated_sliced_signal.metadata.General.title = "Integrated intensity"

Create the interactive computation, which will update when the ROI roi is changed. wWe use the out argument to place the results of the integration in the placeholder signal defined in the previous step:

hs.interactive(
    sliced_signal.sum,
    axis=sliced_signal.axes_manager.signal_axes,
    event=roi.events.changed,
    recompute_out_event=None,
    out=integrated_sliced_signal,
)
<Signal2D, title: Integrated intensity, dimensions: (|32, 32)>

Plot the integrated sum signal:

integrated_sliced_signal.plot()
Integrated intensity Signal
/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/rsciio/utils/rgb_tools.py:62: VisibleDeprecationWarning: The module `rsciio.utils.rgb_tools` has been renamed to `rsciio.utils.rgb` and it will be removed in version 1.0.
  warnings.warn(

Total running time of the script: (0 minutes 1.397 seconds)

Gallery generated by Sphinx-Gallery