Typehint given to data

This commit is contained in:
Chish36 2025-08-12 15:02:59 +01:00 committed by Julian Stirling
parent 6bed02eccf
commit e3a17240db

View file

@ -35,6 +35,29 @@ CSMDep = lt.deps.direct_thing_client_dependency(
) )
AutofocusDep = lt.deps.direct_thing_client_dependency(AutofocusThing, "/autofocus/") AutofocusDep = lt.deps.direct_thing_client_dependency(AutofocusThing, "/autofocus/")
class RomDataTracker:
"""Class for tracking range of motion data."""
def __init__(
self,
stage_coords: list[dict[str, int]] = [],
cor_lat_steps: list[npt.ArrayLike] = [],
delta: dict = {"x": 0, "y": 0},
):
"""Define useful data tracked throughout test."""
self.stage_coords = stage_coords
self.cor_lat_steps = cor_lat_steps
self.delta = delta
def measure(self, current_pos: dict[str, int], cor: npt.ArrayLike):
"""Store useful data."""
self.stage_coords.append(current_pos)
self.cor_lat_steps.append(cor)
def reset_tracker(self):
"""Empty the rom tracker."""
self.stage_coords.clear()
self.cor_lat_steps.clear()
class ParasiticMotionError(Exception): class ParasiticMotionError(Exception):
"""Custom exception raised when parasitic motion is detected. """Custom exception raised when parasitic motion is detected.
@ -45,10 +68,14 @@ class ParasiticMotionError(Exception):
pass pass
def parasitic_detect(delta: float, max_allowed_delta: float) -> None: def parasitic_detect(delta: float, max_allowed_delta: float) -> None:
"""Compare two values and raise parasitic motion error.""" """Compare two values and raise parasitic motion error."""
if delta > max_allowed_delta: if delta > max_allowed_delta:
raise ParasiticMotionError(f"Parasitic motion detected. {delta} is greate than {max_allowed_delta}") raise ParasiticMotionError(
f"Parasitic motion detected. {delta} is greater than {max_allowed_delta}"
)
def _generate_move_dicts( def _generate_move_dicts(
fov_perc: int, fov_perc: int,
@ -153,7 +180,7 @@ def _acquire_z_predict_points(
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,
csm: CSMDep, csm: CSMDep,
cam: CamDep, cam: CamDep,
stage: StageDep, stage: StageDep,
@ -194,7 +221,11 @@ def _acquire_z_predict_points(
data.measure(stage.position, offset) data.measure(stage.position, offset)
parasitic_detect(delta=abs(data.delta[wrong_axis]), max_allowed_delta=abs(wrong_axis_max_medium[wrong_axis])) parasitic_detect(
delta=abs(data.delta[wrong_axis]),
max_allowed_delta=abs(wrong_axis_max_medium[wrong_axis]),
)
def _check_stage_operation( def _check_stage_operation(
small_step: int, small_step: int,
@ -275,7 +306,14 @@ def _check_stage_operation(
data.measure(stage.position, offset) data.measure(stage.position, offset)
parasitic_detect(abs(data.delta[wrong_axis]),abs(_generate_move_dicts(small_step, stream_resolution, direction, factor=0.1)[wrong_axis])) parasitic_detect(
abs(data.delta[wrong_axis]),
abs(
_generate_move_dicts(
small_step, stream_resolution, direction, factor=0.1
)[wrong_axis]
),
)
# this means the edge has been found # this means the edge has been found
if np.abs(data.delta[axis]) < np.abs(minimum_offset_small[axis]): if np.abs(data.delta[axis]) < np.abs(minimum_offset_small[axis]):
@ -333,31 +371,6 @@ def _motion_detection(
return stage.position return stage.position
class RomDataTracker:
"""Class for tracking range of motion data."""
def __init__(
self,
stage_coords: list[dict[str, int]] = [],
cor_lat_steps: list[list[float]] = [],
delta: dict = {"x": 0, "y": 0},
):
"""Define useful data tracked throughout test."""
self.stage_coords = stage_coords
self.cor_lat_steps = cor_lat_steps
self.delta = delta
def measure(self, current_pos: dict[str, int], cor: list[float]):
"""Store useful data."""
self.stage_coords.append(current_pos)
self.cor_lat_steps.append(cor)
def reset_tracker(self):
"""Empty the rom tracker."""
self.stage_coords.clear()
self.cor_lat_steps.clear()
class RangeofMotionThing(lt.Thing): class RangeofMotionThing(lt.Thing):
"""A class used to measure the range of motion of the stage in X and Y.""" """A class used to measure the range of motion of the stage in X and Y."""