This commit is contained in:
Joe Knapper 2026-05-11 13:50:38 +01:00 committed by jaknapper
parent 767e3992ff
commit 1f5adbb1a5
2 changed files with 17 additions and 6 deletions

View file

@ -286,10 +286,14 @@ class JPEGSharpnessMonitor:
self.record = method if record is None else record self.record = method if record is None else record
if not self.method & self.record: if not self.method & self.record:
raise ValueError(f"The sharpness metric `self.record` is not being recorded.") raise ValueError(
f"The sharpness metric {self.record} is not being recorded."
)
if self.record & SharpnessMethod.FOCUS_FOM and not camera.supports_focus_fom: if self.record & SharpnessMethod.FOCUS_FOM and not camera.supports_focus_fom:
raise ValueError("Cannot record focus FOM as this camera doesn't support it.") raise ValueError(
"Cannot record focus FOM as this camera doesn't support it."
)
LOGGER.debug(f"Created sharpness monitor with {stage}, {camera}") LOGGER.debug(f"Created sharpness monitor with {stage}, {camera}")
self._stage_positions: list[Mapping[str, int]] = [] self._stage_positions: list[Mapping[str, int]] = []
self._stage_times: list[float] = [] self._stage_times: list[float] = []
@ -320,7 +324,7 @@ class JPEGSharpnessMonitor:
@property @property
def jpeg_sizes(self) -> Sequence[int]: def jpeg_sizes(self) -> Sequence[int]:
"""The recorded JPEG frame sizes used as a sharpness metric. """The recorded JPEG frame sizes used as a sharpness metric.
:raises ValueError: If JPEG sharpness recording is not enabled. :raises ValueError: If JPEG sharpness recording is not enabled.
""" """
if not self.record & SharpnessMethod.JPEG: if not self.record & SharpnessMethod.JPEG:
@ -483,7 +487,7 @@ class AutofocusThing(lt.Thing):
dz: int = 2000, dz: int = 2000,
start: Literal["centre", "base"] = "centre", start: Literal["centre", "base"] = "centre",
sharpness_metric: SharpnessMethod = SharpnessMethod.JPEG, sharpness_metric: SharpnessMethod = SharpnessMethod.JPEG,
record: Optional[SharpnessMethod] = None record: Optional[SharpnessMethod] = None,
) -> SharpnessDataArrays: ) -> SharpnessDataArrays:
"""Sweep the stage up and down, then move to the sharpest point. """Sweep the stage up and down, then move to the sharpest point.
@ -504,7 +508,10 @@ class AutofocusThing(lt.Thing):
stage position data for the sweep. stage position data for the sweep.
""" """
with JPEGSharpnessMonitor( with JPEGSharpnessMonitor(
self._stage, self._cam, sharpness_metric, record=record, self._stage,
self._cam,
sharpness_metric,
record=record,
) as sharpness_monitor: ) as sharpness_monitor:
# Move to (-dz / 2) # Move to (-dz / 2)
if start == "centre": if start == "centre":
@ -578,7 +585,10 @@ class AutofocusThing(lt.Thing):
attempt = 0 attempt = 0
with JPEGSharpnessMonitor( with JPEGSharpnessMonitor(
self._stage, self._cam, sharpness_metric, record=record, self._stage,
self._cam,
sharpness_metric,
record=record,
) as sharpness_monitor: ) as sharpness_monitor:
while attempt < 10: while attempt < 10:
attempt += 1 attempt += 1

View file

@ -123,6 +123,7 @@ class StreamingPiCamera2(BaseCamera):
Currently the Thing only supports the PiCamera v2 board. This needs Currently the Thing only supports the PiCamera v2 board. This needs
generalisation. generalisation.
""" """
_focus_fom: int _focus_fom: int
supports_focus_fom: bool = True supports_focus_fom: bool = True
tuning: dict = lt.setting(default_factory=dict, readonly=True) tuning: dict = lt.setting(default_factory=dict, readonly=True)