Change navigation and signal shapes¶
Patterns in an EBSD or EBSDMasterPattern signal s
are stored in the s.data
attribute as either numpy.ndarray or dask.array.Array. HyperSpy’s user guide explains how to access, i.e. index, the
data. This section details example uses of navigation (scan) and signal (pattern) indexing specific to EBSD and EBSDMasterPattern signals.
Let’s import the necessary libraries, a larger Nickel EBSD test data set from the kikuchipy.data module [AHvHM19], and the Nickel master pattern, also from the data module
[1]:
# exchange inline for qt5 for interactive plotting from the pyqt package
%matplotlib inline
import hyperspy.api as hs
import kikuchipy as kp
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["font.size"] = 15
# Use kp.load("data.h5") to load your own data
s = kp.data.nickel_ebsd_large(allow_download=True) # External download
print(s)
s_mp = kp.data.nickel_ebsd_master_pattern_small(hemisphere="both")
print(s_mp, s_mp.projection)
WARNING:hyperspy.api:The ipywidgets GUI elements are not available, probably because the hyperspy_gui_ipywidgets package is not installed.
WARNING:hyperspy.api:The traitsui GUI elements are not available, probably because the hyperspy_gui_traitsui package is not installed.
Downloading file 'data/nickel_ebsd_large/patterns.h5' from 'https://github.com/pyxem/kikuchipy-data/raw/master/nickel_ebsd_large/patterns.h5' to '/home/docs/.cache/kikuchipy/master'.
100%|█████████████████████████████████████| 13.0M/13.0M [00:00<00:00, 4.26GB/s]
<EBSD, title: patterns Scan 1, dimensions: (75, 55|60, 60)>
<EBSDMasterPattern, title: ni_mc_mp_20kv_uint8_gzip_opts9, dimensions: (2|401, 401)> stereographic
Crop the navigation or signal axes¶
A new EBSD
or EBSDMasterPattern
signal s2
can be created from a region of interest (ROI) in another EBSD or EBSDMasterPattern signal s
by using HyperSpy’s navigation indexing method inav
. The new signal keeps the metadata
and original_metadata
of s
. Say we, after plotting and inspecting the EBSD signal, want to create a new, smaller signal of the patterns within a rectangle defined by the upper left pattern with index (5, 7) (column, row) and the bottom right
pattern with index (17, 23)
[2]:
s2 = s.inav[5:17, 7:23]
s2
[2]:
<EBSD, title: patterns Scan 1, dimensions: (12, 16|60, 60)>
Or, we want only the northern hemisphere of the EBSDMasterPattern
[3]:
s_mp2 = s_mp.inav[0]
s_mp2
[3]:
<EBSDMasterPattern, title: ni_mc_mp_20kv_uint8_gzip_opts9, dimensions: (|401, 401)>
Patterns can also be cropped with the signal indexing method isig
. Say we wanted to remove the ten outermost pixels in our (60, 60) pixel Nickel patterns
[4]:
s3 = s.isig[10:50, 10:50]
s3
[4]:
<EBSD, title: patterns Scan 1, dimensions: (75, 55|40, 40)>
[5]:
fig, ax = plt.subplots(figsize=(13, 6), ncols=2)
ax[0].imshow(s.inav[10, 50].data, cmap="gray")
ax[0].set_title("Original")
ax[0].axis("off")
ax[1].imshow(s3.inav[10, 50].data, cmap="gray")
ax[1].set_title("Cropped")
ax[1].axis("off")
fig.tight_layout(w_pad=-8)

Binning¶
A new EBSD
signal with patterns binned e.g. by 2 can be obtained using the rebin() method provided by HyperSpy, explained further in their user guide, by passing in either the scale
or new_shape
parameter
[6]:
print(s, s.data.dtype)
<EBSD, title: patterns Scan 1, dimensions: (75, 55|60, 60)> uint8
[7]:
s4 = s.rebin(scale=(1, 1, 2, 2))
print(s4, s4.data.dtype)
<EBSD, title: patterns Scan 1, dimensions: (75, 55|30, 30)> uint64
[8]:
s5 = s.rebin(new_shape=(75, 55, 30, 30))
print(s5, s5.data.dtype)
<EBSD, title: patterns Scan 1, dimensions: (75, 55|30, 30)> uint64
[9]:
fig, ax = plt.subplots(figsize=(13, 6), ncols=2)
ax[0].imshow(s4.inav[10, 50].data, cmap="gray")
ax[0].set_title("rebin() with scale")
ax[1].imshow(s5.inav[10, 50].data, cmap="gray")
ax[1].set_title("rebin() with new_shape")
fig.tight_layout()

Note that rebin()
casts the data to uint64
. This means that in this example, each pixel in the binned signals s4
and s5
takes up eight times the memory of pixels in the original signal s
(uint8
). To revert to uint8
data type, we must rescale the intensities with rescale_intensity().
This also works for EBSDMasterPattern
signals.