.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/region_of_interest/fast_fourier_transform_live.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_auto_examples_region_of_interest_fast_fourier_transform_live.py: Live FFT ======== Get interactive fast Fourier transform (FFT) from a subset of a Signal2D using RectangularROI. .. GENERATED FROM PYTHON SOURCE LINES 9-13 .. code-block:: Python import hyperspy.api as hs import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 14-15 Create a signal: .. GENERATED FROM PYTHON SOURCE LINES 15-17 .. code-block:: Python s = hs.data.atomic_resolution_image() .. GENERATED FROM PYTHON SOURCE LINES 18-19 Add noise to the signal to make it more realistic .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: Python s.data *= 1E3 s.data += np.random.default_rng().poisson(s.data) .. GENERATED FROM PYTHON SOURCE LINES 23-24 Create the ROI, here a :py:class:`~.api.roi.RectangularROI`: .. GENERATED FROM PYTHON SOURCE LINES 24-26 .. code-block:: Python roi = hs.roi.RectangularROI() .. GENERATED FROM PYTHON SOURCE LINES 27-30 Slice signal with the ROI. By using the `interactive` function, the output signal ``sliced_signal`` will update automatically. The ROI will be added automatically on the signal plot. .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: Python s.plot() sliced_signal = roi.interactive(s, recompute_out_event=None) # Choose the second figure as gallery thumbnail: # sphinx_gallery_thumbnail_number = 2 .. image-sg:: /auto_examples/region_of_interest/images/sphx_glr_fast_fourier_transform_live_001.png :alt: Signal :srcset: /auto_examples/region_of_interest/images/sphx_glr_fast_fourier_transform_live_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-41 Get the FFT of this sliced signal, and plot it Apodization is used to smoothen the edge of the image before taking the FFT to remove streaks from the FFT - see the :ref:`signal.fft` section of the user guide for more details: .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python s_fft = hs.interactive(sliced_signal.fft, apodization=True, shift=True, recompute_out_event=None) s_fft.plot(power_spectrum=True) .. image-sg:: /auto_examples/region_of_interest/images/sphx_glr_fast_fourier_transform_live_002.png :alt: FFT of Signal :srcset: /auto_examples/region_of_interest/images/sphx_glr_fast_fourier_transform_live_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.571 seconds) .. _sphx_glr_download_auto_examples_region_of_interest_fast_fourier_transform_live.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fast_fourier_transform_live.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fast_fourier_transform_live.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: fast_fourier_transform_live.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_