Fix some annotations, arguments, and docstring formatting

This commit is contained in:
Julian Stirling 2025-10-16 10:42:48 +01:00
parent 19b2afe7d7
commit 8a0836f368
2 changed files with 30 additions and 26 deletions

View file

@ -13,16 +13,19 @@ is tracked and an error is raised if it exceeds a minimum amount. Currently
this is 10% of the expected motion is the measured axis. this is 10% of the expected motion is the measured axis.
""" """
import numpy as np from typing import Literal, Any, Optional
from typing import Literal
from PIL import Image
import time import time
from ..utilities import quadratic
from scipy.optimize import curve_fit from scipy.optimize import curve_fit
from PIL import Image
import numpy as np
import numpy.typing as npt
from camera_stage_mapping import fft_image_tracking from camera_stage_mapping import fft_image_tracking
import labthings_fastapi as lt import labthings_fastapi as lt
from labthings_fastapi.types.numpy import DenumpifyingDict from labthings_fastapi.types.numpy import DenumpifyingDict
import numpy.typing as npt
from openflexure_microscope_server.utilities import quadratic
# Things # Things
from .autofocus import AutofocusThing from .autofocus import AutofocusThing
@ -41,21 +44,21 @@ class RomDataTracker:
def __init__( def __init__(
self, self,
stage_coords: list[dict[str, int]] = [], stage_coords: Optional[list[dict[str, int]]] = None,
cor_lat_steps: list[npt.ArrayLike] = [], cor_lat_steps: Optional[list[npt.ArrayLike]] = None,
delta: dict = {"x": 0, "y": 0}, delta: Optional[dict[str, int]] = None,
): ) -> None:
"""Define useful data tracked throughout test.""" """Define useful data tracked throughout test."""
self.stage_coords = stage_coords self.stage_coords = [] if stage_coords is None else stage_coords
self.cor_lat_steps = cor_lat_steps self.cor_lat_steps = [] if cor_lat_steps is None else cor_lat_steps
self.delta = delta self.delta = {"x": 0, "y": 0} if delta is None else delta
def measure(self, current_pos: dict[str, int], cor: npt.ArrayLike): def measure(self, current_pos: dict[str, int], cor: npt.ArrayLike) -> None:
"""Store useful data.""" """Store useful data."""
self.stage_coords.append(current_pos) self.stage_coords.append(current_pos)
self.cor_lat_steps.append(cor) self.cor_lat_steps.append(cor)
def reset_tracker(self): def reset_tracker(self) -> None:
"""Empty the rom tracker.""" """Empty the rom tracker."""
self.stage_coords.clear() self.stage_coords.clear()
self.cor_lat_steps.clear() self.cor_lat_steps.clear()
@ -140,7 +143,7 @@ def _predict_z(
def _move_and_measure( def _move_and_measure(
step_size: dict[str, float], step_size: dict[str, float],
axis: Literal["x", "y"], axis: Literal["x", "y"],
data, data: RomDataTracker,
image1: npt.ArrayLike, image1: npt.ArrayLike,
autofocus_proc: bool, autofocus_proc: bool,
csm: CSMDep, csm: CSMDep,
@ -191,6 +194,8 @@ def _acquire_z_predict_points(
) -> None: ) -> None:
"""Complete 5 medium sized steps to collect stage coordinates for prediction. """Complete 5 medium sized steps to collect stage coordinates for prediction.
Delta is updated and tracked after each move.
:params stream_resolution: The resolution of the stream from the camera. :params stream_resolution: The resolution of the stream from the camera.
:param direction: The direction the stage moves. :param direction: The direction the stage moves.
:params axis: The axis which is being measured. This must be 'x' or 'y'. :params axis: The axis which is being measured. This must be 'x' or 'y'.
@ -200,7 +205,6 @@ def _acquire_z_predict_points(
:param stage: A raw_thing_client depeendency for the microscope stage. :param stage: A raw_thing_client depeendency for the microscope stage.
:param autofocus: A direct_thing_client dependency for autofocus. :param autofocus: A direct_thing_client dependency for autofocus.
:return: Stage_coords and cor_lat_steps are lists of data tracked throughout the test. :return: Stage_coords and cor_lat_steps are lists of data tracked throughout the test.
Delta is updated and tracked after each move.
""" """
medium_step = 50 medium_step = 50
wrong_axis_max_medium = _generate_move_dicts( wrong_axis_max_medium = _generate_move_dicts(
@ -234,7 +238,7 @@ def _check_stage_operation(
stream_resolution: list[int], stream_resolution: list[int],
direction: Literal[1, -1], direction: Literal[1, -1],
axis: Literal["x", "y"], axis: Literal["x", "y"],
data, data: RomDataTracker,
minimum_offset_small: dict[str, float], minimum_offset_small: dict[str, float],
csm: CSMDep, csm: CSMDep,
cam: CamDep, cam: CamDep,
@ -373,7 +377,7 @@ def _motion_detection(
return stage.position return stage.position
def _collate_data(data: dict, time: float, csm: CSMDep) -> dict: def _collate_data(data: dict, time: float, csm: CSMDep) -> dict[str, Any]:
"""Collate and calculate all useful data from ROM test. """Collate and calculate all useful data from ROM test.
:param data: Dictionary created from ROM test. :param data: Dictionary created from ROM test.
@ -545,7 +549,7 @@ class RangeofMotionThing(lt.Thing):
cam: CamDep, cam: CamDep,
csm: CSMDep, csm: CSMDep,
logger: lt.deps.InvocationLogger, logger: lt.deps.InvocationLogger,
): ) -> dict[str, Any]:
"""Measures the range of motion of the stage across the x and y axes. """Measures the range of motion of the stage across the x and y axes.
:param autofocus: A raw_thing_client dependency for autofocus. :param autofocus: A raw_thing_client dependency for autofocus.

View file

@ -329,7 +329,7 @@ def _get_version_from_toml(toml_path: str) -> str:
return "Undefined" return "Undefined"
def quadratic(x: float, a: float, b: float, c: float): def quadratic(x: float, a: float, b: float, c: float) -> float:
"""Quadratic function. Used for predicting z. """Quadratic function. Used for predicting z.
:param x: The points at which to evaluate the quadratic. :param x: The points at which to evaluate the quadratic.