xrheed.kinematics.ewald

Classes

Ewald(lattice[, image, stack_index])

Class for calculating and analyzing the Ewald sphere construction in RHEED.

class Ewald(lattice, image=None, stack_index=0)[source]

Bases: object

Class for calculating and analyzing the Ewald sphere construction in RHEED.

This class combines experimental RHEED image metadata with a reciprocal lattice model to predict diffraction spot positions on the screen.

Azimuthal angle convention

Three azimuthal angles are distinguished:

  • image_azimuthal_angle

    Experimental azimuth of the RHEED image, read from image metadata. This value defines the reference frame and is treated as immutable.

  • ewald_azimuthal_rotation

    User-defined relative rotation of the Ewald construction with respect to the image azimuth. This does not modify the image metadata.

  • Ewald azimuthal angles (effective)

    The azimuthal angles actually used in the Ewald construction, derived as

    image_azimuthal_angle ± ewald_azimuthal_rotation

    When mirror symmetry is enabled, both ± rotations are used.

This separation preserves the experimental reference frame while allowing controlled relative rotation of the theoretical Ewald construction.

SPOT_HEIGHT_MM = 5.0
SPOT_WIDTH_MM = 1.5
__init__(lattice, image=None, stack_index=0)[source]

Initialize an Ewald object for RHEED spot calculations.

Parameters:
  • lattice (Lattice) – Lattice object representing the crystal structure.

  • image (Optional[xr.DataArray], optional) – RHEED image data. Can be a single image or a stack of images. If None, default values are used.

  • stack_index (int, optional) – Index of the image to use from a stack (default is 0).

beam_energy
cache_dir
cache_key
calculate_ewald(**kwargs)[source]

Calculate the Ewald construction and update spot positions.

Updates

self.ew_sxNDArray

Spot x-coordinates (mm).

self.ew_syNDArray

Spot y-coordinates (mm).

calculate_match(normalize=True)[source]

Calculate the match coefficient between predicted and observed spots.

Parameters:

normalize (bool) – If True, normalize the coefficient by the number of spots.

Returns:

Match coefficient.

Return type:

np.uint32

ew_sx
ew_sy
property ewald_azimuthal_angle
property ewald_azimuthal_rotation
ewald_radius
property ewald_roi
fine_scaling
image
property image_azimuthal_angle
property incident_angle
label
property lattice_scale
match_alpha(alpha_vector, normalize=True, tqdm_disable=True)[source]

Calculate match coefficients over a range of azimuthal angles.

Parameters:
  • alpha_vector (NDArray[np.float64]) – Array of alpha (azimuthal) angles in degrees.

  • normalize (bool, optional) – If True, normalize the coefficients (default: True).

  • tqdm_disable (bool, optional) – If False, show the tqdm progress bar (default: True).

Returns:

Match coefficients with alpha as coordinate.

Return type:

xr.DataArray

match_alpha_scale(alpha_vector, scale_vector, normalize=True, flatten=True, tqdm_disable=True)[source]

Calculate the match coefficient for a grid of alpha angles and scale values.

Parameters:
  • alpha_vector (NDArray) – Array of azimuthal angles to test.

  • scale_vector (NDArray) – Array of scale values to test.

  • normalize (bool, optional) – If True, normalize the match coefficient (default: True).

  • flatten (bool, optional) –

    If True, the result map is flatten by subtracting quadratic background fitted along scale direction

    (default: True).

  • tqdm_disable (bool, optional) – If False, show the tqdm progress bar (default: True).

Returns:

Match coefficients for each (alpha, scale) pair.

Return type:

xr.DataArray

match_scale(scale_vector, normalize=True, tqdm_disable=True)[source]

Calculate the match coefficient for a series of lattice scale values.

Parameters:
  • scale_vector (NDArray) – Array of scale values to test.

  • normalize (bool, optional) – If True, normalize the match coefficient (default: True).

  • tqdm_disable (bool, optional) – If False, show the tqdm progress bar (default: True).

Returns:

Match coefficients for each scale value.

Return type:

xr.DataArray

mirror_symmetry
plot(ax=None, show_image=True, show_roi=False, auto_levels=0.0, show_center_lines=False, **kwargs)[source]

Plot the calculated spot positions and optionally the RHEED image.

Parameters:
  • ax (Optional[Axes], optional) – Matplotlib axes to plot on. If None, a new figure is created.

  • show_image (bool, optional) – If True, plot the RHEED image (default: True).

  • show_roi (bool, optional) – If True, overlay the ROI boundary (default: False).

  • auto_levels (float, optional) – Contrast enhancement factor for image plotting.

  • show_center_lines (bool, optional) – If True, plot center cross lines (default: False).

  • **kwargs – Additional keyword arguments for the scatter plot.

Returns:

The axes with the plotted data.

Return type:

matplotlib.axes.Axes

plot_spots(ax=None, show_image=False, **kwargs)[source]

Plot the spot mask used for spot matching on a RHEED image.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Matplotlib Axes to plot on. If None, a new figure and axes are created.

  • show_image (bool, default=False) – If True, overlay the spot mask on the original RHEED image. If False, only the mask is displayed.

  • **kwargs – Additional keyword arguments passed to ax.imshow(), e.g., cmap, alpha.

Returns:

The axes containing the plotted mask (and optionally the image).

Return type:

matplotlib.axes.Axes

Raises:

ValueError – If show_image=True but no RHEED image is attached (self.image is None).

Notes

  • The mask is automatically generated by self._generate_mask().

  • The image coordinates (sx, sy) are used to set the extent of the plot.

  • The default colormap for the mask is grayscale.

screen_roi_height
screen_roi_width
screen_sample_distance
screen_scale
set_spot_size(width, height)[source]

Set the spot size used for mask generation.

Parameters:
  • width (float) – Spot width in mm.

  • height (float) – Spot height in mm.

shift_x
shift_y
spot_structure
property stack_index

Index of the current image in a stack.

Type:

int

use_cache