class documentation

A Thing for scanning samples and interacting with past scans.

SmartScanThing exposes all functionality for automatically scanning samples, previewing live stitching, retrieving data from past scans, and for deleting past scans.

Method __enter__ Open hardware connection when the Thing context manager is opened.
Method __exit__ Clean up after context manager is closed.
Method __init__ Initialise a SmartScanThing saving to and loading from the input directory.
Method delete_all_gallery_items Delete all the scans on the microscope.
Method delete_scan Delete the folder for the specified scan.
Method download_zip Return zip after including any files left until the end.
Method get_gallery_bulk_actions Return the bulk gallery actions for smart scan.
Method get_latest_preview Retrieve the latest preview image.
Method purge_empty_scans Delete all scan folders containing no images at the top level.
Method sample_scan Move the stage to cover an area, taking images.
Method stitch_all_scans Check the list of scans, and stitch any that don't have a DZI associated with it.
Method stitch_scan Generate a stitched image based on stage position metadata.
Method workflow_name The name of the scan workflow selector.
Method workflow_name.setter Validate and set workflow_name.
Class Variable stitch_automatically Whether to run a final stitch at the end of a successful scan.
Class Variable stitch_tiff Whether or not to also produce a pyramidal tiff at the end of a scan.
Property all_workflow_names Return a list of all available Scan Workflows.
Property gallery_db_engine The database engine.
Property latest_preview_stitch_path The path of the latest preview stitched image, or None if not available.
Property latest_preview_stitch_time The modification time of the latest preview image, to allow live updating.
Property latest_scan_live_details The details of any ongoing scan, or the previous scan if no scan ongoing.
Property ongoing_scan The ScanDirectory object of the ongoing scan.
Property scan_data The ActiveScanData object holding information about the of the ongoing scan.
Property thing_state Return a metadata dict for ongoing scan to populate.
Property workflow_display_names Return a list of the display names of all available Scan Workflows.
Method _collect_scan_data Collect and return the data for this scan so it cannot be changed mid-scan.
Method _delete_scan Delete a scan.
Method _get_scan_dir Undocumented
Method _main_scan_loop Run the main loop of the scan.
Method _manage_stitching_threads Manage the stitching threads, starting them if needed and not already running.
Method _move_to_next_point Move the stage to the next position.
Method _perform_final_stitch Update the scan zip and perform final stitch of the data.
Method _return_to_starting_position Return to the initial scan position, if set.
Method _run_scan Prepare and run the main scan, and perform final actions on completion.
Method _save_final_scan_data Update scan data JSON file with data only known at the end of the scan.
Class Variable _all_workflows Undocumented
Class Variable _cam Undocumented
Class Variable _class_settings Undocumented
Class Variable _show_data_in_gallery Undocumented
Class Variable _stage Undocumented
Instance Variable _default_workflow Undocumented
Instance Variable _gallery_db_engine Undocumented
Instance Variable _latest_scan_live_details Undocumented
Instance Variable _ongoing_scan Undocumented
Instance Variable _preview_stitcher Undocumented
Instance Variable _scan_data Undocumented
Instance Variable _scan_lock Undocumented
Instance Variable _workflow_name Undocumented
Property _workflow The active scan workflow object.

Inherited from OFMThing:

Method create_data_path Create a RelativeDataPath object with this Thing set as the saving Thing.
Property data_dir The data directory for this thing.
Property show_data_in_gallery Whether to show in the Gallery.
Instance Variable _data_dir Undocumented
def __enter__(self) -> Self: (source)

Open hardware connection when the Thing context manager is opened.

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, thing_server_interface: lt.ThingServerInterface, default_workflow: str): (source)

Initialise a SmartScanThing saving to and loading from the input directory.

Parameters
thing_server_interface:lt.ThingServerInterfaceUndocumented
default_workflow:strThe default workflows that smart scan uses if nothing is set in settings.
def delete_all_gallery_items(self): (source)

Delete all the scans on the microscope.

This will irreversibly remove all scanned data from the microscope!

Use with extreme caution.

@lt.endpoint('delete', 'scans/{scan_name}', responses={200: {'description': 'Successfully deleted scan'}, 400: {'description': 'An error occurred while trying to delete scan'}})
def delete_scan(self, scan_name: str): (source)

Delete the folder for the specified scan.

This endpoint allows scans to be deleted from disk.

Parameters
scan_name:strThe name of the scan to delete
@lt.action(use_global_lock=False)
def download_zip(self, scan_name: str) -> ZipBlob: (source)

Return zip after including any files left until the end.

The zipfile is returned as a Blob.

def get_gallery_bulk_actions(self) -> list[ActionButton]: (source)

Return the bulk gallery actions for smart scan.

@lt.endpoint('get', 'latest_preview_stitch.jpg', responses={200: {'description': 'A preview-quality stitched image', 'content': {'image/jpeg': {}}}, 404: {'description': 'File not found'}})
def get_latest_preview(self) -> FileResponse: (source)

Retrieve the latest preview image.

@lt.action
def purge_empty_scans(self): (source)

Delete all scan folders containing no images at the top level.

@lt.action
def sample_scan(self, scan_name: str = ''): (source)

Move the stage to cover an area, taking images.

The way the stage moves depends on the selected workflow. If images overlap for a scan workflow then the images can be stitched together into a larger composite image.

@lt.action(use_global_lock=False)
def stitch_all_scans(self): (source)

Check the list of scans, and stitch any that don't have a DZI associated with it.

Raises
RuntimeErrorif the microscope is currently running a scan
@lt.action(use_global_lock=False)
def stitch_scan(self, scan_name: str): (source)

Generate a stitched image based on stage position metadata.

@lt.setting
def workflow_name(self) -> str: (source)

The name of the scan workflow selector.

def workflow_name(self, name: str): (source)

Validate and set workflow_name.

stitch_automatically: bool = (source)

Whether to run a final stitch at the end of a successful scan.

stitch_tiff: bool = (source)

Whether or not to also produce a pyramidal tiff at the end of a scan.

@lt.property
all_workflow_names: list[str] = (source)

Return a list of all available Scan Workflows.

@property
gallery_db_engine: ScanGalleryDBEngine = (source)

The database engine.

@property
latest_preview_stitch_path: str | None = (source)

The path of the latest preview stitched image, or None if not available.

@property
latest_preview_stitch_time: float | None = (source)

The modification time of the latest preview image, to allow live updating.

This will return None (null to JS) if there is no preview image to return.

This is used for two reasons:

  1. If all caching was turned off this stitch would be sent over the network repeatedly
  2. If caching was is on, then the stitch will not update when needed.
@lt.property
latest_scan_live_details: LiveScanDetails | None = (source)

The details of any ongoing scan, or the previous scan if no scan ongoing.

@property
ongoing_scan: ScanDirectory = (source)

The ScanDirectory object of the ongoing scan.

Only read this property is a scan is ongoing or it will raise an error.

@property
scan_data: ActiveScanData = (source)

The ActiveScanData object holding information about the of the ongoing scan.

Only read this property is a scan is ongoing or it will raise an error.

@property
thing_state: Mapping[str, Any] = (source)

Return a metadata dict for ongoing scan to populate.

@lt.property
workflow_display_names: dict[str, str] = (source)

Return a list of the display names of all available Scan Workflows.

def _collect_scan_data(self, workflow: ScanWorkflow) -> ActiveScanData: (source)

Collect and return the data for this scan so it cannot be changed mid-scan.

def _delete_scan(self, scan_name: str) -> bool: (source)

Delete a scan.

def _get_scan_dir(self, scan_name: str) -> ScanDirectory: (source)

Undocumented

def _main_scan_loop(self, workflow: ScanWorkflow): (source)

Run the main loop of the scan.

This loop runs during a scan, until no more scan x,y positions are remaining.

def _manage_stitching_threads(self): (source)

Manage the stitching threads, starting them if needed and not already running.

def _move_to_next_point(self, next_point: tuple[int, int], z_estimate: int | None = None) -> tuple[int, int, int]: (source)

Move the stage to the next position.

If no z_estimate is given then the current stage position is used. Must move to the estimated focused position (although moving below would be marginally faster) because background detect is most reliable at the focused position.

Returns
tuple[int, int, int]the (x,y,z) with the chosen z_estimate
def _perform_final_stitch(self): (source)

Update the scan zip and perform final stitch of the data.

def _return_to_starting_position(self): (source)

Return to the initial scan position, if set.

def _run_scan(self, workflow: ScanWorkflow): (source)

Prepare and run the main scan, and perform final actions on completion.

The result (or exception) from the main scan loop determines whether the scan should be stitched and whether the microscope should return to the starting x,y,z position.

def _save_final_scan_data(self, scan_result: str): (source)

Update scan data JSON file with data only known at the end of the scan.

Takes scan_result, a string that is either "success", "cancelled by user", or the error that ended the scan.

_all_workflows: Mapping[str, ScanWorkflow] = (source)

Undocumented

Undocumented

_class_settings: dict[str, bool] = (source)

Undocumented

Undocumented

_default_workflow = (source)

Undocumented

_gallery_db_engine: ScanGalleryDBEngine | None = (source)

Undocumented

_latest_scan_live_details: LiveScanDetails | None = (source)

Undocumented

_ongoing_scan: ScanDirectory | None = (source)

Undocumented

_preview_stitcher: stitching.PreviewStitcher | None = (source)

Undocumented

_scan_data: ActiveScanData | None = (source)

Undocumented

_scan_lock = (source)

Undocumented

_workflow_name = (source)

Undocumented

@property
_workflow: ScanWorkflow = (source)

The active scan workflow object.