This notebook is part of the kikuchipy documentation Links to the documentation won't work from the notebook.

Change navigation and signal shapes

Patterns in an EBSD or EBSDMasterPattern signal s are stored in the 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 module Ă…nes et al. (2019), and the Nickel master pattern, also from the data module

In [ ]:
# Exchange inline for notebook or qt5 (from pyqt) for interactive plotting
%matplotlib inline

import hyperspy.api as hs
import kikuchipy as kp
import matplotlib.pyplot as plt
import numpy as np

# Use kp.load("data.h5") to load your own data
s =  # External download

s_mp ="both")

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)

In [ ]:
s2 = s.inav[5:17, 7:23]

Or, we want only the northern hemisphere of the EBSDMasterPattern

In [ ]:
s_mp2 = s_mp.inav[0]

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

In [ ]:
s3 = s.isig[10:50, 10:50]
In [ ]:
fig, ax = plt.subplots(figsize=(13, 6), ncols=2)
ax[0].imshow(s.inav[10, 50].data, cmap="gray")
ax[1].imshow(s3.inav[10, 50].data, cmap="gray")


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

In [ ]:
In [ ]:
s4 = s.rebin(scale=(1, 1, 2, 2))
In [ ]:
s5 = s.rebin(new_shape=(75, 55, 30, 30))
In [ ]:
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")

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.