Skip to content

Conversation

talonchandler
Copy link
Collaborator

Fixes #470.

Enables sub-pixel precision for focus detection and z_focus_offset values, improving 2D phase reconstructions for coarsely sampled data.

Changes:

  • Settings: z_focus_offset now accepts float values (previously int only)
  • Focus detection: Added optional sub-pixel precision to focus_from_transverse_band()
    • New parameter: enable_subpixel_precision: bool = False
    • Uses a polynomial fit to find a continuous maximum
    • Returns float indices when enabled, maintains integer behavior by default
  • Backwards compatible. Default behavior return integers to continue to support mantis and other applications.

Old usage (unchanged):

focus_slice = focus_from_transverse_band(data, NA_det, lambda_ill, pixel_size)

New usage:

focus_slice = focus_from_transverse_band(
    data, NA_det, lambda_ill, pixel_size,
    polynomial_fit_order=2,
    enable_subpixel_precision=True
)  # Returns float like 5.3 instead of 5

Config files now support float offsets:

transfer_function:
  z_focus_offset: 0.5  # Previously only integers

talonchandler and others added 5 commits August 27, 2025 11:41
- Change z_focus_offset type from Union[int, Literal["auto"]] to Union[float, Literal["auto"]]
- This enables sub-pixel precision for focus offset values in 2D phase reconstruction
- Addresses issue #470 for coarsely sampled slice improvements

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add enable_subpixel_precision parameter (default False for backward compatibility)
- Use polynomial derivative analysis to find continuous extrema when enabled
- Return float focus indices when sub-pixel precision is enabled
- Update plotting function to handle float indices via interpolation
- Enhance docstring with new parameter and return type information

This enables more accurate focus detection for coarsely sampled data
by finding focus positions between discrete slice indices.

Addresses issue #470.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- test_subpixel_precision: Validates float focus detection with synthetic data
- test_subpixel_precision_backward_compatibility: Ensures default behavior unchanged
- test_subpixel_precision_with_plotting: Tests plotting with float indices
- test_z_focus_offset_float_type: Validates settings accept float z_focus_offset
- test_position_list_with_float_offset: Tests position calculation pipeline

All tests verify both functionality and backward compatibility.
Ensures robust implementation of issue #470 requirements.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@gav-sturm
Copy link
Collaborator

@talonchandler one thing that might help in the documentation is selecting a reasonable polynomial fit order if subpixel_precission is set to True. I saw in your tests that 4 is a good default?

@talonchandler
Copy link
Collaborator Author

@talonchandler one thing that might help in the documentation is selecting a reasonable polynomial fit order if subpixel_precission is set to True. I saw in your tests that 4 is a good default?

Good suggestion. @gav-sturm, for your use case I suggest starting with order=2, then increasing to 3 or 4 if you're unhappy with the fits you're seeing in the plots. If this suggestion works well, I'll add it to the docstring.

@talonchandler talonchandler changed the base branch from refactor-midband-loss to main September 3, 2025 00:04
@codecov
Copy link

codecov bot commented Sep 3, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.11%. Comparing base (bf46c27) to head (855a68b).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
waveorder/focus.py 91.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #473      +/-   ##
==========================================
+ Coverage   36.55%   38.11%   +1.56%     
==========================================
  Files          49       49              
  Lines       10186     9791     -395     
==========================================
+ Hits         3723     3732       +9     
+ Misses       6463     6059     -404     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

z_focus_offset and focus_from_transverse_band do not support non-integer values

2 participants