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_scans 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_latest_preview Retrieve the latest preview image.
Method get_scan_thumbnail Retrieve a file from a scan.
Method get_stitch_file Return the stitched image corresponding to a given scan name, if it exists.
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 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_name The name of the last scan to be started.
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 scans All the available scans.
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_all_scan_info Return all the information from the scan directories.
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 _stage Undocumented
Instance Variable _default_workflow Undocumented
Instance Variable _latest_scan_name Undocumented
Instance Variable _ongoing_scan Undocumented
Instance Variable _preview_stitcher Undocumented
Instance Variable _scan_data Undocumented
Instance Variable _scan_dir_manager Undocumented
Instance Variable _scan_lock Undocumented
Instance Variable _workflow_name Undocumented
Property _workflow The active scan workflow object.
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.

In this case it doesn't need to do anything.

def __init__(self, thing_server_interface: lt.ThingServerInterface, scans_folder: str, default_workflow: str): (source)

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

Parameters
thing_server_interface:lt.ThingServerInterfaceUndocumented
scans_folder:strThis is the path to the directory where all scans will be saved. Any scans already in this directory will be accessible through the HTTP interface.
default_workflow:strUndocumented
@lt.endpoint('delete', 'scans')
def delete_all_scans(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
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.

@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.endpoint('get', 'scans/stitched_thumbnail.jpg', responses={200: {'description': 'A thumbnail-quality stitched image', 'content': {'image/jpeg': {}}}, 404: {'description': 'File not found'}})
def get_scan_thumbnail(self, scan_name: str) -> FileResponse: (source)

Retrieve a file from a scan.

This endpoint allows files to be downloaded from a scan.

@lt.endpoint('get', 'get_stitch/{scan_name}', responses={200: {'description': 'Successfully downloading file', 'content': {'*/*': {}}}, 403: {'description': 'Filename not permitted'}, 404: {'description': 'File not found'}})
def get_stitch_file(self, scan_name: str) -> FileResponse: (source)

Return the stitched image corresponding to a given scan name, if it exists.

Will only return a file ending in suffix STITCH_SUFFIX Note: when downloading this, the default filename will be scan_name.jpeg

@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
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
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
latest_preview_stitch_path: str | None = (source)

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

@lt.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_name: str | None = (source)

The name of the last scan to be started.

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.

@lt.property
scans: ScanListInfo = (source)

All the available scans.

Each scan has a name (which can be used to access it), along with its modified and created times (according to the filesystem) and the number of items in the images folder. Note that image count uses a regular expression, and changes to the naming scheme will break it.

@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.

This is a wrapper around scan manager's delete_scan that logs to the things logger if there is a problem.

def _get_all_scan_info(self) -> list[scan_directories.ScanInfo]: (source)

Return all the information from the scan directories.

It is preferable to use the method rather than calling _scan_dir_manager.all_scans_info() directly as it will handle stopping the json in any ongoing scans being read.

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

Undocumented

_default_workflow = (source)

Undocumented

_latest_scan_name: str | None = (source)

Undocumented

Undocumented

_preview_stitcher: stitching.PreviewStitcher | None = (source)

Undocumented

_scan_data: ActiveScanData | None = (source)

Undocumented

_scan_dir_manager = (source)

Undocumented

_scan_lock = (source)

Undocumented

_workflow_name = (source)

Undocumented

@property
_workflow: ScanWorkflow = (source)

The active scan workflow object.