diff --git a/src/openflexure_microscope_server/things/scan_workflows.py b/src/openflexure_microscope_server/things/scan_workflows.py index 9bc61846..9fc132c5 100644 --- a/src/openflexure_microscope_server/things/scan_workflows.py +++ b/src/openflexure_microscope_server/things/scan_workflows.py @@ -370,6 +370,11 @@ class HistoScanWorkflow(RectGridWorkflow[HistoScanSettingsModel]): * 200 for 20x """ + equal_distances: bool = lt.setting(default=False) + """Make the distances in x and y equal in motor steps, rather than in overlap. + + Uses the shorter distance (usually dy) as both dx and dy""" + # The noqa statement is because scan_name is unused but is needed for equivalence # with other workflows that may want to validate the scan name. def check_before_start(self, scan_name: str) -> None: # noqa: ARG002 @@ -408,7 +413,22 @@ class HistoScanWorkflow(RectGridWorkflow[HistoScanSettingsModel]): return self._background_detector.ready def _build_scan_settings(self, base_kwargs: dict) -> HistoScanSettingsModel: - """Construct the SettingModel for all_settings.""" + """Construct the SettingModel for all_settings. + + Adjust dx and dy to be equal if `equal_distances` is set. + """ + # Make dx and dy equal if requested + if self.equal_distances: + dx = abs(base_kwargs.get("dx", 0)) + dy = abs(base_kwargs.get("dy", 0)) + min_displacement = min(dx, dy) + base_kwargs["dx"] = min_displacement + base_kwargs["dy"] = min_displacement + + self.logger.info( + f"Scanning with steps of dx={base_kwargs['dx']} and dy={base_kwargs['dy']}." + ) + return HistoScanSettingsModel( **base_kwargs, max_dist=self.max_range, @@ -576,7 +596,10 @@ class HistoScanWorkflow(RectGridWorkflow[HistoScanSettingsModel]): self, "max_range", label="Maximum Distance (steps)", step=1000 ), property_control_for( - self, "skip_background", label="Detect and Skip Empty Fields " + self, "skip_background", label="Detect and Skip Empty Fields" + ), + property_control_for( + self, "equal_distances", label="Set Equal x and y Distances" ), ] diff --git a/tests/unit_tests/test_scan_workflows.py b/tests/unit_tests/test_scan_workflows.py index 50c27cdc..483b1f99 100644 --- a/tests/unit_tests/test_scan_workflows.py +++ b/tests/unit_tests/test_scan_workflows.py @@ -133,6 +133,31 @@ def test_histo_workflow_settings_generation(histo_workflow, mocker): assert workflow_settings.capture_params.images_dir == "/this/img_dir" +def test_histo_workflow_settings_generation_equal_overlap(histo_workflow, mocker): + """Check that setting x and y equal behaves as expected.""" + mocker.patch.object( + histo_workflow, "_calc_displacement_from_overlap", return_value=(123, 456) + ) + + # Different when False + histo_workflow.equal_distances = False + workflow_settings, _stitching_settings = histo_workflow.all_settings( + "/this/img_dir" + ) + + assert workflow_settings.dx == 123 + assert workflow_settings.dy == 456 + + # Same when set True + histo_workflow.equal_distances = True + workflow_settings, _stitching_settings = histo_workflow.all_settings( + "/this/img_dir" + ) + + assert workflow_settings.dx == 123 + assert workflow_settings.dy == 123 + + # A CSM that is "normal" changing from camera maxtrix coordinates (y,x) to normal # (x, y) coordinates CSM_NORMAL = [ @@ -349,7 +374,7 @@ def test_histo_workflow_settings_ui(histo_workflow): """Check that the workflow specifies the expected controls.""" ui = histo_workflow.settings_ui - assert len(ui) == 7 + assert len(ui) == 8 for element in ui: assert isinstance(element, PropertyControl) @@ -362,5 +387,6 @@ def test_histo_workflow_settings_ui(histo_workflow): "autofocus_dz", "max_range", "skip_background", + "equal_distances", ] assert names == expected_names