Check out the Hyperspy Workshop May 13-17, 2024 Online

Angular Correlations of Amorphous Materials#

This notebook demonstrates caclulating the angular correlation of diffraction patterns recorded from an amorphous (or crystalline) material.

The dataset used for this demonstration is a 4-D STEM dataset of a PdNiP deposited thin film glass aquired using a DE-16 Camera and a 200keV FEI-Titan electron microscopt at 100 fps. The probe size was ~2-nm and step size was .365 nm so there there is singificant probe overlap in the probe positions.

This functionality has been checked to run with pyxem-0.15.0 (April 2023). Bugs are always possible, do not trust the code blindly, and if you experience any issues please report them here: pyxem/pyxem-demos#issues

Background#

Angular Correlations are a very natural extension to variance type studies. They offer more insight into the symmetry of the strucutures being studied as well as offering the ability to be studied spatially.

Mathmatically, the Angular correlation is the angular-autocorrelation of some polar unwrapped diffraction pattern I(k).

$ C(k,:nbsphinx-math:phi) = \frac{_\theta - ^2_\theta }{^2_\theta} $

This is simlar to the radial (“r”) variance often calculated in Fluctuation Electron Microscopy.

Contents#

  1. Importing & Visualization

  2. Polar Reprojection

  3. Angular Correlation

  4. Power Spectrum and Correlation Maps

1 - Importing and Visualization#

This section goes over loading the data from the data folder and visualizing the data for further use.

[ ]:
data_path = "data/09/PdNiP_test.hspy"
[ ]:
%matplotlib inline
import pyxem as pxm
import hyperspy.api as hs
WARNING:silx.opencl.common:Unable to import pyOpenCl. Please install it from: https://pypi.org/project/pyopencl
[ ]:
pxm.__version__
'0.15.1'
[ ]:
data = hs.load("./data/09/PdNiP_test.hspy")
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/io.py:572: VisibleDeprecationWarning: Loading old file version. The binned attribute has been moved from metadata.Signal to axis.is_binned. Setting this attribute for all signal axes instead.
  warnings.warn('Loading old file version. The binned attribute '

2 - Polar Reprojection#

This section deals with converting the signal to a polar signal. This is probably the most important and difficult part of the analysis. Even small distortions in the pattern or misinterpertation of the center of the diffraction pattern will negitively affect the ability to determine correlations.

There is still some ongoing development on methods for identifying and correcting for these distortions but a good check is always to perform the correct and make sure that the first amorphous ring is a line after the polar reprojection. In general your eye should be very good at identifying that. Another thing to notice is that after the correlation if you have small splititing in all of your peaks(especially the self correlation) then most likely your center isn’t completely correct.

[ ]:
data.set_signal_type("electron_diffraction")
data.beam_energy=200
data.unit = "k_nm^-1"

[ ]:
mask =data.get_direct_beam_mask(20)
[ ]:
# Affine correction from fitting an ellipse
import numpy as np
center=(31.2,31.7)
affine=np.array([[ 1.03725511, -0.02662789,  0.        ],
                 [-0.02662789,  1.01903215,  0.        ],
                 [ 0.        ,  0.        ,  1.        ]])
[ ]:
data.set_ai(center=center)
rad = data.get_azimuthal_integral2d(npt=100)
WARNING:pyFAI.geometry.core:No fast path for space: k
[                                        ] | 0% Completed | 105.78 ms
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
[########################################] | 100% Completed | 3.36 ss

Note: This isn’t perfect, as you can see there is still some distortion that an affine transformation could fix, but for the purposes of this demo this it will suffice

[ ]:
rad.sum().plot()
../../_images/tutorials_pyxem-demos_09_Angular_Correlations_of_Amorphous_Materials_20_0.png

3 - Angular Correlations#

This section deals with converting the signal to a correlation signal. The most important part here is to properly mask the data. This is important for example if you have a beam stop

[ ]:
summed = rad.sum()
mask = ((summed>4e6)+(summed<3e5))
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
[ ]:
mask.plot()
../../_images/tutorials_pyxem-demos_09_Angular_Correlations_of_Amorphous_Materials_24_0.png
[ ]:
rad.plot(vmax=4000)
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
../../_images/tutorials_pyxem-demos_09_Angular_Correlations_of_Amorphous_Materials_25_1.png
../../_images/tutorials_pyxem-demos_09_Angular_Correlations_of_Amorphous_Materials_25_2.png
[ ]:
cor = rad.get_angular_correlation(mask=mask)
WARNING:hyperspy.signal:The function you applied does not take into account the difference of units and of scales in-between axes.
[                                        ] | 0% Completed | 105.46 us
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
[########################################] | 100% Completed | 1.05 ss
[ ]:
cor.plot()
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
../../_images/tutorials_pyxem-demos_09_Angular_Correlations_of_Amorphous_Materials_27_1.png
../../_images/tutorials_pyxem-demos_09_Angular_Correlations_of_Amorphous_Materials_27_2.png
[ ]:
cor = rad.map(pxm.utils.correlation_utils._correlation, inplace=False, axis=1, normalize=True)
WARNING:hyperspy.signal:The function you applied does not take into account the difference of units and of scales in-between axes.
[                                        ] | 0% Completed | 110.00 us
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
[########################################] | 100% Completed | 526.11 ms
[ ]:
cor.isig[:].plot(vmax=1, vmin=-1)
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
../../_images/tutorials_pyxem-demos_09_Angular_Correlations_of_Amorphous_Materials_29_1.png
../../_images/tutorials_pyxem-demos_09_Angular_Correlations_of_Amorphous_Materials_29_2.png

4 - Power Spectrum and Correlation Maps#

This section deals with visualization of the correlations as correlation maps. These are spatial maps of the strucutre in some material.

[ ]:
power = cor.get_angular_power()
WARNING:hyperspy.signal:The function you applied does not take into account the difference of units and of scales in-between axes.
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
[                                        ] | 0% Completed | 106.54 ms
/Users/carterfrancis/mambaforge/envs/pyxem-demos/lib/python3.11/site-packages/hyperspy/misc/utils.py:471: VisibleDeprecationWarning: Use of the `binned` attribute in metadata is going to be deprecated in v2.0. Set the `axis.is_binned` attribute instead.
  warnings.warn(
[########################################] | 100% Completed | 215.90 ms
[ ]:
import matplotlib.pyplot as plt
f = plt.figure(figsize=(15,10))
power.plot_symmetries(k_region = [3.,4.5],fig=f)
../../_images/tutorials_pyxem-demos_09_Angular_Correlations_of_Amorphous_Materials_33_0.png