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.

Method __enter__ Start context manager, during which sharpness from the camera is monitored.
Method __exit__ Clean up after context manager is closed.
Method __init__ Initialise a new JPEGSharpnessMonitor. The args are injected automatically.
Method data_dict Return the gathered data as dict.
Method data_to_array Return the gathered data as SharpnessDataArrays.
Method focus_rel Move the stage by dz, monitoring the position over time.
Async Method monitor_sharpness Start monitoring sharpness metrics.
Method move_data Extract sharpness as a function of (interpolated) z.
Method sharpest_z_on_move Return the z position of the sharpest image on a given move.
Instance Variable camera Undocumented
Instance Variable method Undocumented
Instance Variable record Undocumented
Instance Variable running Undocumented
Instance Variable stage Undocumented
Property focus_foms The recorded FocusFoM values.
Property jpeg_sizes The recorded JPEG frame sizes used as a sharpness metric.
Property jpeg_times The timestamps recorded for captured JPEG frames.
Property stage_positions The positions recorded for the stage.
Property stage_times The timestamps recorded for stage position updates.
Instance Variable _focus_foms Undocumented
Instance Variable _jpeg_sizes Undocumented
Instance Variable _jpeg_times Undocumented
Instance Variable _stage_positions Undocumented
Instance Variable _stage_times Undocumented
def __enter__(self) -> Self: (source)

Start context manager, during which sharpness from the camera is monitored.

def __exit__(self, _exc_type: type[BaseException], _exc_value: BaseException | None, _traceback: TracebackType | None): (source)

Clean up after context manager is closed.

def __init__(self, stage: BaseStage, camera: BaseCamera, method: SharpnessMethod = SharpnessMethod.JPEG, record: int | None = None): (source)

Initialise a new JPEGSharpnessMonitor. The args are injected automatically.

Parameters
stage:BaseStageA direct_thing_client dependency for the the microscope stage.
camera:BaseCameraA raw_thing_client depeendency for the camera. This is a raw dependency as required by the underlying class.
method:SharpnessMethodThe sharpness metric used when evaluating autofocus.
record:int | NoneBitmask of sharpness metrics to record while monitoring. If None or 0, only the metric specified by method is recorded.
Raises
ValueErrorIf method is not included in record.
ValueErrorIf SharpnessMethod.FOCUS_FOM is requested but the camera does not support FocusFoM measurements.
def data_dict(self) -> dict: (source)

Return the gathered data as dict.

def data_to_array(self) -> SharpnessDataArrays: (source)

Return the gathered data as SharpnessDataArrays.

def focus_rel(self, dz: int, block_cancellation: bool = False) -> 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 sharpness metrics.

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.

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

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

Undocumented

Undocumented

Undocumented

running: bool = (source)

Undocumented

Undocumented

@property
focus_foms: Sequence[float] = (source)

The recorded FocusFoM values.

Raises
ValueErrorIf FocusFoM recording is not enabled.
@property
jpeg_sizes: Sequence[int] = (source)

The recorded JPEG frame sizes used as a sharpness metric.

Raises
ValueErrorIf JPEG sharpness recording is not enabled.
@property
jpeg_times: Sequence[float] = (source)

The timestamps recorded for captured JPEG frames.

@property
stage_positions: Sequence[Mapping[str, int]] = (source)

The positions recorded for the stage.

Raises
ValueErrorIf stage position recording is not enabled.
@property
stage_times: Sequence[float] = (source)

The timestamps recorded for stage position updates.

_focus_foms: list[float] = (source)

Undocumented

_jpeg_sizes: list[int] = (source)

Undocumented

_jpeg_times: list[float] = (source)

Undocumented

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

Undocumented

_stage_times: list[float] = (source)

Undocumented