Skip to content

Commit

Permalink
oops, forgot to delete duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
gvarnavi committed Jan 2, 2024
1 parent 3820516 commit 2d1d4e4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1943,50 +1943,3 @@ def visualize(
**kwargs,
)
return self

def _return_self_consistency_errors(
self,
max_batch_size=None,
):
"""Compute the self-consistency errors for each probe position"""

xp = self._xp
asnumpy = self._asnumpy

# Batch-size
if max_batch_size is None:
max_batch_size = self._num_diffraction_patterns

# Re-initialize fractional positions and vector patches
errors = np.array([])
positions_px = self._positions_px.copy()

for start, end in generate_batches(
self._num_diffraction_patterns, max_batch=max_batch_size
):
# batch indices
self._positions_px = positions_px[start:end]
self._positions_px_fractional = self._positions_px - xp.round(
self._positions_px
)
(
self._vectorized_patch_indices_row,
self._vectorized_patch_indices_col,
) = self._extract_vectorized_patch_indices()
amplitudes = self._amplitudes[start:end]

# Overlaps
_, _, overlap = self._overlap_projection(self._object, self._probe)
fourier_overlap = xp.fft.fft2(overlap)
intensity_norm = xp.sqrt(xp.sum(xp.abs(fourier_overlap) ** 2, axis=1))

# Normalized mean-squared errors
batch_errors = xp.sum(
xp.abs(amplitudes - intensity_norm) ** 2, axis=(-2, -1)
)
errors = np.hstack((errors, batch_errors))

self._positions_px = positions_px.copy()
errors /= self._mean_diffraction_intensity

return asnumpy(errors)
47 changes: 0 additions & 47 deletions py4DSTEM/process/phase/iterative_mixedstate_ptychography.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,50 +1606,3 @@ def visualize(
)

return self

def _return_self_consistency_errors(
self,
max_batch_size=None,
):
"""Compute the self-consistency errors for each probe position"""

xp = self._xp
asnumpy = self._asnumpy

# Batch-size
if max_batch_size is None:
max_batch_size = self._num_diffraction_patterns

# Re-initialize fractional positions and vector patches
errors = np.array([])
positions_px = self._positions_px.copy()

for start, end in generate_batches(
self._num_diffraction_patterns, max_batch=max_batch_size
):
# batch indices
self._positions_px = positions_px[start:end]
self._positions_px_fractional = self._positions_px - xp.round(
self._positions_px
)
(
self._vectorized_patch_indices_row,
self._vectorized_patch_indices_col,
) = self._extract_vectorized_patch_indices()
amplitudes = self._amplitudes[start:end]

# Overlaps
_, _, overlap = self._overlap_projection(self._object, self._probe)
fourier_overlap = xp.fft.fft2(overlap)
intensity_norm = xp.sqrt(xp.sum(xp.abs(fourier_overlap) ** 2, axis=1))

# Normalized mean-squared errors
batch_errors = xp.sum(
xp.abs(amplitudes - intensity_norm) ** 2, axis=(-2, -1)
)
errors = np.hstack((errors, batch_errors))

self._positions_px = positions_px.copy()
errors /= self._mean_diffraction_intensity

return asnumpy(errors)

0 comments on commit 2d1d4e4

Please sign in to comment.