Restructured scan extension
This commit is contained in:
parent
43c16f1b76
commit
677b08d509
1 changed files with 176 additions and 185 deletions
|
|
@ -8,12 +8,12 @@ from functools import reduce
|
||||||
from openflexure_microscope.captures.capture_manager import generate_basename
|
from openflexure_microscope.captures.capture_manager import generate_basename
|
||||||
from labthings.server.find import find_component, find_extension
|
from labthings.server.find import find_component, find_extension
|
||||||
from labthings.server.extensions import BaseExtension
|
from labthings.server.extensions import BaseExtension
|
||||||
from labthings.server.decorators import use_args, ThingAction
|
from labthings.server.decorators import use_args
|
||||||
from labthings.server import fields
|
from labthings.server import fields
|
||||||
|
|
||||||
from openflexure_microscope.devel import abort, update_task_progress
|
from openflexure_microscope.devel import abort, update_task_progress
|
||||||
|
|
||||||
from labthings.server.view import View
|
from labthings.server.view import View, ActionView
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -54,18 +54,6 @@ def flatten_grid(grid):
|
||||||
return grid
|
return grid
|
||||||
|
|
||||||
|
|
||||||
### Progress
|
|
||||||
|
|
||||||
_images_to_be_captured: int = 1
|
|
||||||
_images_captured_so_far: int = 0
|
|
||||||
|
|
||||||
|
|
||||||
def progress():
|
|
||||||
progress = (_images_captured_so_far / _images_to_be_captured) * 100
|
|
||||||
logging.info(progress)
|
|
||||||
return progress
|
|
||||||
|
|
||||||
|
|
||||||
### Capturing
|
### Capturing
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -99,10 +87,20 @@ def capture(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ScanExtension(BaseExtension):
|
||||||
|
def __init__(self):
|
||||||
|
self._images_to_be_captured: int = 1
|
||||||
|
self._images_captured_so_far: int = 0
|
||||||
|
return BaseExtension.__init__(self, "org.openflexure.scan", version="2.0.0")
|
||||||
|
|
||||||
|
def progress(self):
|
||||||
|
progress = (self._images_captured_so_far / self._images_to_be_captured) * 100
|
||||||
|
logging.info(progress)
|
||||||
|
return progress
|
||||||
|
|
||||||
### Scanning
|
### Scanning
|
||||||
|
|
||||||
|
|
||||||
def tile(
|
def tile(
|
||||||
|
self,
|
||||||
microscope,
|
microscope,
|
||||||
basename: str = None,
|
basename: str = None,
|
||||||
temporary: bool = False,
|
temporary: bool = False,
|
||||||
|
|
@ -118,12 +116,9 @@ def tile(
|
||||||
annotations: dict = {},
|
annotations: dict = {},
|
||||||
tags: list = [],
|
tags: list = [],
|
||||||
):
|
):
|
||||||
global _images_to_be_captured
|
|
||||||
global _images_captured_so_far
|
|
||||||
|
|
||||||
# Keep task progress
|
# Keep task progress
|
||||||
_images_to_be_captured = reduce((lambda x, y: x * y), grid)
|
self._images_to_be_captured = reduce((lambda x, y: x * y), grid)
|
||||||
_images_captured_so_far = 0
|
self._images_captured_so_far = 0
|
||||||
|
|
||||||
# Generate a basename if none given
|
# Generate a basename if none given
|
||||||
if not basename:
|
if not basename:
|
||||||
|
|
@ -210,11 +205,11 @@ def tile(
|
||||||
tags=tags,
|
tags=tags,
|
||||||
)
|
)
|
||||||
# Update task progress
|
# Update task progress
|
||||||
_images_captured_so_far += 1
|
self._images_captured_so_far += 1
|
||||||
update_task_progress(progress())
|
update_task_progress(self.progress())
|
||||||
else:
|
else:
|
||||||
logging.debug("Entering z-stack")
|
logging.debug("Entering z-stack")
|
||||||
stack(
|
self.stack(
|
||||||
microscope=microscope,
|
microscope=microscope,
|
||||||
basename=basename,
|
basename=basename,
|
||||||
temporary=temporary,
|
temporary=temporary,
|
||||||
|
|
@ -235,6 +230,7 @@ def tile(
|
||||||
|
|
||||||
|
|
||||||
def stack(
|
def stack(
|
||||||
|
self,
|
||||||
microscope,
|
microscope,
|
||||||
basename: str = None,
|
basename: str = None,
|
||||||
temporary: bool = False,
|
temporary: bool = False,
|
||||||
|
|
@ -248,7 +244,6 @@ def stack(
|
||||||
annotations: dict = {},
|
annotations: dict = {},
|
||||||
tags: list = [],
|
tags: list = [],
|
||||||
):
|
):
|
||||||
global _images_captured_so_far
|
|
||||||
|
|
||||||
# Store initial position
|
# Store initial position
|
||||||
initial_position = microscope.stage.position
|
initial_position = microscope.stage.position
|
||||||
|
|
@ -275,8 +270,8 @@ def stack(
|
||||||
tags=tags,
|
tags=tags,
|
||||||
)
|
)
|
||||||
# Update task progress
|
# Update task progress
|
||||||
_images_captured_so_far += 1
|
self._images_captured_so_far += 1
|
||||||
update_task_progress(progress())
|
update_task_progress(self.progress())
|
||||||
|
|
||||||
if i != steps - 1:
|
if i != steps - 1:
|
||||||
logging.debug("Moving z by {}".format(step_size))
|
logging.debug("Moving z by {}".format(step_size))
|
||||||
|
|
@ -286,11 +281,9 @@ def stack(
|
||||||
microscope.stage.move_abs(initial_position)
|
microscope.stage.move_abs(initial_position)
|
||||||
|
|
||||||
|
|
||||||
### Web views
|
scan_extension_v2 = ScanExtension()
|
||||||
|
|
||||||
|
class TileScanAPI(ActionView):
|
||||||
@ThingAction
|
|
||||||
class TileScanAPI(View):
|
|
||||||
@use_args(
|
@use_args(
|
||||||
{
|
{
|
||||||
"filename": fields.String(missing=None, example=None),
|
"filename": fields.String(missing=None, example=None),
|
||||||
|
|
@ -328,7 +321,7 @@ class TileScanAPI(View):
|
||||||
logging.info("Running tile scan...")
|
logging.info("Running tile scan...")
|
||||||
|
|
||||||
# return a handle on the scan task
|
# return a handle on the scan task
|
||||||
return tile(
|
return scan_extension_v2.tile(
|
||||||
microscope,
|
microscope,
|
||||||
basename=args.get("filename"),
|
basename=args.get("filename"),
|
||||||
temporary=args.get("temporary"),
|
temporary=args.get("temporary"),
|
||||||
|
|
@ -345,6 +338,4 @@ class TileScanAPI(View):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
scan_extension_v2 = BaseExtension("org.openflexure.scan", version="2.0.0")
|
|
||||||
|
|
||||||
scan_extension_v2.add_view(TileScanAPI, "/tile", endpoint="tile")
|
scan_extension_v2.add_view(TileScanAPI, "/tile", endpoint="tile")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue