class documentation

A class with direct access to the CameraThing for monitoring the MJPEG stream.

The autofocus algorithm uses sharpness calculated from the file size of the images in the MJPEG stream. This class monitors both the stage position and the jpeg sharpness over time.

The run context manager is used to start monitoring the camera stream. Position monitoring happens during focus_rel. Raw data can be retrieved with data_dict and data with interpolated z positions can be retrieved with move_data.

A new JPEGSharpnessMonitor instance is created each time an action with the SharpnessMonitorDep as an argument is called.

Method __init__ Initialise a new JPEGSharpnessMonitor. The args are injected automatically.
Method data_dict Return the gathered data as a single convenient dictionary.
Method focus_rel Move the stage by dz, monitoring the position over time.
Async Method monitor_sharpness Start monitoring the frame sizes.
Method move_data Extract sharpness as a function of (interpolated) z.
Method run Context manager, during which we will monitor sharpness from the camera.
Method sharpest_z_on_move Return the z position of the sharpest image on a given move.
Instance Variable camera Undocumented
Instance Variable jpeg_sizes Undocumented
Instance Variable jpeg_times Undocumented
Instance Variable portal Undocumented
Instance Variable running Undocumented
Instance Variable stage Undocumented
Instance Variable stage_positions Undocumented
Instance Variable stage_times Undocumented
def __init__(self, stage: Stage, camera: RawCamera, portal: lt.deps.BlockingPortal): (source)

Initialise a new JPEGSharpnessMonitor. The args are injected automatically.

Parameters
stage:StageA direct_thing_client dependency for the the microscope stage.
camera:RawCameraA raw_thing_client depeendency for the camera. This is a raw dependency as the underlying class needs to be
portal:lt.deps.BlockingPortalThe asyncio blocking portal for asynchronous task scheduling.
def data_dict(self) -> SharpnessDataArrays: (source)

Return the gathered data as a single convenient dictionary.

def focus_rel(self, dz: int, **kwargs) -> tuple[int, int]: (source)

Move the stage by dz, monitoring the position over time.

This performs exactly one move. Multiple calls of this method will append to the internal position storage for more complex autofocus procedures.

This should be run from within the JPEGSharpnessMonitor.run context manager so that sharpness data and timestamps are also collected.

async def monitor_sharpness(self): (source)

Start monitoring the frame sizes.

def move_data(self, istart: int, istop: int | None = None) -> tuple[np.ndarray, np.ndarray, np.ndarray]: (source)

Extract sharpness as a function of (interpolated) z.

@contextmanager
def run(self): (source)

Context manager, during which we will monitor sharpness from the camera.

def sharpest_z_on_move(self, data_index: int) -> int: (source)

Return the z position of the sharpest image on a given move.

Undocumented

jpeg_sizes: list[int] = (source)

Undocumented

jpeg_times: list[float] = (source)

Undocumented

Undocumented

running: bool = (source)

Undocumented

Undocumented

stage_positions: list[Mapping[str, int]] = (source)

Undocumented

stage_times: list[float] = (source)

Undocumented