From ba86c3729222182a858ff35ce05c1b244b5bff23 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Thu, 11 Jan 2024 02:48:38 +0000 Subject: [PATCH] Swap background detection from argument to property For consistency, I've made background detection a property. --- .../things/smart_scan.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 25a950d0..898fbebd 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -362,7 +362,6 @@ class SmartScanThing(Thing): csm: CSMDep, background_detect: BackgroundDep, recentre: RecentreStage, - sample_check ): """Move the stage to cover an area, taking images that can be tiled together. @@ -381,7 +380,7 @@ class SmartScanThing(Thing): # It's annoying to have to wait to find out! max_dist = self.max_range - if sample_check: + if self.skip_background: d = background_detect.background_distributions if not d: raise RuntimeError("Background is not set: you need to calibrate background detection.") @@ -464,7 +463,7 @@ class SmartScanThing(Thing): ) # Check if the image is background - if sample_check: + if self.skip_background: image_is_sample = background_detect.image_is_sample() else: image_is_sample = True @@ -610,6 +609,18 @@ class SmartScanThing(Thing): def max_range(self, value: int) -> None: self.thing_settings["max_range"] = value + @thing_property + def skip_background(self) -> bool: + """Whether to detect and skip empty fields of view + + This uses the settings from the `background_detect` Thing. + """ + return self.thing_settings.get("skip_background", True) + + @skip_background.setter + def skip_background(self, value: bool) -> None: + self.thing_settings["skip_background"] = value + @thing_property def autofocus_dz(self) -> int: """The z distance to perform an autofocus"""