Skip to content

Conversation

@a4894z
Copy link
Collaborator

@a4894z a4894z commented Jun 10, 2025

Features/fixes

The default behavior is to use the 0th order shared probe mode to compute the center of mass (com); this adds the option of using the probe intensity as well.

Related issues (optional)

N/A

Mentions

Ming Du

Checklist

Have you...

  • Formatted your code properly adhering to PEP-8? Considering using RUFF to format your code automatically.
  • Resolved all merge conflicts with the main branch?
  • Checked the diffs between your branch and the main branch to ensure that your changes are not introducing any regressions or unnecessary/irrelevant changes?

@a4894z a4894z requested review from Copilot and mdw771 June 10, 2025 15:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a toggle to compute the probe’s center of mass using its intensity rather than always using the default (0th order shared) probe mode.

  • Introduces use_intensity_for_com option in ProbeCenterConstraintOptions.
  • Updates center_probe to branch on that option and compute intensity‐based COM when enabled.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/ptychi/api/options/base.py Added use_intensity_for_com flag with a docstring to ProbeCenterConstraintOptions.
src/ptychi/data_structures/probe.py Modified center_probe to optionally compute COM from probe intensity.
Comments suppressed due to low confidence (3)

src/ptychi/api/options/base.py:505

  • Clarify the docstring to state that enabling this flag computes COM from the probe’s squared‐magnitude intensity, and ensure the indentation matches surrounding fields.
use_intensity_for_com: bool = False

src/ptychi/data_structures/probe.py:398

  • Add a unit test for the intensity‐based centering branch to verify the COM shift is computed correctly when use_intensity_for_com is enabled.
if self.options.center_constraint.use_intensity_for_com:

src/ptychi/data_structures/probe.py:399

  • Computing intensity directly on self.data[0,...] bypasses any operator mode transformations applied by get_mode_and_opr_mode. Consider using get_mode_and_opr_mode(0, 0) inside the intensity calculation to stay consistent with the default COM computation.
probe_to_be_shifted = torch.sum( torch.abs( self.data[0,...] ) ** 2, 0 )

com = ip.find_center_of_mass(self.get_mode_and_opr_mode(0, 0))

if self.options.center_constraint.use_intensity_for_com:
probe_to_be_shifted = torch.sum( torch.abs( self.data[0,...] ) ** 2, 0 )
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove extra spaces inside the torch.sum and torch.abs calls to match project style (torch.sum(torch.abs(self.data[0,...])**2, dim=0)).

Suggested change
probe_to_be_shifted = torch.sum( torch.abs( self.data[0,...] ) ** 2, 0 )
probe_to_be_shifted = torch.sum(torch.abs(self.data[0,...]) ** 2, 0)

Copilot uses AI. Check for mistakes.
a4894z and others added 4 commits June 10, 2025 10:11
@mdw771 mdw771 merged commit 93c5489 into main Jun 10, 2025
0 of 2 checks passed
@a4894z a4894z deleted the use_probe_int_for_com_shift branch June 15, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants