From 8ba40832e00e2a325e57245cb0eccec31a9d8c6e Mon Sep 17 00:00:00 2001 From: jaknapper Date: Mon, 23 Jun 2025 14:13:08 +0100 Subject: [PATCH] Neighbour cutoff moved from autofocus.py to scan_planners.py --- src/openflexure_microscope_server/scan_planners.py | 12 ++++++++---- .../things/autofocus.py | 4 ---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/openflexure_microscope_server/scan_planners.py b/src/openflexure_microscope_server/scan_planners.py index 6d430aa4..d9c26b9a 100644 --- a/src/openflexure_microscope_server/scan_planners.py +++ b/src/openflexure_microscope_server/scan_planners.py @@ -20,6 +20,11 @@ XYPosList: TypeAlias = list[XYPos] XYZPosList: TypeAlias = list[XYZPos] +# how many times the minimum distance between images to include as a "nearby" image +# default 1.4 includes images offset in x or y, but not diagonally +NEIGHBOUR_CUTOFF = 1.4 + + def enforce_xy_tuple(value: XYPos) -> XYPos: """ Used for enforcing that an input is a tuple and is the correct length @@ -214,7 +219,7 @@ class ScanPlanner: Return the xyz position of the nearby site with the lowest z position. Lowest position is best, as starting too high causes smart stacking to autofocus and restart. Starting too low just requires extra movements in +z. - Nearby is defined as within 1.6 times the distance to the closest neighbour. + Nearby is defined as within NEIGHBOUR_CUTOFF times the distance to the closest neighbour. Returns None if there if no focussed locations are present """ @@ -229,10 +234,9 @@ class ScanPlanner: # Note linalg.norm always uses float64 dists = np.linalg.norm((path_pos - current_pos), axis=1) - # Get indices of all focused sites within 1.6x the minimum distance. - # 1.6x chosen as it includes offsets in x and y on the Picamera2 aspect ratio + # Get indices of all focused sites within NEIGHBOUR_CUTOFF the minimum distance. # Note np.where always returns a tuple of arrays, hence the trailing [0] - indices = np.where(dists <= 1.6 * np.min(dists))[0] + indices = np.where(dists <= NEIGHBOUR_CUTOFF * np.min(dists))[0] # Turning into an array allows slicing based on a list focused_locations_array = np.array(self._focused_locations) diff --git a/src/openflexure_microscope_server/things/autofocus.py b/src/openflexure_microscope_server/things/autofocus.py index 679b0e77..c3359b9d 100644 --- a/src/openflexure_microscope_server/things/autofocus.py +++ b/src/openflexure_microscope_server/things/autofocus.py @@ -41,10 +41,6 @@ class StackParams(BaseModel): # distance (in steps) to overshoot a move and then undo, to account for backlash backlash_correction: int = 250 - # how many times the minimum distance between images to include as a "nearby" image - # default 1.4 includes images offset in x or y, but not diagonally - neighbour_cutoff: float = 1.4 - # how many images can be appended to the stack after the predicted peak to test for focus # before assuming the focus was passed, and restarting the stack stack_height_limit: int = 15