.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/pattern_processing/pattern_binning.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_pattern_processing_pattern_binning.py: Pattern binning =============== This example shows how to bin :class:`~kikuchipy.signals.EBSD` patterns using :meth:`~kikuchipy.signals.EBSD.downsample` or HyperSpy's :meth:`~kikuchipy.signals.EBSD.rebin` (see :ref:`hyperspy:rebin-label` for details). .. note:: In general, better contrast is obtained by removing the static (and dynamic) background prior to binning instead of after it. .. GENERATED FROM PYTHON SOURCE LINES 14-26 .. code-block:: default import hyperspy.api as hs import kikuchipy as kp s = kp.data.si_ebsd_moving_screen(allow_download=True, show_progressbar=False) s.remove_static_background(show_progressbar=False) print(s) print(s.static_background.shape) print(s.detector) .. rst-class:: sphx-glr-script-out .. code-block:: none (480, 480) EBSDDetector (480, 480), px_size 1.0 um, binning 1, tilt 0.0, azimuthal 0.0, pc (0.5, 0.5, 0.5) .. GENERATED FROM PYTHON SOURCE LINES 27-30 Downsample by a factor of 8 while maintaining the data type (achieved by rescaling the pattern intensity). Note how the :attr:`~kikuchipy.signals.EBSD.static_background` and :attr:`~kikuchipy.signals.EBSD.detector` attributes are updated. .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: default s2 = s.downsample(8, inplace=False) _ = hs.plot.plot_images([s, s2], axes_decor="off", tight_layout=True, label=None) print(s2.static_background.shape) print(s2.detector) .. image-sg:: /examples/pattern_processing/images/sphx_glr_pattern_binning_001.png :alt: pattern binning :srcset: /examples/pattern_processing/images/sphx_glr_pattern_binning_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [ ] | 0% Completed | 265.08 us [########################################] | 100% Completed | 100.68 ms (60, 60) EBSDDetector (60, 60), px_size 1.0 um, binning 8, tilt 0.0, azimuthal 0.0, pc (0.5, 0.5, 0.5) .. GENERATED FROM PYTHON SOURCE LINES 37-40 Rebin by passing the new shape (use ``(1, 1, 60, 60)`` if binning a 2D map). Note how the pattern is not rescaled and the data type is cast to either ``int64`` or ``float64`` depending on the initial data type. .. GENERATED FROM PYTHON SOURCE LINES 40-45 .. code-block:: default s3 = s.rebin(new_shape=(60, 60)) print(s3.data.dtype) print(s3.data.min(), s3.data.max()) .. rst-class:: sphx-glr-script-out .. code-block:: none uint64 3152 11998 .. GENERATED FROM PYTHON SOURCE LINES 46-49 The latter method is more flexible in that it allows for different binning factors in each axis, the factors are not restricted to being integers and the factors do not have to be divisors of the initial signal shape. .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: default s4 = s.rebin(scale=(8, 9)) print(s4.data.shape) .. rst-class:: sphx-glr-script-out .. code-block:: none (53, 60) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.802 seconds) **Estimated memory usage:** 35 MB .. _sphx_glr_download_examples_pattern_processing_pattern_binning.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pattern_binning.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pattern_binning.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_