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 | __init__ |
Initialise a SmartScanThing saving to and loading from the input directory. |
| Method | delete |
Delete all the scans on the microscope. |
| Method | delete |
Delete the folder for the specified scan. |
| Method | download |
Return zip after including any files left until the end. |
| Method | get |
Retrieve the latest preview image. |
| Method | get |
Retrieve a file from a scan. |
| Method | get |
Return the stitched image corresponding to a given scan name, if it exists. |
| Method | purge |
Delete all scan folders containing no images at the top level. |
| Method | sample |
Move the stage to cover an area, taking images that can be tiled together. |
| Method | stitch |
Check the list of scans, and stitch any that don't have a DZI associated with it. |
| Method | stitch |
Generate a stitched image based on stage position metadata. |
| Class Variable | autofocus |
The z distance to perform an autofocus in steps. |
| Class Variable | max |
The maximum distance in steps from the centre of the scan. |
| Class Variable | overlap |
The fraction (0-1) that adjacent images should overlap in x or y. |
| Class Variable | save |
A tuple of the image resolution to capture. |
| Class Variable | skip |
Whether to detect and skip empty fields of view. |
| Class Variable | stitch |
Whether to run a final stitch at the end of a successful scan. |
| Class Variable | stitch |
Whether or not to also produce a pyramidal tiff at the end of a scan. |
| Property | latest |
The path of the latest preview stitched image, or None if not available. |
| Property | latest |
The modification time of the latest preview image, to allow live updating. |
| Property | latest |
The name of the last scan to be started. |
| Property | scans |
All the available scans. |
| Method | _calc |
Take a test image and use camera stage mapping to calculate x and y displacement. |
| Method | _check |
Before starting a scan, check that background and camera-stage-mapping are set. |
| Method | _collect |
Collect and return the data for this scan so it cannot be changed mid-scan. |
| Method | _delete |
Delete a scan. |
| Method | _main |
Run the main loop of the scan. |
| Method | _manage |
Manage the stitching threads, starting them if needed and not already running. |
| Method | _move |
Move the stage to the next position. |
| Method | _perform |
Update the scan zip and perform final stitch of the data. |
| Method | _return |
Return to the initial scan position, if set. |
| Method | _run |
Prepare and run the main scan, and perform final actions on completion. |
| Method | _save |
Update scan data JSON file with data only known at the end of the scan. |
| Instance Variable | _autofocus |
Undocumented |
| Instance Variable | _cam |
Undocumented |
| Instance Variable | _cancel |
Undocumented |
| Instance Variable | _csm |
Undocumented |
| Instance Variable | _latest |
Undocumented |
| Instance Variable | _ongoing |
Undocumented |
| Instance Variable | _preview |
Undocumented |
| Instance Variable | _scan |
Undocumented |
| Instance Variable | _scan |
Undocumented |
| Instance Variable | _scan |
Undocumented |
| Instance Variable | _scan |
Undocumented |
| Instance Variable | _stage |
Undocumented |
Initialise a SmartScanThing saving to and loading from the input directory.
| Parameters | |
scansstr | This 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. |
lt.deps.InvocationLogger):
(source)
¶
Delete all the scans on the microscope.
This will irreversibly remove all scanned data from the microscope! Use with extreme caution.
str, logger: lt.deps.InvocationLogger):
(source)
¶
Delete the folder for the specified scan.
This endpoint allows scans to be deleted from disk.
Takes the scan name to delete, and the Invocation Logger
FileResponse:
(source)
¶
Retrieve the latest preview image.
str) -> FileResponse:
(source)
¶
Retrieve a file from a scan.
This endpoint allows files to be downloaded from a scan.
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.deps.CancelHook, logger: lt.deps.InvocationLogger, autofocus: AutofocusDep, stage: StageDep, cam: CameraClient, csm: CSMDep, scan_name: str = ''):
(source)
¶
Move the stage to cover an area, taking images that can be tiled together.
The stage will move in a pattern that grows outwards from the starting point, stopping once it is surrounded by "background" (as detected by the camera Thing) or reaches the "max_range" measured in steps.
lt.deps.InvocationLogger, cancel: lt.deps.CancelHook):
(source)
¶
Check the list of scans, and stitch any that don't have a DZI associated with it.
| Raises | |
RuntimeError | if the microscope is currently running a scan |
lt.deps.InvocationLogger, cancel: lt.deps.CancelHook, scan_name: str, correlation_resize: float | None = None, overlap: float | None = None):
(source)
¶
Generate a stitched image based on stage position metadata.
Note that as this is a lt.thing_action it needs the logger passed as a variable if called from another thing action
Whether to detect and skip empty fields of view.
This uses the settings from the BackgroundDetectThing.
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:
- If all caching was turned off this stitch would be sent over the network repeatedly
- If caching was is on, then the stitch will not update when needed.
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.
Take a test image and use camera stage mapping to calculate x and y displacement.
| Parameters | |
overlap:int | The desired overlap as a fraction of the image. i.e. 0.5 means that each image should overlap its nearest neighbour by 50%. |
| Returns | |
tuple[ | (dx, dy) - the x and y displacements in steps |
Before starting a scan, check that background and camera-stage-mapping are set.
- Raise error if:
- background is to be skipped but is not set
- camera stage mapping is not set
Raise warning if not using background detect that scan will go on until max steps reached
Delete a scan.
This is a wrapper around scan manager's delete_scan that logs to the invocation logger id there is a problem.
Run the main loop of the scan.
This loop runs during a scan, until no more scan x,y positions are remaining.
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[ | the (x,y,z) with the chosen z_estimate |
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.