.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/selecting_data/crop_navigation_axes.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_selecting_data_crop_navigation_axes.py: Crop navigation axes ==================== This example shows various ways to crop the navigation axes of an :class:`~kikuchipy.signals.EBSD` signal using HyperSpy's ``inav`` slicer and :meth:`~kikuchipy.signals.EBSD.crop` method (see :ref:`hyperspy:signal.indexing` for details). .. GENERATED FROM PYTHON SOURCE LINES 10-26 .. code-block:: default import hyperspy.api as hs import kikuchipy as kp # Import data s = kp.data.nickel_ebsd_small() s.remove_static_background(show_progressbar=False) # Inspect data and attributes plot_kwds = dict(axes_decor=None, label=None, colorbar=None, tight_layout=True) _ = hs.plot.plot_images(s, **plot_kwds) print(s) print(s.xmap.shape) print(s.detector.navigation_shape) .. image-sg:: /examples/selecting_data/images/sphx_glr_crop_navigation_axes_001.png :alt: crop navigation axes :srcset: /examples/selecting_data/images/sphx_glr_crop_navigation_axes_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (3, 3) (3, 3) .. GENERATED FROM PYTHON SOURCE LINES 27-30 Get a new signal with the patterns in the first row using ``inav``. Note how the :attr:`~kikuchipy.signals.EBSD.xmap` and :attr:`~kikuchipy.signals.EBSD.detector` attributes are updated. .. GENERATED FROM PYTHON SOURCE LINES 30-38 .. code-block:: default s2 = s.inav[:, 0] _ = hs.plot.plot_images(s2, **plot_kwds) print(s2) print(s2.xmap.shape) print(s2.detector.navigation_shape) .. image-sg:: /examples/selecting_data/images/sphx_glr_crop_navigation_axes_002.png :alt: crop navigation axes :srcset: /examples/selecting_data/images/sphx_glr_crop_navigation_axes_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (3,) (3,) .. GENERATED FROM PYTHON SOURCE LINES 39-40 Get the first column using ``crop()``, which overwrites the signal inplace .. GENERATED FROM PYTHON SOURCE LINES 40-49 .. code-block:: default s3 = s.deepcopy() s3.crop(1, start=0, end=1) _ = hs.plot.plot_images(s3, **plot_kwds) print(s3) print(s3.xmap.shape) print(s3.detector.navigation_shape) .. image-sg:: /examples/selecting_data/images/sphx_glr_crop_navigation_axes_003.png :alt: crop navigation axes :srcset: /examples/selecting_data/images/sphx_glr_crop_navigation_axes_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (1, 3) (1, 3) .. GENERATED FROM PYTHON SOURCE LINES 50-54 While ``inav`` returned a signal with only one navigation dimension, ``crop()`` left a single row. We can remove this ``(1,)`` dimension using :meth:`~hyperspy.signal.BaseSignal.squeeze`, but note that the custom ``EBSD`` attributes are not cropped accordingly .. GENERATED FROM PYTHON SOURCE LINES 54-60 .. code-block:: default s4 = s3.squeeze() print(s4) print(s4.xmap.shape) print(s4.detector.navigation_shape) .. rst-class:: sphx-glr-script-out .. code-block:: none (1, 3) (1, 3) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.946 seconds) **Estimated memory usage:** 9 MB .. _sphx_glr_download_examples_selecting_data_crop_navigation_axes.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: crop_navigation_axes.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: crop_navigation_axes.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_