This page was generated from doc/tutorials/visualizing_patterns.ipynb. Interactive online version: Binder badge.

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 hyperspy.api as hs
import kikuchipy as kp
import matplotlib.pyplot as plt
import numpy as np
from orix import io, plot, quaternion, vector
import pyvista
import skimage.exposure as ske
import skimage.transform as skt


pyvista.global_theme.window_size = [700, 700]
pyvista.set_jupyter_backend(
    "pythreejs"
)  # See https://docs.pyvista.org/user-guide/jupyter/index.html
[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

VirtualBSEGenerator for <EBSD, title: patterns Scan 1, dimensions: (75, 55|60, 60)>
(5, 5)
[5]:
vbse_rgb = vbse_gen.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 | 203.60 ms
[########################################] | 100% Completed | 811.22 ms
[8]:
iq = s.get_image_quality()
s_iq = hs.signals.Signal2D(iq)
s.plot(navigator=s_iq, scalebar=False)
[########################################] | 100% Completed | 408.75 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")

This plot uses one of the Jupyter backends supported by PyVista, which must be installed separately. If we want to plot the master pattern in a separate window instead, we can pass plotter_kwargs={"notebook": False}" to plot_spherical(). PyVista, required for this interactive plot, is an optional dependency of kikuchipy; see the installation guide for details.