Crop signal axes#

This example shows various ways to crop the signal axes of an EBSD signal using HyperSpy’s isig slicer and the crop() and crop_image() methods (see Indexing for details).

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.static_background.shape)
print(s.detector)
crop signal axes
<EBSD, title: patterns Scan 1, dimensions: (3, 3|60, 60)>
(60, 60)
EBSDDetector (60, 60), px_size 1 um, binning 8, tilt 0, azimuthal 0, pc (0.425, 0.213, 0.501)

Get a new signal, removing the first and last ten rows of pixels and first and last five columns of pixels. Note how the static_background and detector attributes are updated.

s2 = s.isig[5:55, 10:50]

_ = hs.plot.plot_images(s2, **plot_kwds)
print(s2)
print(s2.static_background.shape)
print(s2.detector)
crop signal axes
<EBSD, title: patterns Scan 1, dimensions: (3, 3|50, 40)>
(40, 50)
EBSDDetector (40, 50), px_size 1 um, binning 8, tilt 0, azimuthal 0, pc (0.41, 0.07, 0.751)

Do the same inplace using crop()

s3 = s.deepcopy()
s3.crop(2, start=5, end=55)
s3.crop("dy", start=10, end=50)

_ = hs.plot.plot_images(s3, **plot_kwds)
print(s3)
print(s3.static_background.shape)
print(s3.detector)
crop signal axes
<EBSD, title: patterns Scan 1, dimensions: (3, 3|50, 40)>
(40, 50)
EBSDDetector (40, 50), px_size 1 um, binning 8, tilt 0, azimuthal 0, pc (0.41, 0.07, 0.751)

Do the same inplace using crop_image()

s4 = s.deepcopy()
s4.crop_image(top=10, bottom=50, left=5, right=55)

_ = hs.plot.plot_images(s4, **plot_kwds)
print(s4)
print(s4.static_background.shape)
print(s4.detector)
crop signal axes
<EBSD, title: patterns Scan 1, dimensions: (3, 3|50, 40)>
(40, 50)
EBSDDetector (40, 50), px_size 1 um, binning 8, tilt 0, azimuthal 0, pc (0.41, 0.07, 0.751)

Total running time of the script: (0 minutes 3.002 seconds)

Estimated memory usage: 13 MB

Gallery generated by Sphinx-Gallery