Skip to content

pypty.se

getvirtualhaadf

Compute a virtual HAADF image from 4D-STEM data.

PARAMETER DESCRIPTION
pypty_params

Dictionary with keys 'data_path', 'scan_size', 'plot', 'output_folder'.

TYPE: dict

save

Whether to save the image. Default is True.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
haadf

HAADF intensities array.

TYPE: ndarray

get_aperture

Generate a binary aperture mask from diffraction data.

PARAMETER DESCRIPTION
params

Dictionary with keys 'data_path', 'data_pad', 'plot', 'bright_threshold', 'flip_ky'.

TYPE: dict

RETURNS DESCRIPTION
params

Updated dict including 'aperture_mask'.

TYPE: dict

create_binned_dataset

Downsample a dataset by spatial binning and save to a new file.

PARAMETER DESCRIPTION
path_orig

Path to the original dataset.

TYPE: str

path_new

Path to save the binned dataset.

TYPE: str

bin

Binning factor.

TYPE: int

RAISES DESCRIPTION
IOError

If file operations fail.

compensate_pattern_drift

Compensate drift in diffraction patterns via phase correlation.

PARAMETER DESCRIPTION
aperture

Binary aperture mask.

TYPE: ndarray

patterns

4D diffraction patterns.

TYPE: ndarray

RETURNS DESCRIPTION
ndarray

Drift-compensated patterns.

get_virtual_annular_detector

Compute virtual detector signal using annular masks.

PARAMETER DESCRIPTION
pypty_params

Dictionary with keys 'data_path', 'scan_size', 'plot', 'output_folder'.

TYPE: dict

inner_rad

Inner radius in normalized units. Default is 0.

TYPE: float DEFAULT: 0

outer_rad

Outer radius in normalized units. Default is 1.

TYPE: float DEFAULT: 1

save

Whether to save the signal. Default is False.

TYPE: bool DEFAULT: False

offset_x

X-offset. Default is 0.

TYPE: float DEFAULT: 0

offset_y

Y-offset. Default is 0.

TYPE: float DEFAULT: 0

RETURNS DESCRIPTION
ndarray

2D detector signal array.

coordinate_transformation_2d

Map coordinates from XY space to UV space using polynomial coefficients.

PARAMETER DESCRIPTION
xy

Coordinates to transform. Shape (2, N) or (N, 2).

TYPE: array_like

ab

Transformation coefficients. Length 3 (linear), 6 (quadratic), or 10 (cubic).

TYPE: ndarray

RETURNS DESCRIPTION
ndarray

Transformed coordinates, shape (N, 2).

Notes

Original implementation by Wouter Van den Broek.

find_ab

Estimate polynomial coefficients for coordinate mapping.

PARAMETER DESCRIPTION
x

Source x-coordinates.

TYPE: array_like

y

Source y-coordinates.

TYPE: array_like

u

Target u-coordinates.

TYPE: array_like

v

Target v-coordinates.

TYPE: array_like

trafo_flag

Transformation order: 0=linear, 1=quadratic, 2=cubic. Default is 2.

TYPE: int DEFAULT: 2

RETURNS DESCRIPTION
ndarray

Transformation coefficients.

Notes

Original implementation by Wouter Van den Broek.

unwarp_im

Correct distortions and illumination in warped images.

PARAMETER DESCRIPTION
warp_im

Input image(s).

TYPE: array_like

ab

Transformation coefficients.

TYPE: ndarray

method

Interpolation method. Default is 'linear'.

TYPE: str DEFAULT: 'linear'

RETURNS DESCRIPTION
ndarray

Unwarped image(s).

Notes

Original implementation by Wouter Van den Broek.

coordinate_transformation_2d_areamag

Compute local area magnification of polynomial mapping.

PARAMETER DESCRIPTION
xy

Coordinates of shape (2, N) or (N, 2).

TYPE: array_like

ab

Transformation coefficients.

TYPE: ndarray

RETURNS DESCRIPTION
ndarray

Local magnification values.

Notes

Original implementation by Wouter Van den Broek.

fit_vector_field

Fit a smooth displacement field from calibration points.

PARAMETER DESCRIPTION
x

Nominal coordinates.

TYPE: array_like

y

Nominal coordinates.

TYPE: array_like

u

Observed coordinates.

TYPE: array_like

v

Observed coordinates.

TYPE: array_like

Xi

Grid coordinates for mapping.

TYPE: array_like

Yi

Grid coordinates for mapping.

TYPE: array_like

RETURNS DESCRIPTION
tuple of numpy.ndarray

Displacement fields (dV, dU).

warp_image

Warp image(s) based on a displacement field.

PARAMETER DESCRIPTION
image

Input image(s).

TYPE: array_like

vector_field

Displacement fields (U, V).

TYPE: tuple of numpy.ndarray

order

Interpolation order. Default is 1.

TYPE: int DEFAULT: 1

extra_angle_rotation_compensation

Rotation angle in degrees. Default is 0.

TYPE: float DEFAULT: 0

RETURNS DESCRIPTION
ndarray

Warped image(s).

compose_fields

Compose two displacement fields for use with warp_image.

Resulting field corresponds to: first apply field1, then field2.

PARAMETER DESCRIPTION
field1

First displacement field. Applied closest to the original image.

TYPE: (U1, V1)

field2

Second displacement field. Applied after field1.

TYPE: (U2, V2)

order

Interpolation order used to resample field1.

TYPE: int DEFAULT: 1

mode

Boundary mode for map_coordinates (e.g. 'nearest', 'constant').

TYPE: str DEFAULT: 'nearest'

RETURNS DESCRIPTION
U_tot, V_tot : np.ndarray

Composed displacement field such that: warp_image(warp_image(I, field1), field2) ≈ warp_image(I, (U_tot, V_tot))

warp_images_batch

Apply warping to a batch of images using precomputed indices.

PARAMETER DESCRIPTION
images

Batch of images.

TYPE: array_like

vector_field

Not used.

TYPE: ignored

batches

Batch indices.

TYPE: array_like

warped_rows

Flattened row and column indices.

TYPE: array_like

warped_cols

Flattened row and column indices.

TYPE: array_like

order

Interpolation order.

TYPE: int

RETURNS DESCRIPTION
ndarray

Warped images.

unwarp_4dstem_batch

Unwarp a 4D-STEM dataset in batches.

PARAMETER DESCRIPTION
data_old

Input dataset.

TYPE: str or ndarray

path_numpy_new

Path to save warped data.

TYPE: str DEFAULT: None

vector_field

Displacement fields.

TYPE: tuple of numpy.ndarray DEFAULT: None

batch_size

Frames per batch. Default is 20.

TYPE: int DEFAULT: 20

order

Interpolation order. Default is 5.

TYPE: int DEFAULT: 5

return_data

If True, return data instead of saving.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
ndarray or None

Warped dataset or None.

RAISES DESCRIPTION
ValueError

If total frames not divisible by batch_size.

remove_hot_pixels

Remove hot pixels from 4D-STEM data.

PARAMETER DESCRIPTION
data

Input dataset.

TYPE: ndarray

percentile

Threshold percentile. Default is 99.99.

TYPE: float DEFAULT: 99.99

RETURNS DESCRIPTION
ndarray

Corrected dataset.