operation#
Operation modules provide reusable numerical routines used by analyzers.
operation.stitch#
Operation functions to stitch profiles together.
- pyleem.operation.stitch.find_stitch_points(x_ranges, method='midpoint')[source]#
Locate the stitch points between the ranges.
- Parameters:
x_ranges (list) – List of abscissa ranges.
method (str) – Method to locate the stitch points.
- Returns:
List of stitch points.
- Return type:
list
- pyleem.operation.stitch.stitch_profiles(x_array_list, y_array_list, mask_points)[source]#
Stitch profiles together based on mask points.
Each x and y array is assumed to be sorted. Currently, if the abscissa of a profile lands exactly on a mask point, the point is included in the first profile and excluded from the second profile. For the last profile, the last mask point is included.
This can lead to an issue that at same x value, there are two different y values.
- Parameters:
x_array_list (list) – List of x arrays for each profile.
y_array_list (list) – List of y arrays for each profile.
mask_points (list) – List of mask points between profiles.
- Returns:
Stitched profile and abscissa.
- Return type:
tuple
operation.drift#
Drift correction for stacks of LEEM images.
This module adapts the pairwise image-registration approach described by de Jong et al., Ultramicroscopy 213, 112913 (2020), DOI: 10.1016/j.ultramic.2019.112913, and demonstrated in the MIT-licensed TAdeJong/LEEM-analysis drift correction notebook: TAdeJong/LEEM-analysis
- pyleem.operation.drift.filter_image(image, sigma=3, crop_size=None)[source]#
Crop, smooth, edge-filter, and center one image for registration.
- pyleem.operation.drift.filter_images(images, sigma=3, crop_size=None)[source]#
Filter an image stack for drift registration.
- pyleem.operation.drift.choose_max_workers(max_workers)[source]#
Choose the number of drift-correction worker threads.
- pyleem.operation.drift.registration_weight(error)[source]#
Return a least-squares weight from a registration error.
- pyleem.operation.drift.relative_shifts(images, upsample_factor=10, max_workers=None, chunk_size=32, max_distance=None)[source]#
Return pairwise shifts needed to align image j to image i.
- pyleem.operation.drift.frame_pairs(count, max_distance=None)[source]#
Yield frame pairs to register.
- pyleem.operation.drift.chunk_pairs(pairs, chunk_size)[source]#
Yield fixed-size chunks from a stream of frame pairs.
- pyleem.operation.drift.register_pairs(images, pairs, upsample_factor)[source]#
Register image pairs and return their measured shifts.
- pyleem.operation.drift.register_pairs_threaded(images, pairs, upsample_factor, max_workers, chunk_size)[source]#
Register pair chunks with a thread pool.
- pyleem.operation.drift.absolute_shifts(relative_shift_array, weights=None, reference_index=0)[source]#
Reduce pairwise shifts to correction shifts for each image.
- pyleem.operation.drift.calculate_drift(images, sigma=3, crop_size=None, upsample_factor=10, max_workers=None, chunk_size=32, max_distance=None, reference_index=0)[source]#
Estimate correction shifts for an image stack.
Shifts use NumPy image-axis order, (y, x). The returned shifts are the correction shifts applied to each image, relative to reference_index.
- pyleem.operation.drift.shift_canvas(image_shape, shifts)[source]#
Return the canvas shape and offset needed to apply the shifts.