Note
Go to the end to download the full example code.
Centering the Zero Beam#
Making a Dummy Dataset with a Zero Beam that systematically deviates from the center
import hyperspy.api as hs
import pyxem as pxm
s = pxm.data.tilt_boundary_data(correct_pivot_point=False)
[ ] | 0% Completed | 229.99 us
[ ] | 0% Completed | 100.56 ms
[ ] | 0% Completed | 200.95 ms
[########################################] | 100% Completed | 301.45 ms
Getting the Position of the Zero beam#
The zero beam position can be obtained using the get_direct_beam_position() method.
s_shifts = s.get_direct_beam_position(method="blur", sigma=5, half_square_width=20)
s_shifts.plot()
# Getting a Linear Plane
# ---------------------
# In many instances the zero beam position will vary systematically with the scan position.
# This can be corrected by fitting a linear plane to the zero beam position using the
# :meth:`get_linear_plane` method.
s_linear_plane = s_shifts.get_linear_plane()
s_linear_plane.plot()
[ ] | 0% Completed | 146.56 us
[########################################] | 100% Completed | 100.48 ms
[<Axes: title={'center': 'x-shift'}, xlabel='x axis (px)', ylabel='y axis (px)'>, <Axes: title={'center': 'y-shift'}, xlabel='x axis (px)', ylabel='y axis (px)'>]
Centering the Zero Beam#
The zero beam can be centered using the center_direct_beam() method.
Then we sum all the diffraction patterns for the both the centered beam,
and the non-centered one, to compare them.
s_centered = s.center_direct_beam(shifts=s_linear_plane, inplace=False)
s_pacbed_centered = s_centered.sum()
s_pacbed = s.sum()
hs.plot.plot_images([s_pacbed, s_pacbed_centered], label=["Original", "Centered"])

[ ] | 0% Completed | 159.02 us
[ ] | 0% Completed | 100.48 ms
[########################################] | 100% Completed | 200.86 ms
[<Axes: title={'center': 'Original'}, xlabel='kx axis (px)', ylabel='ky axis (px)'>, <Axes: title={'center': 'Centered'}, xlabel='kx axis (px)', ylabel='ky axis (px)'>]
Total running time of the script: (0 minutes 2.068 seconds)

