From e73ee8875c1d0bca33a57f6d82420074719a7903 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Tue, 30 Mar 2021 17:51:00 +0100 Subject: [PATCH] Fixed type annotations in autofocus and mock stage I don't know why these didn't fail before - possibly because of incomplete type information from old numpy... I removed a few annotations because they were failing (e.g. np.sum can return a scalar or an array), but I don't think this should be a problem - the function inputs and return values are still typed. --- .../api/default_extensions/autofocus.py | 15 +++++++++------ openflexure_microscope/stage/mock.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/openflexure_microscope/api/default_extensions/autofocus.py b/openflexure_microscope/api/default_extensions/autofocus.py index ed6fd813..ba6f00ca 100644 --- a/openflexure_microscope/api/default_extensions/autofocus.py +++ b/openflexure_microscope/api/default_extensions/autofocus.py @@ -129,18 +129,21 @@ def monitor_sharpness(microscope: Microscope): def sharpness_sum_lap2(rgb_image: np.ndarray) -> float: """Return an image sharpness metric: sum(laplacian(image)**")""" - image_bw: float = np.mean(rgb_image, 2) - image_lap: float = ndimage.filters.laplace(image_bw) - return np.mean(image_lap.astype(float) ** 4) + image_bw = np.mean(rgb_image, 2) + image_lap = ndimage.filters.laplace(image_bw) + return float(np.mean(image_lap.astype(float) ** 4)) def sharpness_edge(image: np.ndarray) -> float: """Return a sharpness metric optimised for vertical lines""" - gray: float = np.mean(image.astype(float), 2) + gray = np.mean(image.astype(float), 2) n: int = 20 edge: np.ndarray = np.array([[-1] * n + [1] * n]) - return np.sum( - [np.sum(ndimage.filters.convolve(gray, W) ** 2) for W in [edge, edge.T]] + return float( + np.sum( + [np.sum(ndimage.filters.convolve(gray, W) ** 2) + for W in [edge, edge.T]] + ) ) diff --git a/openflexure_microscope/stage/mock.py b/openflexure_microscope/stage/mock.py index 8b67b196..4268224c 100644 --- a/openflexure_microscope/stage/mock.py +++ b/openflexure_microscope/stage/mock.py @@ -89,7 +89,7 @@ class MissingStage(BaseStage): ) displacement = move - initial_move = np.array(displacement, dtype=np.int) + initial_move = np.array(displacement, dtype=np.integer) self._position = list(np.array(self._position) + np.array(initial_move)) logging.debug(np.array(self._position) + np.array(initial_move))