diff --git a/src/openflexure_microscope_server/background_detect.py b/src/openflexure_microscope_server/background_detect.py index 7773eb93..4941054f 100644 --- a/src/openflexure_microscope_server/background_detect.py +++ b/src/openflexure_microscope_server/background_detect.py @@ -8,7 +8,7 @@ current camera field of view contains sample. from typing import Optional, Any import cv2 import numpy as np -from pydantic import BaseModel +from pydantic import BaseModel, Field, ConfigDict from pydantic.errors import PydanticUserError from scipy.stats import norm from labthings_fastapi.thing_description import type_to_dataschema @@ -153,13 +153,18 @@ class ChannelDistributions(BaseModel): class ColourChannelDetectSettings(BaseModel): """A BaseModel for storing the settings for colour channel detectors.""" + model_config = ConfigDict(extra="forbid") + channel_tolerance: float = 7.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 = 25.0 + + # Use Field to set Title reported to UI. By default Pydantic will convert the name + # from snake_case to Title Case. + min_sample_coverage: float = Field(25, title="Sample Coverage Required (%)") """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 fcccaae8..80f46b55 100644 --- a/src/openflexure_microscope_server/things/camera/__init__.py +++ b/src/openflexure_microscope_server/things/camera/__init__.py @@ -516,6 +516,20 @@ class BaseCamera(lt.Thing): """The status of the active detector for the UI.""" return self.active_detector.status + @lt.thing_action + def update_detector_settings(self, data) -> None: + """Update the settings of the current detector. + + This is an action not a setting/property as the data model depends on the + selected detector. As such, it cannot be specified with the necessary precision + to be included in a ThingDescription as a setting/property, while retaining + enough useful information to communicate to the UI how it is set and read. + + The information on how to read the settings is exposed in + ``background_detector_status``. + """ + self.active_detector.settings = data + @lt.thing_setting def background_detector_data(self) -> dict: """The data for each background detector, used to save to disk.""" diff --git a/webapp/src/components/labThingsComponents/inputFromSchema.vue b/webapp/src/components/labThingsComponents/inputFromSchema.vue index e1463507..32f78f63 100644 --- a/webapp/src/components/labThingsComponents/inputFromSchema.vue +++ b/webapp/src/components/labThingsComponents/inputFromSchema.vue @@ -51,20 +51,21 @@