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

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)

# Getting the Position of the Zero beam
# -------------------------------------
# The zero beam position can be obtained using the :meth:`get_direct_beam_position` method.

shifts = s.get_direct_beam_position(method="blur", sigma=5, half_square_width=20)
hs.plot.plot_images(shifts.T)  # Plotting the shifts
(0,),  (1,)
[                                        ] | 0% Completed | 155.05 us
[                                        ] | 0% Completed | 100.47 ms
[########################################] | 100% Completed | 200.84 ms

[                                        ] | 0% Completed | 136.76 us
[########################################] | 100% Completed | 100.45 ms

[<Axes: title={'center': ' (0,)'}>, <Axes: title={'center': ' (1,)'}>]
# Making 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:`make_linear_plane` method.
shifts.make_linear_plane()  # Making a linear plane to remove the systematic shift
hs.plot.plot_images(shifts.T)  # Plotting the shifts after making a linear plane

# Centering the Zero Beam
# -----------------------
# The zero beam can be centered using the :meth:`center_direct_beam` method.

centered = s.center_direct_beam(shifts=shifts, inplace=False)
pacbed_centered = (
    centered.sum()
)  # Plotting the sum of the dataset to check that the zero beam is centered
pacbed = (
    s.sum()
)  # Plotting the sum of the dataset to check that the zero beam is centered

hs.plot.plot_images([pacbed, pacbed_centered], label=["Original", "Centered"])
  • (0,),  (1,)
  • Original, Centered
[                                        ] | 0% Completed | 144.12 us
[                                        ] | 0% Completed | 100.46 ms
[########################################] | 100% Completed | 200.83 ms

[<Axes: title={'center': 'Original'}>, <Axes: title={'center': 'Centered'}>]

Total running time of the script: (0 minutes 2.453 seconds)

Gallery generated by Sphinx-Gallery