diff --git a/openflexure_microscope/plugins/default/scan/api.py b/openflexure_microscope/plugins/default/scan/api.py new file mode 100644 index 00000000..97d18c45 --- /dev/null +++ b/openflexure_microscope/plugins/default/scan/api.py @@ -0,0 +1,87 @@ +import numpy as np + +from openflexure_microscope.api.v1.views import MicroscopeViewPlugin +from openflexure_microscope.api.utilities import JsonPayload + +from flask import request, jsonify, abort + + +class TileScanAPI(MicroscopeViewPlugin): + def post(self): + payload = JsonPayload(request) + + # Get params + name = payload.param('name') + step_size = payload.param('step_size', default=[2000, 1500], convert=list) + grid = payload.param('grid', default=[3, 3], convert=list) + autofocus_dz = payload.param('autofocus_dz', default=20, convert=int) + + use_video_port = payload.param('use_video_port', default=False, convert=bool) + resize = payload.param('size', default=None) + if resize: + if ('width' in resize) and ('height' in resize): + resize = (int(resize['width']), int(resize['height'])) # Convert dict to tuple + else: + abort(404) + + bayer = payload.param('bayer', default=True, convert=bool) + metadata = payload.param('metadata', default={}, convert=dict) + tags = payload.param('tags', default=[], convert=list) + + print("Running tile scan...") + task = self.microscope.task.start( + self.plugin.tile, + basename = name, + step_size = step_size, + grid = grid, + autofocus_dz = autofocus_dz, + use_video_port = use_video_port, + resize = resize, + bayer = bayer, + metadata = metadata, + tags = tags + ) + + # return a handle on the autofocus task + return jsonify(task.state, 202) + + + +class ZStackAPI(MicroscopeViewPlugin): + def post(self): + payload = JsonPayload(request) + + # Get params + name = payload.param('name') + step_size = payload.param('step_size', default=[2000, 1500], convert=list) + steps = payload.param('steps', default=5, convert=int) + center = payload.param('center', default=True, convert=bool) + + use_video_port = payload.param('use_video_port', default=False, convert=bool) + resize = payload.param('size', default=None) + if resize: + if ('width' in resize) and ('height' in resize): + resize = (int(resize['width']), int(resize['height'])) # Convert dict to tuple + else: + abort(404) + + bayer = payload.param('bayer', default=True, convert=bool) + metadata = payload.param('metadata', default={}, convert=dict) + tags = payload.param('tags', default=[], convert=list) + + print("Running tile scan...") + task = self.microscope.task.start( + self.plugin.stack, + basename = name, + step_size = step_size, + steps = steps, + center = center, + use_video_port = use_video_port, + resize = resize, + bayer = bayer, + metadata = metadata, + tags = tags + ) + + # return a handle on the autofocus task + return jsonify(task.state, 202) \ No newline at end of file diff --git a/openflexure_microscope/plugins/default/scan/plugin.py b/openflexure_microscope/plugins/default/scan/plugin.py index ab31e125..5fe1273a 100644 --- a/openflexure_microscope/plugins/default/scan/plugin.py +++ b/openflexure_microscope/plugins/default/scan/plugin.py @@ -7,13 +7,18 @@ from openflexure_microscope.camera.base import generate_basename from openflexure_microscope.plugins import MicroscopePlugin from openflexure_microscope.utilities import set_properties +from .api import TileScanAPI, ZStackAPI class ScanPlugin(MicroscopePlugin): """ Stack and tile plugin """ - api_views = {} + api_views = { + '/tile': TileScanAPI, + '/stack': ZStackAPI, + } + def capture(self, basename,