module documentation

OpenFlexure Microscope API extension for stage calibration.

This file contains the HTTP API for camera/stage calibration. It includes calibration functions that measure the relationship between stage coordinates and camera coordinates, as well as functions that move by a specified displacement in pixels, perform closed-loop moves, and return the calibration data.

This module is only intended to be called from the OpenFlexure Microscope server, and depends on that server and its underlying LabThings library.

Class CameraStageMapper A Thing to manage mapping between image and stage coordinates.
Class CSMUncalibratedError An Exception raised if camera stage mapping data is needed but unavailable.
Class MoveHistory A named tuple containing the position over time for a single move.
Class RecordedMove Call stage movement and maintain a record of position and time.
Function csm_img_to_stage Apply any CSM matrix to image coordinates.
Function csm_stage_to_img Apply any CSM matrix to stage coordinates to get image coordinates.
Function _array_to_stage_tuple Convert a numpy array into a tuple of ints.
Function _serialise_numpy_in_dict Undocumented
def csm_img_to_stage(matrix: np.ndarray | list[list[float]], *, x: float | int, y: float | int, **_kwargs: int) -> Mapping[str, int]: (source)

Apply any CSM matrix to image coordinates.

x and y must be kwargs and extra kwargs are ignored, allowing: csm_img_to_stage(matrix, **position) to run for a mapping position.

Note that x and y are the actual (x, y) of the image, not the (m, n) indices used by numpy

Parameters
matrix:np.ndarray | list[list[float]]The matrix to use in the calculation
x:float | intthe x image coordinate (keyword only)
y:float | intthe y image coordinate (keyword only)
**_kwargs:intUndocumented
Returns
Mapping[str, int]The resulting stage coordinates as a mapping.
def csm_stage_to_img(matrix: np.ndarray | list[list[float]], *, x: float | int, y: float | int, **_kwargs: int) -> Mapping[str, float]: (source)

Apply any CSM matrix to stage coordinates to get image coordinates.

x and y must be kwargs and extra kwargs are ignored, allowing: csm_img_to_stage(matrix, **position) to run for a mapping position.

Note that x and y are the actual (x, y) of the image, not the (m, n) indices used numpy

Parameters
matrix:np.ndarray | list[list[float]]The matrix to use in the calculation
x:float | intthe x stage coordinate (keyword only)
y:float | intthe y stage coordinate (keyword only)
**_kwargs:intUndocumented
Returns
Mapping[str, float]The resulting img coordinates as a mapping.
def _array_to_stage_tuple(pos: np.ndarray) -> tuple[int, int, int]: (source)

Convert a numpy array into a tuple of ints.

Parameters
pos:np.ndarrayInput position array must be 3 elements long.
Returns
tuple[int, int, int]a tuple of 3 integers
Raises
ValueErrorIf the array is not of length 3.
def _serialise_numpy_in_dict(dict_with_numpy: dict) -> dict: (source)

Undocumented