Apply suggestions from code review of branch camera_modes

Co-authored-by: Joe Knapper <joe.knapper@glasgow.ac.uk>
This commit is contained in:
Julian Stirling 2026-06-05 15:53:04 +00:00
parent bc7204f554
commit 071d62e8a0
11 changed files with 28 additions and 28 deletions

View file

@ -68,9 +68,9 @@ class OFMThing(lt.Thing):
"""Create a ``RelativeDataPath`` object with this Thing set as the saving Thing.
:param path: The relative path within the data directory of this Thing's data
dir that the data shudl be saved.
dir that the data should be saved to.
:param absolute: Set to True if the current path is absolute. A relative path
will be returned. An validation error will be raised if the absolute path
will be returned. A validation error will be raised if the absolute path
is not within the data directory.
:return: A ``RelativeDataPath`` object with the saving Thing already set.

View file

@ -230,8 +230,10 @@ class BaseCamera(OFMThing, ABC):
# would be ideal.
self._default_background_detector = "bg_channel_deviations_luv"
self._background_detector_name: Optional[str] = None
self._framerate_monitor_running = False
if "default" and "full_resolution" not in self.streaming_modes:
required_modes = ("default", "full_resolution")
if not all(mode in self.streaming_modes for mode in required_modes):
raise KeyError(
f"Camera {type(self).__name__} doesn't define both a 'default' and a "
"'full_resolution' streaming mode."
@ -559,7 +561,7 @@ class BaseCamera(OFMThing, ABC):
def capture_downsampled_array(self) -> NDArray:
"""Acquire one image from the camera, downsample, and return as an array.
* The array is downsamples by the thing property `downsampled_array_factor`.
* The array is downsampled by the thing property `downsampled_array_factor`.
* The default capture array arguments are used.
This method provides the interface expected by the camera_stage_mapping.
@ -718,7 +720,7 @@ class BaseCamera(OFMThing, ABC):
"""Capture a PIL image from the camera.
This unlike the ``grab_*`` methods this may pause the stream or temporarily
switch streaming mode to capute the image if required by the mode.
switch streaming mode to capture the image if required by the mode.
"""
@lt.action

View file

@ -149,7 +149,7 @@ class OpenCVCamera(BaseCamera):
raise NotImplementedError(
"OpenCV camera camera doesn't support raw capture."
)
# Warn if the capture mode is incorrect, but don't read the cooerced value as
# Warn if the capture mode is incorrect, but don't read the coerced value as
# this camera only supports one mode.
self._validate_capture_mode(capture_mode)
ret, frame = self.cap.read()
@ -159,7 +159,7 @@ class OpenCVCamera(BaseCamera):
def _capture_image(self, capture_mode: str = "standard") -> Image.Image:
"""Acquire one image from the camera and return as a PIL image."""
# Warn if the capture mode is incorrect, but don't read the cooerced value as
# Warn if the capture mode is incorrect, but don't read the coerced value as
# this camera only supports one mode.
self._validate_capture_mode(capture_mode)
return Image.fromarray(self.capture_as_array())

View file

@ -536,8 +536,8 @@ class StreamingPiCamera2(BaseCamera, ABC):
If the camera is already in the correct mode, the stream isn't paused and
this is the same as using ``self._streaming_picamera()``.
Otherwise, pause stream, and switch switch mode. Mode is reset and stream
restarts stream after the context manager closes.
Otherwise, pause stream, and switch mode. Mode is reset and stream
restarts after the context manager closes.
"""
required_streaming_mode = capture_mode_info.streaming_mode
if (
@ -568,7 +568,7 @@ class StreamingPiCamera2(BaseCamera, ABC):
"""Acquire one image from the camera and return it as a PIL Image.
:param capture_mode: The capture mode to use. See the description field of each
mode for more detail in ``capture_modes`` for more detail.
mode in ``capture_modes`` for more detail.
:raises TimeoutError: if this time is exceeded during capture.
"""
@ -594,13 +594,13 @@ class StreamingPiCamera2(BaseCamera, ABC):
:param capture_mode: (Optional) The name of the capture mode as defined by the
camera.
:param raw: Whether to capture RAW data. Capturing RAW data may infore some
:param raw: Whether to capture RAW data. Capturing RAW data may ignore some
of the camera mode settings.
:raises TimeoutError: if this time is exceeded during capture.
"""
if raw:
# Raw cannot used _capture_image.
# Raw cannot use _capture_image.
capture_mode = self._validate_capture_mode(capture_mode)
capture_mode_info = self.capture_modes[capture_mode]

View file

@ -496,10 +496,8 @@ class SimulatedCamera(BaseCamera):
Setting this to True will result in an error.
"""
if raw is True:
raise NotImplementedError(
"Simulation camera camera doesn't support raw capture."
)
# Warn if the capture mode is incorrect, but don't read the cooerced value as
raise NotImplementedError("Simulation camera doesn't support raw capture.")
# Warn if the capture mode is incorrect, but don't read the coerced value as
# this camera only supports one mode.
self._validate_capture_mode(capture_mode)
return np.array(self.generate_frame())
@ -509,7 +507,7 @@ class SimulatedCamera(BaseCamera):
It is used for capture to memory.
"""
# Warn if the capture mode is incorrect, but don't read the cooerced value as
# Warn if the capture mode is incorrect, but don't read the coerced value as
# this camera only supports one mode.
self._validate_capture_mode(capture_mode)
return self.generate_frame()

View file

@ -129,7 +129,7 @@ class ScanWorkflow(Generic[SettingModelType], lt.Thing):
"""Return the save resolution as determined by a test image."""
# Capture an example image.
image = self._cam._capture_image(capture_mode=self.capture_mode)
# Check side to create a unit faction for downsampling.
# Check size to create a unit faction for downsampling.
return image.size
def pre_scan_routine(self, settings: SettingModelType) -> None: