get_direct_beam_position#

Diffraction2D.get_direct_beam_position(method, lazy_output=None, signal_slice=None, half_square_width=None, show_slice_on_plot=False, subpixel=True, prefilter_sigma=None, **kwargs)[source]#

Estimate the direct beam position in each experimentally acquired electron diffraction pattern. Returns the shifts required to center the diffraction pattern.

Parameters:
  • method (str,) – Must be one of “cross_correlate”, “blur”, “interpolate” or “center_of_mass”.

    “cross_correlate”: Center finding using cross-correlation of circles of

    radius_start to radius_finish.

    “blur”: Center finding by blurring each frame with a Gaussian kernel with

    standard deviation sigma and finding the maximum.

    “interpolate”: Finding the center by summing along X/Y and finding the peak

    for each axis independently. Data is blurred first using a Gaussian kernel with standard deviation sigma.

    “center_of_mass”: The center is found using a calculation of the center of mass.

    Optionally a mask can be applied to focus on just the center of some dataset. To suppress contrast from diffuse scattering, a threshold value threshold can also be given. The mean intensity of the diffraction image will be multiplied by this and any values below the product will be set to 0.

  • lazy_output (optional) – If True, s_shifts will be a lazy signal. If False, a non-lazy signal. By default, if the signal is (non-)lazy, the result will also be (non-)lazy.

  • signal_slice (None or tuple) – A tuple defining the (low_x,high_x, low_y, high_y) to slice the data before finding the direct beam. Equivalent to s.isig[low_x:high_x, low_y:high_y].get_direct_beam_position()+[low_x,low_y])

  • half_square_width (int) – Half the side length of square that captures the direct beam in all scans. Means that the centering algorithm is stable against diffracted spots brighter than the direct beam. Crops the diffraction pattern to half_square_width pixels around the center of the diffraction pattern. Only one of half_square_width or signal_slice can be defined.

  • show_slice_on_plot (bool) – Add a marker on the signal to indicate the area considered in the estimation of the direct beam. Default is False.

  • subpixel (bool) – For blur and interpolate method only - other methods process with subpixel precision. If True, the beam position is calculated with subpixel precision by upsampling before measuring the beam position. The upsampling factor can be adjusted by passing the upsampling_factor parameter (default is 5.0). If False, the beam position is calculated without subpixel precision. Default is True.

  • prefilter_sigma (float, optional) – Standard deviation for the Gaussian kernel used for prefiltering the data with the before finding the direct beam. If None, no prefiltering is done. If int or float, filtering is applied to the navigation axes only. Use iterable to filter in both navigation and signal axes.

  • **kwargs (dict) – Additional arguments accepted by pyxem.utils.diffraction.find_beam_center_blur(), pyxem.utils.diffraction.find_beam_center_interpolate(), pyxem.utils.diffraction.find_beam_offset_cross_correlation(), and pyxem.signals.diffraction.center_of_mass_from_image(),

Returns:

s_shifts – Array containing the shifts for each SED pattern, with the first signal index being the x-shift and the second the y-shift.

Return type:

pyxem.signals.BeamShift

Examples

Using center of mass method

>>> s = pxm.data.tilt_boundary_data(correct_pivot_point=False)
>>> s_bs = s.get_direct_beam_position(method="center_of_mass")
>>> s_bs_color = s_bs.get_magnitude_phase_signal()

Also threshold

>>> s_bs = s.get_direct_beam_position(method="center_of_mass", threshold=2)

Get a lazy signal, then calculate afterwards

>>> s_bs = s.get_direct_beam_position(lazy_output=True, method="center_of_mass")
>>> s_bs.compute(show_progressbar=False)

Setting the upsampling factor (default 4.0) for setting the subpixel precision with the blur method

>>> s_shifts = s.get_direct_beam_position(
...     method="blur", sigma=5, half_square_width=15, upsampling_factor=2.0
... )

Using a pre-filtering step before finding the direct beam

>>> s_shifts = s.get_direct_beam_position(
...     method="blur", sigma=5, half_square_width=15, prefilter_sigma=2.0
... )