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:
|
save
|
Whether to save the image. Default is True.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
haadf
|
HAADF intensities array.
TYPE:
|
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:
|
| RETURNS | DESCRIPTION |
|---|---|
params
|
Updated dict including 'aperture_mask'.
TYPE:
|
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:
|
path_new
|
Path to save the binned dataset.
TYPE:
|
bin
|
Binning factor.
TYPE:
|
| 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:
|
patterns
|
4D diffraction patterns.
TYPE:
|
| 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:
|
inner_rad
|
Inner radius in normalized units. Default is 0.
TYPE:
|
outer_rad
|
Outer radius in normalized units. Default is 1.
TYPE:
|
save
|
Whether to save the signal. Default is False.
TYPE:
|
offset_x
|
X-offset. Default is 0.
TYPE:
|
offset_y
|
Y-offset. Default is 0.
TYPE:
|
| 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:
|
ab
|
Transformation coefficients. Length 3 (linear), 6 (quadratic), or 10 (cubic).
TYPE:
|
| 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:
|
y
|
Source y-coordinates.
TYPE:
|
u
|
Target u-coordinates.
TYPE:
|
v
|
Target v-coordinates.
TYPE:
|
trafo_flag
|
Transformation order: 0=linear, 1=quadratic, 2=cubic. Default is 2.
TYPE:
|
| 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:
|
ab
|
Transformation coefficients.
TYPE:
|
method
|
Interpolation method. Default is 'linear'.
TYPE:
|
| 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:
|
ab
|
Transformation coefficients.
TYPE:
|
| 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:
|
y
|
Nominal coordinates.
TYPE:
|
u
|
Observed coordinates.
TYPE:
|
v
|
Observed coordinates.
TYPE:
|
Xi
|
Grid coordinates for mapping.
TYPE:
|
Yi
|
Grid coordinates for mapping.
TYPE:
|
| 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:
|
vector_field
|
Displacement fields (U, V).
TYPE:
|
order
|
Interpolation order. Default is 1.
TYPE:
|
extra_angle_rotation_compensation
|
Rotation angle in degrees. Default is 0.
TYPE:
|
| 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:
|
field2
|
Second displacement field. Applied after field1.
TYPE:
|
order
|
Interpolation order used to resample field1.
TYPE:
|
mode
|
Boundary mode for map_coordinates (e.g. 'nearest', 'constant').
TYPE:
|
| 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:
|
vector_field
|
Not used.
TYPE:
|
batches
|
Batch indices.
TYPE:
|
warped_rows
|
Flattened row and column indices.
TYPE:
|
warped_cols
|
Flattened row and column indices.
TYPE:
|
order
|
Interpolation order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Warped images. |
unwarp_4dstem_batch
¶
Unwarp a 4D-STEM dataset in batches.
| PARAMETER | DESCRIPTION |
|---|---|
data_old
|
Input dataset.
TYPE:
|
path_numpy_new
|
Path to save warped data.
TYPE:
|
vector_field
|
Displacement fields.
TYPE:
|
batch_size
|
Frames per batch. Default is 20.
TYPE:
|
order
|
Interpolation order. Default is 5.
TYPE:
|
return_data
|
If True, return data instead of saving.
TYPE:
|
| 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:
|
percentile
|
Threshold percentile. Default is 99.99.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Corrected dataset. |