class documentation

class RangeofMotionThing(lt.Thing): (source)

Constructor: RangeofMotionThing()

View In Hierarchy

A class used to measure the range of motion of the stage in X and Y.

Method __init__ Initialise and create the lock.
Method perform_rom_test Measures the range of motion of the stage across the x and y axes.
Instance Variable calibrated_range Undocumented
Method _big_z_corrected_movement Take one big move with feed-forward z-correction.
Method _img_percentage_to_img_coords For a given image percentage and axis return the distance in img coords.
Method _initial_moves_for_z_prediction Perform 5 medium sized moves with autofocus for z feed-forward.
Method _move_and_measure Move the stage and measure the offset between the two positions.
Method _move_back_until_motion_detected Move the stage against the direction of test unil motion is detected.
Method _move_until_edge Move in one direction until movement per step decreases significantly.
Method _movement_in_img_coords Return the dictionary for a move in image coordinates.
Method _offset_from Take an image and calculate the offset from an input image.
Method _set_stream_resolution Set the self._stream_resolution attribute by reading camera.
Method _stage_still_moves Carry out 3 small moves in a given direction and axis.
Instance Variable _lock Undocumented
Instance Variable _rom_data Undocumented
Instance Variable _stream_resolution Undocumented
def __init__(self): (source)

Initialise and create the lock.

@lt.thing_action
def perform_rom_test(self, autofocus: AutofocusDep, stage: StageDep, cam: CamDep, csm: CSMDep, logger: lt.deps.InvocationLogger) -> dict[str, Any]: (source)

Measures the range of motion of the stage across the x and y axes.

Parameters
autofocus:AutofocusDepA raw_thing_client dependency for autofocus.
stage:StageDepA raw_thing_client depeendency for the microscope stage.
cam:CamDepA raw_thing_client depeendency for the camera.
csm:CSMDepA raw_thing_client depeendency for camera stage mapping.
logger:lt.deps.InvocationLoggerA raw_thing_client depeendency for the logger.
Returns
dict[str, Any]Results dictionary separated into keys of each axis and direction.
calibrated_range = (source)

Undocumented

def _big_z_corrected_movement(self, axis: Literal['x', 'y'], direction: Literal[1, -1], rom_deps: RomDeps): (source)

Take one big move with feed-forward z-correction.

The size is defined by the BIG_STEP constant.

Parameters
axis:Literal['x', 'y']The axis to move in.
direction:Literal[1, -1]The direction to move in.
rom_deps:RomDepsAll dependencies that were passed to the calling Action
def _img_percentage_to_img_coords(self, fov_perc: int, axis: Literal['x', 'y']) -> float: (source)

For a given image percentage and axis return the distance in img coords.

Parameters
fov_perc:intThe percentage of field of view the stage should move by.
axis:Literal['x', 'y']The resolution of the stream from the camera.
Returns
floatDistance in image coordinates (pixels)
def _initial_moves_for_z_prediction(self, axis: Literal['x', 'y'], direction: Literal[1, -1], rom_deps: RomDeps): (source)

Perform 5 medium sized moves with autofocus for z feed-forward.

z-feed forward allows prediction of the z-position as the stage moves. For the feed forward calculation to work an initial number of measurements must be taken. This method performs these initial measurements.

Parameters
axis:Literal['x', 'y']The axis which is being measured. This must be 'x' or 'y'.
direction:Literal[1, -1]The direction the stage moves.
rom_deps:RomDepsAll dependencies that were passed to the calling Action
def _move_and_measure(self, movement: dict[str, float], rom_deps: RomDeps, perform_autofocus: bool = True, max_autofocus_repeats: int = 0, abs_min_offset: float = 0.0) -> dict[str, float]: (source)

Move the stage and measure the offset between the two positions.

Parameters
movement:dict[str, float]A dictionary containing the distance to move in image coords.
rom_deps:RomDepsAll dependencies that were passed to the calling Action
perform_autofocus:boolSet to False to disable autofocus after move. Default is True
max_autofocus_repeats:intThe number of times to repeat the focus if the detected (on-axis) offset is below abs_min_offset. This will only work if abs_min_offset is also set
abs_min_offset:floatThe absolute minimum (on-axis) offset, under which the autofocus is repeated.
Returns
dict[str, float]The calculated offset from cross correlation.
def _move_back_until_motion_detected(self, axis: Literal['x', 'y'], direction: Literal[1, -1], rom_deps: RomDeps): (source)

Move the stage against the direction of test unil motion is detected.

In the case that the stage has reached the end of the motion, this method moves the motor in the opposite direction until reliable motion is detected.

Parameters
axis:Literal['x', 'y']The axis in which the stage is moving. This must be 'x' or 'y'.
direction:Literal[1, -1]The direction in which the stage was moving during the test, this method will move in the opposite direction.
rom_deps:RomDepsAll dependencies that were passed to the calling Action
def _move_until_edge(self, axis: Literal['x', 'y'], direction: Literal[1, -1], rom_deps: RomDeps): (source)

Move in one direction until movement per step decreases significantly.

This should move until the edge of the stage. Once the edge is reached there will be some movement as there is no hard stop, but it will reduce significantly.

Parameters
axis:Literal['x', 'y']The axis which is being measured. This must be 'x' or 'y'.
direction:Literal[1, -1]The direction which is being measured. This must be 1 or -1.
rom_deps:RomDepsAll dependencies that were passed to the calling Action
Returns
Results dictionary containing stage positions, correlations and the final position.
def _movement_in_img_coords(self, fov_perc: int, axis: Literal['x', 'y'], direction: Literal[1, -1]) -> dict[str, float]: (source)

Return the dictionary for a move in image coordinates.

This dictionary can be passed directly to csm.move_in_image_coordinates

Parameters
fov_perc:intThe percentage of field of view the stage should move by.
axis:Literal['x', 'y']The resolution of the stream from the camera.
direction:Literal[1, -1]The direction the stage moves.
Returns
dict[str, float]The movement size in image coordinates
def _offset_from(self, before_img: np.ndarray, rom_deps: RomDeps) -> dict[str, float]: (source)

Take an image and calculate the offset from an input image.

Parameters
before_img:np.ndarrayThe image the offset should be calculated with respect to.
rom_deps:RomDepsAll dependencies that were passed to the calling Action
Returns
dict[str, float]The calculated offset as a dictionary in pixels
def _set_stream_resolution(self, cam: CamDep): (source)

Set the self._stream_resolution attribute by reading camera.

Parameters
cam:CamDepThe camera dependency.
def _stage_still_moves(self, axis: Literal['x', 'y'], direction: Literal[1, -1], rom_deps: RomDeps) -> bool: (source)

Carry out 3 small moves in a given direction and axis.

An image is taken before and after each move to check the stage has moved as far as it should. If the offset (calculated by cross correlation) is less than expected, 3 attempts are made to refocus the image to ensure that image quality is not causing the offset to mistakenly be reported as a low value. If the calculated offset is still too low then this is taken as an indication that the edge has been found.

Parameters
axis:Literal['x', 'y']The axis which is being measured. This must be 'x' or 'y'.
direction:Literal[1, -1]The direction the stage moves.
rom_deps:RomDepsAll dependencies that were passed to the calling Action
Returns
boolUndocumented

Undocumented

_rom_data = (source)

Undocumented

_stream_resolution: tuple[int, int] | None = (source)

Undocumented