Note
Go to the end to download the full example code.
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_signal() 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)

<EBSD, title: patterns Scan 1, dimensions: (3, 3|60, 60)>
(60, 60)
EBSDDetector(shape=(60, 60), pc=(0.425, 0.213, 0.501), sample_tilt=70.0, tilt=0.0, azimuthal=0.0, binning=8.0, px_size=1.0 um)
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)

<EBSD, title: patterns Scan 1, dimensions: (3, 3|50, 40)>
(40, 50)
EBSDDetector(shape=(40, 50), pc=(0.41, 0.07, 0.751), sample_tilt=70.0, tilt=0.0, azimuthal=0.0, binning=8.0, px_size=1.0 um)
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)

<EBSD, title: patterns Scan 1, dimensions: (3, 3|50, 40)>
(40, 50)
EBSDDetector(shape=(40, 50), pc=(0.41, 0.07, 0.751), sample_tilt=70.0, tilt=0.0, azimuthal=0.0, binning=8.0, px_size=1.0 um)
Do the same inplace using crop_signal()
s4 = s.deepcopy()
s4.crop_signal(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)

<EBSD, title: patterns Scan 1, dimensions: (3, 3|50, 40)>
(40, 50)
EBSDDetector(shape=(40, 50), pc=(0.41, 0.07, 0.751), sample_tilt=70.0, tilt=0.0, azimuthal=0.0, binning=8.0, px_size=1.0 um)
Total running time of the script: (0 minutes 2.674 seconds)
Estimated memory usage: 739 MB