From 8f30f08bdfe119dbb3f8eb0c448ac342357ec90d Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Fri, 6 Feb 2026 13:28:30 +0000 Subject: [PATCH] Apply suggestions from code review of branch scan-workflows Co-authored-by: Joe Knapper --- src/openflexure_microscope_server/scan_directories.py | 5 ++--- .../things/scan_workflows.py | 10 +++++----- src/openflexure_microscope_server/things/smart_scan.py | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/openflexure_microscope_server/scan_directories.py b/src/openflexure_microscope_server/scan_directories.py index a31d24ce..a5ddb6fe 100644 --- a/src/openflexure_microscope_server/scan_directories.py +++ b/src/openflexure_microscope_server/scan_directories.py @@ -189,15 +189,14 @@ class HistoricScanData(BaseScanData): @model_validator(mode="before") @classmethod def coerce_legacy(cls, data: dict) -> dict: - """Coerce any legacy data.""" - r"""Coerce any scan data from before version 2 into the version 2 format.""" + """Coerce any scan data from before version 2 into the version 2 format.""" # Before the current version no schema_version was set if "schema_version" in data: return data if "correlation_resize" and "overlap" in data: correlation_resize = data.pop("correlation_resize") - # Note we don't pop overlap is a setting for the legacy workflow as well + # Note we don't pop overlap, as it is a setting for the legacy workflow as well # as a stitching setting. # This is done because in future workflows the stitching overlap may be a # directly set setting or something that is calculated from other settings. diff --git a/src/openflexure_microscope_server/things/scan_workflows.py b/src/openflexure_microscope_server/things/scan_workflows.py index fd072bcc..dc6a30a0 100644 --- a/src/openflexure_microscope_server/things/scan_workflows.py +++ b/src/openflexure_microscope_server/things/scan_workflows.py @@ -195,8 +195,8 @@ class HistoScanWorkflow(ScanWorkflow[HistoScanSettingsModel]): """The minimum number of images to capture in a stack. This many images are captures and tested for focus, if the focus is not central - enough more images may be captured. After new images are captured the number sets - the number of images used for checking if focus is central. + enough more images may be captured. After new images are captured, this value sets + the number of images used for checking if focus is achieved. Defaults to 9 which balances reliability and speed. """ @@ -286,7 +286,7 @@ class HistoScanWorkflow(ScanWorkflow[HistoScanSettingsModel]): return scan_settings, stitching_settings def _calc_displacement_from_overlap(self, overlap: float) -> tuple[int, int]: - """Take a test image and use camera stage mapping to calculate x and y displacement. + """Use camera stage mapping to calculate x and y displacement. :param overlap: The desired overlap as a fraction of the image. i.e. 0.5 means that each image should overlap its nearest neighbour by 50%. @@ -295,7 +295,7 @@ class HistoScanWorkflow(ScanWorkflow[HistoScanSettingsModel]): """ csm_image_res = self._csm.image_resolution if csm_image_res is None: - raise RuntimeError("CSM not set. Scan shouldn't have progresses this far.") + raise RuntimeError("CSM not set. Scan shouldn't have progressed this far.") # Calculate displacements in image coordinates dx_img = csm_image_res[1] * (1 - overlap) @@ -448,7 +448,7 @@ class HistoScanWorkflow(ScanWorkflow[HistoScanSettingsModel]): imaged = focused or save_on_failure if not imaged: - msg = f"Stack failed at {xyz_pos} treating as background." + msg = f"Stack failed at {xyz_pos}. Treating as background." self.logger.info(msg) # run_smart_stage always returns a focus height for the sharpest image even diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 0ef550b3..3f8b36e0 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -43,7 +43,7 @@ T = TypeVar("T") P = ParamSpec("P") -# This allows ActiveScanData to hold arbitrary workflow settings models during a scan. +# This allows ActiveScanData to hold arbitrary workflow settings models during a scan. AnyModel = Annotated[ BaseModel, PlainSerializer(lambda value: value.model_dump(), return_type=dict), @@ -233,7 +233,7 @@ class SmartScanThing(lt.Thing): def sample_scan(self, scan_name: str = "") -> None: """Move the stage to cover an area, taking images. - Depending on the way the stage moves depends on the selected workflow. + The way the stage moves depends on the selected workflow. If images overlap for a scan workflow then the images can be stitched together into a larger composite image. """