Skip to content

Commit

Permalink
adding self_consistency_errors property. not implemented for 3D yet
Browse files Browse the repository at this point in the history
  • Loading branch information
gvarnavi committed Nov 1, 2023
1 parent fd59289 commit b67a064
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 1 deletion.
31 changes: 30 additions & 1 deletion py4DSTEM/process/phase/iterative_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,35 @@ def positions(self):

@property
def object_cropped(self):
"""cropped and rotated object"""
"""Cropped and rotated object"""

return self._crop_rotate_object_fov(self._object)

@property
def self_consistency_errors(self):
"""Compute the self-consistency errors for each probe position"""

xp = self._xp
asnumpy = self._asnumpy

# Re-initialize fractional positions and vector patches, max_batch_size = None
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()

# Overlaps
_, _, overlap = self._overlap_projection(self._object, self._probe)
fourier_overlap = xp.fft.fft2(overlap)

# Normalized mean-squared errors
error = xp.sum(
xp.abs(self._amplitudes - xp.abs(fourier_overlap)) ** 2, axis=(-2, -1)
)
error /= self._mean_diffraction_intensity

return asnumpy(error)
Original file line number Diff line number Diff line change
Expand Up @@ -3509,3 +3509,31 @@ def _return_object_fft(

obj = self._crop_rotate_object_fov(np.sum(obj, axis=0))
return np.abs(np.fft.fftshift(np.fft.fft2(np.fft.ifftshift(obj))))

@property
def self_consistency_errors(self):
"""Compute the self-consistency errors for each probe position"""

xp = self._xp
asnumpy = self._asnumpy

# Re-initialize fractional positions and vector patches, max_batch_size = None
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()

# 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
error = xp.sum(xp.abs(self._amplitudes - intensity_norm) ** 2, axis=(-2, -1))
error /= self._mean_diffraction_intensity

return asnumpy(error)
28 changes: 28 additions & 0 deletions py4DSTEM/process/phase/iterative_mixedstate_ptychography.py
Original file line number Diff line number Diff line change
Expand Up @@ -2327,3 +2327,31 @@ def show_fourier_probe(
chroma_boost=chroma_boost,
**kwargs,
)

@property
def self_consistency_errors(self):
"""Compute the self-consistency errors for each probe position"""

xp = self._xp
asnumpy = self._asnumpy

# Re-initialize fractional positions and vector patches, max_batch_size = None
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()

# 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
error = xp.sum(xp.abs(self._amplitudes - intensity_norm) ** 2, axis=(-2, -1))
error /= self._mean_diffraction_intensity

return asnumpy(error)
Original file line number Diff line number Diff line change
Expand Up @@ -3327,3 +3327,8 @@ def positions(self):
positions_all.append(asnumpy(positions))

return np.asarray(positions_all)

@property
def self_consistency_errors(self):
"""Compute the self-consistency errors for each probe position"""
raise NotImplementedError()
5 changes: 5 additions & 0 deletions py4DSTEM/process/phase/iterative_overlap_tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -3207,3 +3207,8 @@ def positions(self):
positions_all.append(asnumpy(positions))

return np.asarray(positions_all)

@property
def self_consistency_errors(self):
"""Compute the self-consistency errors for each probe position"""
raise NotImplementedError()
29 changes: 29 additions & 0 deletions py4DSTEM/process/phase/iterative_simultaneous_ptychography.py
Original file line number Diff line number Diff line change
Expand Up @@ -3357,3 +3357,32 @@ def visualize(
)

return self

@property
def self_consistency_errors(self):
"""Compute the self-consistency errors for each probe position"""

xp = self._xp
asnumpy = self._asnumpy

# Re-initialize fractional positions and vector patches, max_batch_size = None
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()

# Overlaps
_, _, overlap = self._warmup_overlap_projection(self._object, self._probe)
fourier_overlap = xp.fft.fft2(overlap[0])

# Normalized mean-squared errors
error = xp.sum(
xp.abs(self._amplitudes[0] - xp.abs(fourier_overlap)) ** 2, axis=(-2, -1)
)
error /= self._mean_diffraction_intensity

return asnumpy(error)

0 comments on commit b67a064

Please sign in to comment.