Skip to content

Commit 93c5489

Browse files
a4894zAshish TripathiCopilotmdw771
authored
FEAT: allow using total probe intensity for COM in probe center constraint
Co-authored-by: Ashish Tripathi <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: MD <[email protected]>
1 parent 653023d commit 93c5489

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/ptychi/api/options/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,13 @@ class ProbeCenterConstraintOptions(FeatureOptions):
501501
enabled: bool = False
502502

503503
optimization_plan: OptimizationPlan = dataclasses.field(default_factory=OptimizationPlan)
504+
505+
use_intensity_for_com: bool = False
506+
"""
507+
Whether to use the magnitude of the dominant shared probe
508+
mode for computing the center of mass of the probe in order
509+
to keep it centered, or to use the total probe intensity.
510+
"""
504511

505512

506513
@dataclasses.dataclass

src/ptychi/data_structures/probe.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,13 @@ def center_probe(self):
394394
"""
395395
Move the probe's center of mass to the center of the probe array.
396396
"""
397-
com = ip.find_center_of_mass(self.get_mode_and_opr_mode(0, 0))
397+
398+
if self.options.center_constraint.use_intensity_for_com:
399+
probe_to_be_shifted = torch.sum(torch.abs(self.data[0, ...]) ** 2, dim=0)
400+
else:
401+
probe_to_be_shifted = self.get_mode_and_opr_mode(0, 0)
402+
403+
com = ip.find_center_of_mass(probe_to_be_shifted)
398404
shift = utils.to_tensor(self.shape[-2:]) // 2 - com
399405
shifted_probe = self.shift(shift)
400406
self.set_data(shifted_probe)

0 commit comments

Comments
 (0)