A Thing to manage mapping between image and stage coordinates.
To use this Thing, the stage must have axes named "x", "y", and "z", or must override the get_xyz_position() and move_to_xyz_position() methods.
| Method | assert |
Return image_to_stage_displacement matrix or raise error if it's not set. |
| Method | calibrate |
Measure the relationship between camera and stage coordinates. |
| Method | convert |
Convert image coordinates to stage coordinates. Only x and y are returned. |
| Method | convert |
Convert stage coordinates to image coordinates. Only x and y are returned. |
| Method | move |
Move by a given number of pixels on the camera. |
| Instance Variable | image |
The image size used to calibrate the image_to_stage_displacement_matrix. |
| Instance Variable | image |
A 2x2 matrix that converts displacement in image coordinates to stage coordinates. |
| Instance Variable | last |
The timestamp of the last calibration. This can be used to get the data file. |
| Property | calibration |
Whether the camera stage mapper needs calibrating. |
| Property | can |
Whether the Thing permits calibration. |
| Property | last |
The most recent CSM calibration. |
| Property | thing |
Summary metadata describing the current state of the Thing. |
| Method | _detect |
Move the stage in increasing steps until motion is detected. |
| Method | _fit |
Fit all runs from the camera stage. |
| Method | _fit |
Fit the backlash in this run. |
| Method | _fit |
Fit the camera stage mapping matrix from all the displacements recorded. |
| Method | _measure |
Measure camera vs stage displacement in 1 direction on one axis. |
| Method | _measure |
Measure a single axis, and return the measurement data in a dictionary. |
| Method | _write |
Write the CSM data to disk and return the timestamp. |
| Class Variable | _cam |
Undocumented |
| Class Variable | _class |
Undocumented |
| Class Variable | _stage |
Undocumented |
Inherited from OFMThing:
| Method | __enter__ |
Set the data directory when the Thing is entered. |
| Method | __exit__ |
Close the OFMThing. |
| Method | create |
Create a RelativeDataPath object with this Thing set as the saving Thing. |
| Property | data |
The data directory for this thing. |
| Property | show |
Whether to show in the Gallery. |
| Class Variable | _show |
Undocumented |
| Instance Variable | _data |
Undocumented |
Measure the relationship between camera and stage coordinates.
Note: this is the method used by camera_stage_mapping to measure the CSM matrix, calling this directly will perform a measurement but not set the measurement, for use.
float, y: float, **_kwargs: float) -> Mapping[ str, int]:
(source)
¶
Convert image coordinates to stage coordinates. Only x and y are returned.
int, y: int, **_kwargs: int) -> Mapping[ str, float]:
(source)
¶
Convert stage coordinates to image coordinates. Only x and y are returned.
Move by a given number of pixels on the camera.
NB x and y here refer to what is usually understood to be the horizontal and vertical axes of the image. In many toolkits, "matrix indices" are used, which swap the order of these coordinates. This includes opencv and PIL. So, don't be surprised if you find it necessary to swap x and y around.
As a general rule, x usually corresponds to the longer dimension of the image, and y to the shorter one. Checking what shape your chosen toolkit reports for an image usually helps resolve any ambiguity.
A 2x2 matrix that converts displacement in image coordinates to stage coordinates.
Note that this matrix is defined using "matrix coordinates", i.e. image coordinates are (y,x). To make a move in image coordinates (dy, dx), where dx is horizontal, you should move the stage by:
stage_disp = np.dot(
np.array([dy,dx]),
np.array(image_to_stage_displacement_matrix),
)Literal[ 'x', 'y'], target_movement_px: int) -> tuple[ list[ tuple[ int, int, int]], list[ tuple[ float, float]]]:
(source)
¶
Move the stage in increasing steps until motion is detected.
The stage is moved in one axis. This will complete if motion is detected in any direction in the camera coordinates.
| Returns | |
tuple[ | Two lists, One of absolute x positions and camera . |
Fit all runs from the camera stage.
| Parameters | |
csmdict[ | The dictionary created by calibrate_xy |
| Returns | |
tuple[ | The camera stage mapping matrix and the magnitude of the backlash. |
Literal[ 'x', 'y'], stage_pos: np.ndarray, cam_pos: np.ndarray) -> tuple[ float, int]:
(source)
¶
Fit the backlash in this run.
Start with the full fit and remove the initial points until the standard error minimises. Then use the displacement between the first point and the extrapolated fit to calculate the backlash.
| Parameters | |
axis:Literal[ | Undocumented |
stagenp.ndarray | A nx3 matrix of stage positions. |
camnp.ndarray | A nx2 matrix of camera positions. |
| Returns | |
tuple[ | The estimated backlash, and the number of points to exclude due to backlash. |
list[ np.ndarray], all_cam_displacements: list[ np.ndarray]) -> np.ndarray:
(source)
¶
Fit the camera stage mapping matrix from all the displacements recorded.
| Parameters | |
alllist[ | A list of nx3 matrixies with the camera displacements for each run. |
alllist[ | A list of nx3 matrixies with the stage displacements for each run. |
| Returns | |
np.ndarray | The camera stage mapping matrix. |
Literal[ 'x', 'y'], step_size: int, n_moves: int = 10) -> tuple[ list[ tuple[ int, int, int]], list[ tuple[ float, float]]]:
(source)
¶
Measure camera vs stage displacement in 1 direction on one axis.
Literal[ 'x', 'y'], *, target_movement_px: int, starting_position: Mapping[ str, int]) -> dict[ str, Any]:
(source)
¶
Measure a single axis, and return the measurement data in a dictionary.