.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/data_visualization/signal_normalisation.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_data_visualization_signal_normalisation.py: Signal normalisation ==================== .. GENERATED FROM PYTHON SOURCE LINES 8-11 .. code-block:: Python import hyperspy.api as hs import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 12-16 Default normalisation --------------------- Create two unique Signal1D for example .. GENERATED FROM PYTHON SOURCE LINES 17-26 .. code-block:: Python s = hs.data.luminescence_signal() s_shifted = np.roll(s.data, 200) s_shifted = hs.signals.Signal1D(s_shifted) s1 = (s/0.8 + hs.signals.Signal1D(s_shifted/4)) + 500 s2 = s + hs.signals.Signal1D(s_shifted/2) .. GENERATED FROM PYTHON SOURCE LINES 27-28 Plot un-normalised signals .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python hs.plot.plot_spectra([s1,s2]) .. image-sg:: /auto_examples/data_visualization/images/sphx_glr_signal_normalisation_001.png :alt: signal normalisation :srcset: /auto_examples/data_visualization/images/sphx_glr_signal_normalisation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 32-33 Plot both signals with default normalisation, of min and max intensity values to 0 and 1 .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python hs.plot.plot_spectra([s1, s2], normalise = True) .. image-sg:: /auto_examples/data_visualization/images/sphx_glr_signal_normalisation_002.png :alt: signal normalisation :srcset: /auto_examples/data_visualization/images/sphx_glr_signal_normalisation_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 37-41 Normalising to signal range --------------------------- In the case that we want to normalise our signals to the background noise, we can create a custom normalisation function. The mean intensity over the index range 5 - 100 is specified to normalise the signals to .. GENERATED FROM PYTHON SOURCE LINES 42-52 .. code-block:: Python def normalise_mean_range(signal): data = signal.data normalise_range = signal.isig[5:100].data scale_factor = 1 / normalise_range.mean() return data * scale_factor .. GENERATED FROM PYTHON SOURCE LINES 53-54 Plot signals with custom normalisation function passed as parameter .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python hs.plot.plot_spectra([s1,s2], normalise = normalise_mean_range) .. image-sg:: /auto_examples/data_visualization/images/sphx_glr_signal_normalisation_003.png :alt: signal normalisation :srcset: /auto_examples/data_visualization/images/sphx_glr_signal_normalisation_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 57-61 Normalising to specified signal value ------------------------------------- In the case that we want to normalise our signals to the second weaker peak in our spectra, we adjust our function to normalise the signals to the intensity at energy position 4.5 eV .. GENERATED FROM PYTHON SOURCE LINES 62-72 .. code-block:: Python def normalise_energy_value(signal): data = signal.data normalise_value = signal.isig[4.5].data scale = 1 / normalise_value return data * scale .. GENERATED FROM PYTHON SOURCE LINES 73-74 Plot signals with custom normalisation function passed as parameter .. GENERATED FROM PYTHON SOURCE LINES 74-75 .. code-block:: Python hs.plot.plot_spectra([s1,s2], normalise = normalise_energy_value) .. image-sg:: /auto_examples/data_visualization/images/sphx_glr_signal_normalisation_004.png :alt: signal normalisation :srcset: /auto_examples/data_visualization/images/sphx_glr_signal_normalisation_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.862 seconds) .. _sphx_glr_download_auto_examples_data_visualization_signal_normalisation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: signal_normalisation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: signal_normalisation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: signal_normalisation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_