Skip to content

Commit

Permalink
switch to centered alignment bins by default
Browse files Browse the repository at this point in the history
  • Loading branch information
gvarnavi committed Jul 18, 2024
1 parent d995f66 commit 7c2eb04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 4 additions & 1 deletion py4DSTEM/process/phase/parallax.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ def reconstruct(
min_alignment_bin: int = 1,
num_iter_at_min_bin: int = 2,
alignment_bin_values: list = None,
centered_alignment_bins: bool = True,
cross_correlation_upsample_factor: int = 8,
regularizer_matrix_size: Tuple[int, int] = (1, 1),
regularize_shifts: bool = False,
Expand Down Expand Up @@ -879,6 +880,8 @@ def reconstruct(
(bin_vals, np.repeat(bin_vals[-1], num_iter_at_min_bin - 1))
)

bin_shift = 0 if centered_alignment_bins else 0.5

if plot_aligned_bf:
num_plots = bin_vals.shape[0]
nrows = int(np.sqrt(num_plots))
Expand Down Expand Up @@ -913,7 +916,7 @@ def reconstruct(
G_ref = xp.fft.fft2(self._recon_BF)

# Segment the virtual images with current binning values
xy_inds = xp.round(xy_center / bin_vals[a0] + 0.5).astype("int")
xy_inds = xp.round(xy_center / bin_vals[a0] + bin_shift).astype("int")
xy_vals = np.unique(
asnumpy(xy_inds), axis=0
) # axis is not yet supported in cupy
Expand Down
16 changes: 9 additions & 7 deletions py4DSTEM/process/phase/parameter_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,15 @@ def _split_static_and_optimization_vars(self, argdict):
return static_args, optimization_args

def _get_scan_positions(self, affine_transform, dataset):
R_pixel_size = dataset.calibration.get_R_pixel_size()
x, y = (
np.arange(dataset.R_Nx) * R_pixel_size,
np.arange(dataset.R_Ny) * R_pixel_size,
)
x, y = np.meshgrid(x, y, indexing="ij")
scan_positions = np.stack((x.ravel(), y.ravel()), axis=1)
scan_positions = self._init_static_args.pop("initial_scan_positions",None)
if scan_positions is None:
R_pixel_size = dataset.calibration.get_R_pixel_size()
x, y = (
np.arange(dataset.R_Nx) * R_pixel_size,
np.arange(dataset.R_Ny) * R_pixel_size,
)
x, y = np.meshgrid(x, y, indexing="ij")
scan_positions = np.stack((x.ravel(), y.ravel()), axis=1)
scan_positions = scan_positions @ affine_transform.asarray()
return scan_positions

Expand Down

0 comments on commit 7c2eb04

Please sign in to comment.