From 06f12973f4f0791812c986c7d299209f6aaed7c4 Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Mon, 2 Mar 2026 19:40:44 +0000 Subject: [PATCH 1/5] Add limits to background detect and settling time settings --- .../things/background_detect.py | 8 ++++---- .../things/camera/__init__.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/openflexure_microscope_server/things/background_detect.py b/src/openflexure_microscope_server/things/background_detect.py index 19ab6874..8039605f 100644 --- a/src/openflexure_microscope_server/things/background_detect.py +++ b/src/openflexure_microscope_server/things/background_detect.py @@ -99,14 +99,14 @@ class ColourChannelDetectLUV(BackgroundDetectAlgorithm): # provided there. min_stds = [0.5, 0.3, 0.5] - channel_tolerance: float = lt.setting(default=7.0) + channel_tolerance: float = lt.setting(default=7.0, ge=0) """Channel Tolerance The number of standard deviations a pixel value must be from the background mean to be considered sample. """ - min_sample_coverage: float = lt.setting(default=25) + min_sample_coverage: float = lt.setting(default=25, ge=0, le=100) """Sample Coverage Required (%) The minimum percentage of the image that needs to be identified as sample for the @@ -223,14 +223,14 @@ class ChannelDeviationLUV(BackgroundDetectAlgorithm): # LUV colour space not converting to the CIELUV numbers) min_stds = [0.5, 0.3, 0.5] - channel_tolerance: float = lt.setting(default=7.0) + channel_tolerance: float = lt.setting(default=7.0, ge=0) """Channel Tolerance The number of standard deviations a pixel value must be from the background mean to be considered sample. """ - min_sample_coverage: float = lt.setting(default=25) + min_sample_coverage: float = lt.setting(default=25, ge=0, le=100) """Sample Coverage Required (%) The minimum percentage of the image that needs to be identified as sample for the diff --git a/src/openflexure_microscope_server/things/camera/__init__.py b/src/openflexure_microscope_server/things/camera/__init__.py index dd4f6cdd..14088f21 100644 --- a/src/openflexure_microscope_server/things/camera/__init__.py +++ b/src/openflexure_microscope_server/things/camera/__init__.py @@ -565,7 +565,7 @@ class BaseCamera(lt.Thing): except Exception as e: raise IOError(f"An error occurred while saving {jpeg_path}") from e - settling_time: float = lt.setting(default=0.2) + settling_time: float = lt.setting(default=0.2, ge=0) """The settling time when calling the ``settle()`` method.""" @lt.action From 99b9b0f3d65834b6d0dea3dd5bea1c82713818a5 Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Mon, 2 Mar 2026 19:55:21 +0000 Subject: [PATCH 2/5] Add limits to noise level, sample density and downsample --- src/openflexure_microscope_server/things/camera/__init__.py | 2 +- src/openflexure_microscope_server/things/camera/simulation.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/openflexure_microscope_server/things/camera/__init__.py b/src/openflexure_microscope_server/things/camera/__init__.py index 14088f21..6b9bc323 100644 --- a/src/openflexure_microscope_server/things/camera/__init__.py +++ b/src/openflexure_microscope_server/things/camera/__init__.py @@ -274,7 +274,7 @@ class BaseCamera(lt.Thing): "CameraThings must define their own capture_array method" ) - downsampled_array_factor: int = lt.property(default=2) + downsampled_array_factor: int = lt.property(default=2, ge=1) """The downsampling factor when calling capture_downsampled_array.""" @lt.action diff --git a/src/openflexure_microscope_server/things/camera/simulation.py b/src/openflexure_microscope_server/things/camera/simulation.py index 31e3979e..5db72b8b 100644 --- a/src/openflexure_microscope_server/things/camera/simulation.py +++ b/src/openflexure_microscope_server/things/camera/simulation.py @@ -172,6 +172,8 @@ class SimulatedCamera(BaseCamera): @blob_density.setter def _set_blob_density(self, value: int) -> None: + if value < 0: + self.logger.warning("Sample density must be >= 0") self._blob_density = value if self._capture_enabled: self.generate_canvas() @@ -457,7 +459,7 @@ class SimulatedCamera(BaseCamera): return self._capture_thread.is_alive() return False - noise_level: float = lt.property(default=2.0) + noise_level: float = lt.property(default=2.0, ge=0) def _capture_frames(self) -> None: last_frame_t = time.time() From c9cc4e84682c4d67bab1bc02d4d45e149f8ad4ae Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Mon, 2 Mar 2026 20:35:25 +0000 Subject: [PATCH 3/5] Apply suggestions from code review of branch check-setting-validation Co-authored-by: Julian Stirling --- src/openflexure_microscope_server/things/camera/simulation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openflexure_microscope_server/things/camera/simulation.py b/src/openflexure_microscope_server/things/camera/simulation.py index 5db72b8b..c8ad6f26 100644 --- a/src/openflexure_microscope_server/things/camera/simulation.py +++ b/src/openflexure_microscope_server/things/camera/simulation.py @@ -174,6 +174,7 @@ class SimulatedCamera(BaseCamera): def _set_blob_density(self, value: int) -> None: if value < 0: self.logger.warning("Sample density must be >= 0") + return self._blob_density = value if self._capture_enabled: self.generate_canvas() @@ -459,7 +460,7 @@ class SimulatedCamera(BaseCamera): return self._capture_thread.is_alive() return False - noise_level: float = lt.property(default=2.0, ge=0) + noise_level: float = lt.property(default=2.0, ge=0, le=50) def _capture_frames(self) -> None: last_frame_t = time.time() From 25c733a0c34e15e5d864bddf949a2dd2c8f1523c Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Wed, 4 Mar 2026 17:28:20 +0000 Subject: [PATCH 4/5] Apply suggestions from code review of branch check-setting-validation Co-authored-by: Julian Stirling --- src/openflexure_microscope_server/things/camera/simulation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/openflexure_microscope_server/things/camera/simulation.py b/src/openflexure_microscope_server/things/camera/simulation.py index c8ad6f26..d75c36e5 100644 --- a/src/openflexure_microscope_server/things/camera/simulation.py +++ b/src/openflexure_microscope_server/things/camera/simulation.py @@ -173,8 +173,7 @@ class SimulatedCamera(BaseCamera): @blob_density.setter def _set_blob_density(self, value: int) -> None: if value < 0: - self.logger.warning("Sample density must be >= 0") - return + raise ValueError("Sample density must be >= 0") self._blob_density = value if self._capture_enabled: self.generate_canvas() From e1a8b9907eb624281f970179734427d90392adaf Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Sat, 7 Mar 2026 20:15:06 +0000 Subject: [PATCH 5/5] Update picamera tests --- picamera_coverage.zip | Bin 54038 -> 54038 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/picamera_coverage.zip b/picamera_coverage.zip index 4a6c18565efa1d51a3ede16982b80d3e405a658b..09438bb3cc01239acf74a6c89d403e793896500e 100644 GIT binary patch delta 103 zcmbQXjCtBJX5IjAW)=|!5XhgDzL8h=0!RL&^q5b7c%Dplx{#)BmSmZfY;0s~Y-DDb yW|U->mTHt@k(gv?Zf0SbmXexcWNv0)nw+-z{Dp0d%=wejCwE-3MVN5*k|zM+izWF0 delta 103 zcmbQXjCtBJX5IjAW)=|!5D?ptvXNK!0*Ba!lo-EzKPo0WT}V?;Nij(?OHN5Ku}HKq yGP6uJFf&Rru}m?wG%`*ywy;PxHMB5KN=)8-{=zm!X0Z(^lRGZiB1|}Y$rAvb_#{;T