.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/data_processing/rebinning.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_processing_rebinning.py: Rebinning ========= This example shows how to rebin a dataset. .. GENERATED FROM PYTHON SOURCE LINES 9-10 Load the data .. GENERATED FROM PYTHON SOURCE LINES 10-19 .. code-block:: Python import lumispy as lum cl1 = lum.data.asymmetric_peak_map() cl1 = cl1.remove_background(signal_range=(550.0, 620.0), background_type="Offset") cl1 = cl1.isig[:-3] cl1.spikes_removal_tool(interactive=False) cl3 = cl1.deepcopy() .. GENERATED FROM PYTHON SOURCE LINES 20-21 Display the original data .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python cl1.inav[0, 0].plot() .. image-sg:: /auto_examples/data_processing/images/sphx_glr_rebinning_001.png :alt: 880_30K_map2a Signal :srcset: /auto_examples/data_processing/images/sphx_glr_rebinning_001.png, /auto_examples/data_processing/images/sphx_glr_rebinning_001_5_00x.png 5.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 25-29 The current dataset is quite noisy. As the peak is broad in comparison with the spectral resolution. One way to improve that is by rebinning the data along the signal axis using :py:meth:`hyperspy.api.signals.BaseSignal.rebin`. The parameter 'scale' specifies the rebinning factor for each axis. Here we rebin by a factor of 2 along the signal axis and keep the resolution along the navigation axes unchanged. .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python cl2 = cl1.rebin(scale=[1, 1, 2]) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Display the rebinned data .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: Python cl2.inav[0, 0].plot() .. image-sg:: /auto_examples/data_processing/images/sphx_glr_rebinning_002.png :alt: 880_30K_map2a Signal :srcset: /auto_examples/data_processing/images/sphx_glr_rebinning_002.png, /auto_examples/data_processing/images/sphx_glr_rebinning_002_5_00x.png 5.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 38-41 We can alternatively rebin using the parameter `new_shape`. For each dimension, the new number of pixels has to be specified. From the old shape of (30, 16|334), we rebin to a new shape of (20, 10|150). .. GENERATED FROM PYTHON SOURCE LINES 41-48 .. code-block:: Python cl3.plot() # original data cl4 = cl3.rebin(new_shape=[20, 10, 150]) cl4.plot() # rebinned data .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/data_processing/images/sphx_glr_rebinning_003.png :alt: 880_30K_map2a Navigator :srcset: /auto_examples/data_processing/images/sphx_glr_rebinning_003.png, /auto_examples/data_processing/images/sphx_glr_rebinning_003_5_00x.png 5.00x :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/data_processing/images/sphx_glr_rebinning_004.png :alt: 880_30K_map2a Signal :srcset: /auto_examples/data_processing/images/sphx_glr_rebinning_004.png, /auto_examples/data_processing/images/sphx_glr_rebinning_004_5_00x.png 5.00x :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/data_processing/images/sphx_glr_rebinning_005.png :alt: 880_30K_map2a Navigator :srcset: /auto_examples/data_processing/images/sphx_glr_rebinning_005.png, /auto_examples/data_processing/images/sphx_glr_rebinning_005_5_00x.png 5.00x :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/data_processing/images/sphx_glr_rebinning_006.png :alt: 880_30K_map2a Signal :srcset: /auto_examples/data_processing/images/sphx_glr_rebinning_006.png, /auto_examples/data_processing/images/sphx_glr_rebinning_006_5_00x.png 5.00x :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 10.622 seconds) .. _sphx_glr_download_auto_examples_data_processing_rebinning.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: rebinning.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: rebinning.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: rebinning.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_