Merge branch 'sharpness-monitor-none' into 'v3'

Sharpness monitor accepting 0 as None

Closes #776

See merge request openflexure/openflexure-microscope-server!592
This commit is contained in:
Joe Knapper 2026-05-15 15:27:52 +00:00
commit bea1e35d61
2 changed files with 14 additions and 2 deletions

View file

@ -274,7 +274,7 @@ class JPEGSharpnessMonitor:
dependency as required by the underlying class. dependency as required by the underlying class.
:param method: The sharpness metric used when evaluating autofocus. :param method: The sharpness metric used when evaluating autofocus.
:param record: Bitmask of sharpness metrics to record while monitoring. :param record: Bitmask of sharpness metrics to record while monitoring.
If ``None``, only the metric specified by ``method`` is recorded. If ``None`` or 0, only the metric specified by ``method`` is recorded.
:raises ValueError: If ``method`` is not included in ``record``. :raises ValueError: If ``method`` is not included in ``record``.
:raises ValueError: If ``SharpnessMethod.FOCUS_FOM`` is requested but :raises ValueError: If ``SharpnessMethod.FOCUS_FOM`` is requested but
@ -283,7 +283,7 @@ class JPEGSharpnessMonitor:
self.camera = camera self.camera = camera
self.stage = stage self.stage = stage
self.method = method self.method = method
self.record = method if record is None else record self.record = record if record else method
if not self.method & self.record: if not self.method & self.record:
raise ValueError( raise ValueError(

View file

@ -130,6 +130,18 @@ def test_record_defaults_to_method(mock_stage, mock_camera):
assert monitor.record == SharpnessMethod.FOCUS_FOM assert monitor.record == SharpnessMethod.FOCUS_FOM
def test_zero_record_defaults_to_method(mock_stage, mock_camera):
"""If record=0, only the selected method is recorded."""
monitor = JPEGSharpnessMonitor(
mock_stage,
mock_camera,
method=SharpnessMethod.FOCUS_FOM,
record=0,
)
assert monitor.record == SharpnessMethod.FOCUS_FOM
def test_record_must_include_selected_method(mock_stage, mock_camera): def test_record_must_include_selected_method(mock_stage, mock_camera):
"""The selected autofocus metric must also be recorded.""" """The selected autofocus metric must also be recorded."""
with pytest.raises(ValueError, match="not being recorded"): with pytest.raises(ValueError, match="not being recorded"):