Live notebook

You can run this notebook in a live session Binder or view it on Github.

Visualizing patterns#

The EBSD and EBSDMasterPattern signals have a powerful and versatile plot() method provided by HyperSpy. Its uses are greatly detailed in HyperSpy’s visualisation user guide. This section details example uses specific to EBSD and EBSDMasterPattern signals.

Let’s import the necessary libraries and a Nickel EBSD test data set [Ånes et al., 2019]

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

import matplotlib.pyplot as plt
import numpy as np
import pyvista
import skimage.exposure as ske
import skimage.transform as skt

import hyperspy.api as hs
import kikuchipy as kp
from orix import io, plot, quaternion, vector


# See https://docs.pyvista.org/user-guide/jupyter/index.html
pyvista.set_jupyter_backend("panel")
2023-07-24 16:19:51,037 - numexpr.utils - INFO - NumExpr defaulting to 2 threads.
/tmp/ipykernel_7805/2126874160.py:16: PyVistaDeprecationWarning: `panel` backend is deprecated and is planned for future removal.
  pyvista.set_jupyter_backend("panel")
[2]:
# Use kp.load("data.h5") to load your own data
s = kp.data.nickel_ebsd_large(allow_download=True)  # External download
s
[2]:
<EBSD, title: patterns Scan 1, dimensions: (75, 55|60, 60)>

Virtual image#

A virtual backscatter electron (VBSE) image created from any detector region of interest with the get_virtual_bse_intensity() method or get_rgb_image() explained in the virtual backscatter electron imaging tutorial, can be used as a navigator for a scan s

[4]:
VirtualBSEImager for <EBSD, title: patterns Scan 1, dimensions: (75, 55|60, 60)>
(5, 5)
[5]:
vbse_rgb = vbse_imager.get_rgb_image(r=(3, 1), b=(3, 2), g=(3, 3))
vbse_rgb
[5]:
<VirtualBSEImage, title: , dimensions: (|75, 55)>
[6]:
s.plot(navigator=vbse_rgb, cmap="viridis")
../_images/tutorials_visualizing_patterns_10_0.png
../_images/tutorials_visualizing_patterns_10_1.png

Any image#

Images made into a Signal2D can be used as navigators, like a quality metric map like the image quality map calculated using get_image_quality()

[7]:
s.remove_static_background()
s.remove_dynamic_background()
[########################################] | 100% Completed | 205.65 ms
[########################################] | 100% Completed | 810.19 ms
[8]:
iq = s.get_image_quality()
s_iq = hs.signals.Signal2D(iq)
s.plot(navigator=s_iq)
[########################################] | 100% Completed | 405.82 ms
../_images/tutorials_visualizing_patterns_13_1.png
../_images/tutorials_visualizing_patterns_13_2.png

We can obtain an RGB signal from an RGB image using get_rgb_navigator(). Let’s load an orientation map from dictionary indexing in the pattern matching tutorial

[9]:
rgb_z = plt.imread(
    "../_static/image/visualizing_patterns/ni_large_rgb_z.png"
)
rgb_z = rgb_z[..., :3]  # Drop the alpha channel
s_rgb_z = kp.draw.get_rgb_navigator(rgb_z)

s.plot(navigator=s_rgb_z, colorbar=False)
../_images/tutorials_visualizing_patterns_15_0.png
../_images/tutorials_visualizing_patterns_15_1.png

Plot multiple signals#

HyperSpy provides the function plot_signals() to plot multiple signals with the same navigator, as explained in their documentation. This enables e.g. plotting of experimental and best matching simulated patterns side-by-side as a visual inspection of indexing results. See the pattern matching tutorial for a demonstration.

Plot master patterns#

EBSDMasterPattern signals can be navigated along their energy axis and/or their northern/southern hemisphere. Let’s reload the Nickel master pattern used in the previous section, but this time in the stereographic projection.

[10]:
# Only a single energy, 20 keV
mp_stereo = kp.data.nickel_ebsd_master_pattern_small(
    projection="stereographic", hemisphere="both"
)
print(mp_stereo.axes_manager)
<Axes manager, axes: (2|401, 401)>
            Name |   size |  index |  offset |   scale |  units
================ | ====== | ====== | ======= | ======= | ======
      hemisphere |      2 |      0 |       0 |       1 |
---------------- | ------ | ------ | ------- | ------- | ------
           width |    401 |      0 |  -2e+02 |       1 |     px
          height |    401 |      0 |  -2e+02 |       1 |     px

As can be seen from the axes manager, the master pattern has two navigation axes, the northern and southern hemispheres, thus, when plotting, we get a navigation slider

[11]:
../_images/tutorials_visualizing_patterns_20_0.png
../_images/tutorials_visualizing_patterns_20_1.png

We can plot the master pattern on the sphere, provided it is in the stereographic projection and that both hemispheres are loaded if it is non-centrosymmetric, using EBSDMasterPattern.plot_spherical(). The initial orientation of the sphere corresponds to the orientation of the stereographic and Lambert projections.

[12]:
# Interactive!
mp_stereo.plot_spherical(style="points")