This page was generated from doc/user_guide/change_navigation_signal_shapes.ipynb. Interactive online version: Binder badge.

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 [AHvHM19], and the Nickel master pattern, also from the data module

# 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")
<EBSD, title: patterns Scan 1, dimensions: (75, 55|60, 60)>
<EBSDMasterPattern, title: ni_mc_mp_20kv_uint8_gzip_opts9, dimensions: (2|401, 401)>


EBSD methods inherited from HyperSpy that changes the pattern array in any way, like cropping the navigation shape with EBSD.inav, will not crop the CrystalMap stored in the xmap property. This also goes for the detector and static_background properties. Remember for example to crop the background pattern accordingly before calling EBSD.remove_static_background() after EBSD.isig is used to crop the patterns.

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)

s2 = s.inav[5:17, 7:23]
<EBSD, title: patterns Scan 1, dimensions: (12, 16|60, 60)>

Or, we want only the northern hemisphere of the EBSDMasterPattern

s_mp2 = s_mp.inav[0]
<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

s3 = s.isig[10:50, 10:50]
<EBSD, title: patterns Scan 1, dimensions: (75, 55|40, 40)>
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

<EBSD, title: patterns Scan 1, dimensions: (75, 55|60, 60)> uint8
s4 = s.rebin(scale=(1, 1, 2, 2))
<EBSD, title: patterns Scan 1, dimensions: (75, 55|30, 30)> uint64
s5 = s.rebin(new_shape=(75, 55, 30, 30))
<EBSD, title: patterns Scan 1, dimensions: (75, 55|30, 30)> uint64
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.