Changed typehints to literal for axis and direction

This commit is contained in:
Chish36 2025-07-30 17:58:03 +01:00 committed by Julian Stirling
parent 897cb022b1
commit 4cde2d5cd1

View file

@ -15,6 +15,7 @@ is tracked and an error is raised if it exceeds a reasonable amount.
import numpy as np import numpy as np
import cv2 import cv2
import json import json
from typing import Literal
from PIL import Image from PIL import Image
import time import time
from ..utilities import quadratic from ..utilities import quadratic
@ -37,7 +38,10 @@ AutofocusDep = lt.deps.direct_thing_client_dependency(AutofocusThing, "/autofocu
def _generate_move_dicts( def _generate_move_dicts(
fov_perc: int, stream_resolution: list[int], direction: int, factor: float = 1 fov_perc: int,
stream_resolution: list[int],
direction: Literal[1, -1],
factor: float = 1,
) -> dict[str, float]: ) -> dict[str, float]:
"""Create a single dictionary of x and y moves for moving in image coordinates. """Create a single dictionary of x and y moves for moving in image coordinates.
@ -54,7 +58,7 @@ def _generate_move_dicts(
def _predict_z( def _predict_z(
positions: list, axis: str, relative_move: float, stage: StageDep, csm: CSMDep positions: list, axis: Literal["x", "y"], relative_move: float, stage: StageDep, csm: CSMDep
) -> float: ) -> float:
"""Predict the next z position for a move using previous positions. """Predict the next z position for a move using previous positions.
@ -82,7 +86,7 @@ def _predict_z(
def _move_and_measure( def _move_and_measure(
step_size: dict[str, float], step_size: dict[str, float],
axis: str, axis: Literal["x", "y"],
data, data,
image1: npt.ArrayLike, image1: npt.ArrayLike,
autofocus_proc: bool, autofocus_proc: bool,
@ -125,8 +129,8 @@ def _move_and_measure(
def _acquire_z_predict_points( def _acquire_z_predict_points(
stream_resolution: list[int], stream_resolution: list[int],
direction: int, direction: Literal[1, -1],
axis: str, axis: Literal["x", "y"],
data, data,
csm: CSMDep, csm: CSMDep,
cam: CamDep, cam: CamDep,
@ -173,8 +177,8 @@ def _acquire_z_predict_points(
def _check_stage_operation( def _check_stage_operation(
small_step: int, small_step: int,
stream_resolution: list[int], stream_resolution: list[int],
direction: int, direction: Literal[1, -1],
axis: str, axis: Literal["x", "y"],
data, data,
minimum_offset_small: dict[str, float], minimum_offset_small: dict[str, float],
csm: CSMDep, csm: CSMDep,
@ -256,8 +260,8 @@ def _check_stage_operation(
def _motion_detection( def _motion_detection(
axis: str, axis: Literal["x", "y"],
direction: int, direction: Literal[1, -1],
csm: CSMDep, csm: CSMDep,
stage: StageDep, stage: StageDep,
cam: CamDep, cam: CamDep,
@ -348,8 +352,8 @@ class RangeofMotionThing(lt.Thing):
cam: CamDep, cam: CamDep,
csm: CSMDep, csm: CSMDep,
logger: lt.deps.InvocationLogger, logger: lt.deps.InvocationLogger,
axis: str, axis: Literal["x", "y"],
direction: int, direction: Literal[1,-1],
) -> dict: ) -> dict:
"""Measure the range of motion in a single axis and direction. """Measure the range of motion in a single axis and direction.