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. The method’s uses are greatly detailed in HyperSpy’s visualization 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 as pv
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
pv.set_jupyter_backend("static")
[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]:
maps_vbse_rgb = vbse_imager.get_rgb_image(r=(3, 1), b=(3, 2), g=(3, 3))
maps_vbse_rgb
[5]:
<VirtualBSEImage, title: , dimensions: (|75, 55)>
[6]:
s.plot(navigator=maps_vbse_rgb, cmap="viridis")
../_images/tutorials_visualizing_patterns_10_0.png
../_images/tutorials_visualizing_patterns_10_1.png

Any image#

An image made into a Signal2D can be used as navigators. This includes quality metric maps such as the image quality map, calculated using get_image_quality()

[7]:
s.remove_static_background()
s.remove_dynamic_background()
[########################################] | 100% Completed | 202.60 ms
[########################################] | 100% Completed | 707.52 ms
[8]:
maps_iq = s.get_image_quality()
s_iq = hs.signals.Signal2D(maps_iq)
s.plot(navigator=s_iq)
[########################################] | 100% Completed | 403.25 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 IPF-Z map representing orientations obtained from dictionary indexing in the pattern matching tutorial

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

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

By overlaying the image quality map on the RGB image, we can visualize crystal directions within grains and the grain morphology in the same image

[10]:
maps_iq_1d = maps_iq.ravel()  # Flat array required by orix
maps_ipfz_1d = maps_ipfz.reshape(-1, 3)
fig = s.xmap.plot(maps_ipfz_1d, overlay=maps_iq_1d, return_figure=True)
../_images/tutorials_visualizing_patterns_17_0.png

By extracting the image array, we can use this map to navigate patterns in

[11]:
maps_ipfz_iq = fig.axes[0].images[0].get_array()
s_ipfz_iq = kp.draw.get_rgb_navigator(maps_ipfz_iq)
s.plot(s_ipfz_iq)
../_images/tutorials_visualizing_patterns_19_0.png
../_images/tutorials_visualizing_patterns_19_1.png

Plot multiple signals#

HyperSpy provides the function plot_signals() to plot multiple signals with the same navigator (detailed in their documentation). Among other uses, this function enables plotting of the experimental and best matching simulated patterns side by side. This can be a powerful visual validation 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 upper/lower hemispheres. Let’s reload the nickel master pattern used in the previous section, but this time in the stereographic projection.

[12]:
# 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 upper and lower hemispheres. When plotting, we therefore get a navigation slider

[13]:
../_images/tutorials_visualizing_patterns_24_0.png
../_images/tutorials_visualizing_patterns_24_1.png

We can plot the master pattern on the sphere with EBSDMasterPattern.plot_spherical(). This visualization requires the master pattern to be in the stereographic projection. If the corresponding phase is centrosymmetry, the upper and lower hemispheres are identical, so we only need one of them to cover the sphere. If the phase is non-centrosymmetric, however, both hemispheres must be loaded, as they are unequal. The initial orientation of the sphere corresponds to the orientation of the stereographic and Lambert projections.

[14]:
mp_stereo.plot_spherical(style="points")
../_images/tutorials_visualizing_patterns_26_0.png

PyVista, required for this plot, is an optional dependency of kikuchipy (see the installation guide for details). Here, the plot uses the static Jupyter backend supported by PyVista. The backend was set in the first notebook cell. When running the notebook locally, we can make the plot interactive setting the backend to "trame". We can pass plotter_kwargs={"notebook": False}" to plot_spherical() if we want to plot the master pattern in a separate window.