Added scan API routes

This commit is contained in:
Joel Collins 2019-03-07 09:54:43 +00:00
parent d10263adf8
commit 298bc2ba6a
2 changed files with 93 additions and 1 deletions

View file

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