Blackened everything
This commit is contained in:
parent
e213647217
commit
5966ce29be
57 changed files with 1938 additions and 1414 deletions
|
|
@ -7,51 +7,70 @@ from . import capture, record, preview, function
|
|||
|
||||
def construct_blueprint(microscope_obj):
|
||||
|
||||
blueprint = Blueprint('camera_blueprint', __name__)
|
||||
blueprint = Blueprint("camera_blueprint", __name__)
|
||||
|
||||
# Metadata routes
|
||||
blueprint.add_url_rule(
|
||||
'/capture/<capture_id>/metadata/<filename>',
|
||||
view_func=capture.MetadataAPI.as_view('metadata_download', microscope=microscope_obj))
|
||||
"/capture/<capture_id>/metadata/<filename>",
|
||||
view_func=capture.MetadataAPI.as_view(
|
||||
"metadata_download", microscope=microscope_obj
|
||||
),
|
||||
)
|
||||
|
||||
blueprint.add_url_rule(
|
||||
'/capture/<capture_id>/metadata',
|
||||
view_func=capture.MetadataRedirectAPI.as_view('metadata_download_redirect', microscope=microscope_obj))
|
||||
"/capture/<capture_id>/metadata",
|
||||
view_func=capture.MetadataRedirectAPI.as_view(
|
||||
"metadata_download_redirect", microscope=microscope_obj
|
||||
),
|
||||
)
|
||||
|
||||
# Tag routes
|
||||
blueprint.add_url_rule(
|
||||
'/capture/<capture_id>/tags',
|
||||
view_func=capture.TagsAPI.as_view('capture_tags', microscope=microscope_obj))
|
||||
"/capture/<capture_id>/tags",
|
||||
view_func=capture.TagsAPI.as_view("capture_tags", microscope=microscope_obj),
|
||||
)
|
||||
|
||||
# Capture routes
|
||||
blueprint.add_url_rule(
|
||||
'/capture/<capture_id>/download/<filename>',
|
||||
view_func=capture.DownloadAPI.as_view('capture_download', microscope=microscope_obj))
|
||||
"/capture/<capture_id>/download/<filename>",
|
||||
view_func=capture.DownloadAPI.as_view(
|
||||
"capture_download", microscope=microscope_obj
|
||||
),
|
||||
)
|
||||
|
||||
blueprint.add_url_rule(
|
||||
'/capture/<capture_id>/download',
|
||||
view_func=capture.DownloadRedirectAPI.as_view('capture_download_redirect', microscope=microscope_obj))
|
||||
"/capture/<capture_id>/download",
|
||||
view_func=capture.DownloadRedirectAPI.as_view(
|
||||
"capture_download_redirect", microscope=microscope_obj
|
||||
),
|
||||
)
|
||||
|
||||
blueprint.add_url_rule(
|
||||
'/capture/<capture_id>/',
|
||||
view_func=capture.CaptureAPI.as_view('capture', microscope=microscope_obj))
|
||||
"/capture/<capture_id>/",
|
||||
view_func=capture.CaptureAPI.as_view("capture", microscope=microscope_obj),
|
||||
)
|
||||
|
||||
blueprint.add_url_rule(
|
||||
'/capture/',
|
||||
view_func=capture.ListAPI.as_view('capture_list', microscope=microscope_obj))
|
||||
"/capture/",
|
||||
view_func=capture.ListAPI.as_view("capture_list", microscope=microscope_obj),
|
||||
)
|
||||
|
||||
# Preview routes
|
||||
blueprint.add_url_rule(
|
||||
'/preview/<string:operation>',
|
||||
view_func=preview.GPUPreviewAPI.as_view('gpu_preview', microscope=microscope_obj))
|
||||
"/preview/<string:operation>",
|
||||
view_func=preview.GPUPreviewAPI.as_view(
|
||||
"gpu_preview", microscope=microscope_obj
|
||||
),
|
||||
)
|
||||
|
||||
# Function routes
|
||||
blueprint.add_url_rule(
|
||||
'/overlay',
|
||||
view_func=function.OverlayAPI.as_view('overlay', microscope=microscope_obj))
|
||||
"/overlay",
|
||||
view_func=function.OverlayAPI.as_view("overlay", microscope=microscope_obj),
|
||||
)
|
||||
|
||||
blueprint.add_url_rule(
|
||||
'/zoom',
|
||||
view_func=function.ZoomAPI.as_view('zoom', microscope=microscope_obj))
|
||||
"/zoom", view_func=function.ZoomAPI.as_view("zoom", microscope=microscope_obj)
|
||||
)
|
||||
|
||||
return(blueprint)
|
||||
return blueprint
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ from flask import Response, jsonify, request, abort, url_for, redirect, send_fil
|
|||
|
||||
|
||||
class ListAPI(MicroscopeView):
|
||||
|
||||
def get(self):
|
||||
"""
|
||||
Get list of image captures.
|
||||
|
|
@ -30,12 +29,16 @@ class ListAPI(MicroscopeView):
|
|||
:status 200: capture found
|
||||
:status 404: no capture found with that id
|
||||
"""
|
||||
include_unavailable = get_bool(request.args.get('include_unavailable'))
|
||||
include_unavailable = get_bool(request.args.get("include_unavailable"))
|
||||
|
||||
if include_unavailable:
|
||||
captures = [image.state for image in self.microscope.camera.images]
|
||||
else:
|
||||
captures = [image.state for image in self.microscope.camera.images if image.state['available']]
|
||||
captures = [
|
||||
image.state
|
||||
for image in self.microscope.camera.images
|
||||
if image.state["available"]
|
||||
]
|
||||
|
||||
return jsonify(captures)
|
||||
|
||||
|
|
@ -100,38 +103,40 @@ class ListAPI(MicroscopeView):
|
|||
"""
|
||||
payload = JsonResponse(request)
|
||||
|
||||
filename = payload.param('filename')
|
||||
temporary = payload.param('temporary', default=False, convert=bool)
|
||||
use_video_port = payload.param('use_video_port', default=False, convert=bool)
|
||||
bayer = payload.param('bayer', default=True, convert=bool)
|
||||
metadata = payload.param('metadata', default={}, convert=dict)
|
||||
tags = payload.param('tags', default=[], convert=list)
|
||||
filename = payload.param("filename")
|
||||
temporary = payload.param("temporary", default=False, convert=bool)
|
||||
use_video_port = payload.param("use_video_port", default=False, convert=bool)
|
||||
bayer = payload.param("bayer", default=True, convert=bool)
|
||||
metadata = payload.param("metadata", default={}, convert=dict)
|
||||
tags = payload.param("tags", default=[], convert=list)
|
||||
|
||||
resize = payload.param('size', default=None)
|
||||
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
|
||||
if ("width" in resize) and ("height" in resize):
|
||||
resize = (
|
||||
int(resize["width"]),
|
||||
int(resize["height"]),
|
||||
) # Convert dict to tuple
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
# Explicitally acquire lock (prevents empty files being created if lock is unavailable)
|
||||
with self.microscope.camera.lock:
|
||||
output = self.microscope.camera.new_image(
|
||||
write_to_file=True,
|
||||
temporary=temporary,
|
||||
filename=filename)
|
||||
write_to_file=True, temporary=temporary, filename=filename
|
||||
)
|
||||
|
||||
self.microscope.camera.capture(
|
||||
output,
|
||||
use_video_port=use_video_port,
|
||||
resize=resize,
|
||||
bayer=bayer)
|
||||
output, use_video_port=use_video_port, resize=resize, bayer=bayer
|
||||
)
|
||||
|
||||
metadata.update({
|
||||
'position': self.microscope.state['stage']['position'],
|
||||
'microscope_id': self.microscope.id,
|
||||
'microscope_name': self.microscope.name
|
||||
})
|
||||
metadata.update(
|
||||
{
|
||||
"position": self.microscope.state["stage"]["position"],
|
||||
"microscope_id": self.microscope.id,
|
||||
"microscope_name": self.microscope.name,
|
||||
}
|
||||
)
|
||||
|
||||
output.put_metadata(metadata)
|
||||
output.put_tags(tags)
|
||||
|
|
@ -140,7 +145,6 @@ class ListAPI(MicroscopeView):
|
|||
|
||||
|
||||
class CaptureAPI(MicroscopeView):
|
||||
|
||||
def get(self, capture_id):
|
||||
"""
|
||||
Get JSON representation of a capture
|
||||
|
|
@ -200,14 +204,15 @@ class CaptureAPI(MicroscopeView):
|
|||
|
||||
# Add API routes to returned state
|
||||
uri_dict = {
|
||||
'uri': {'state': '{}'.format(url_for('.capture', capture_id=capture_obj.id))}
|
||||
"uri": {
|
||||
"state": "{}".format(url_for(".capture", capture_id=capture_obj.id))
|
||||
}
|
||||
}
|
||||
|
||||
# If available, also add download link
|
||||
if capture_metadata['available']:
|
||||
uri_dict['uri']['download'] = '{}download/{}'.format(
|
||||
url_for('.capture', capture_id=capture_obj.id),
|
||||
capture_obj.filename
|
||||
if capture_metadata["available"]:
|
||||
uri_dict["uri"]["download"] = "{}download/{}".format(
|
||||
url_for(".capture", capture_id=capture_obj.id), capture_obj.filename
|
||||
)
|
||||
|
||||
capture_metadata.update(uri_dict)
|
||||
|
|
@ -257,7 +262,7 @@ class CaptureAPI(MicroscopeView):
|
|||
|
||||
if not capture_obj:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
|
||||
data_dict = JsonResponse(request).json
|
||||
|
||||
capture_obj.put_metadata(data_dict)
|
||||
|
|
@ -299,17 +304,20 @@ class DownloadRedirectAPI(MicroscopeView):
|
|||
"""
|
||||
capture_obj = self.microscope.camera.image_from_id(capture_id)
|
||||
|
||||
if not capture_obj or not capture_obj.state['available']:
|
||||
if not capture_obj or not capture_obj.state["available"]:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
thumbnail = get_bool(request.args.get('thumbnail'))
|
||||
thumbnail = get_bool(request.args.get("thumbnail"))
|
||||
|
||||
return redirect(url_for(
|
||||
'.capture_download',
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.filename,
|
||||
thumbnail=thumbnail
|
||||
), code=307)
|
||||
return redirect(
|
||||
url_for(
|
||||
".capture_download",
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.filename,
|
||||
thumbnail=thumbnail,
|
||||
),
|
||||
code=307,
|
||||
)
|
||||
|
||||
|
||||
class DownloadAPI(MicroscopeView):
|
||||
|
|
@ -317,19 +325,22 @@ class DownloadAPI(MicroscopeView):
|
|||
|
||||
capture_obj = self.microscope.camera.image_from_id(capture_id)
|
||||
|
||||
if not capture_obj or not capture_obj.state['available']:
|
||||
if not capture_obj or not capture_obj.state["available"]:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
thumbnail = get_bool(request.args.get('thumbnail'))
|
||||
thumbnail = get_bool(request.args.get("thumbnail"))
|
||||
|
||||
# If no filename is specified, redirect to the capture's currently set filename
|
||||
if not filename:
|
||||
return redirect(url_for(
|
||||
'capture_download',
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.filename,
|
||||
thumbnail=thumbnail
|
||||
), code=307)
|
||||
return redirect(
|
||||
url_for(
|
||||
"capture_download",
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.filename,
|
||||
thumbnail=thumbnail,
|
||||
),
|
||||
code=307,
|
||||
)
|
||||
|
||||
# Download the image data using the requested filename
|
||||
if thumbnail:
|
||||
|
|
@ -337,9 +348,7 @@ class DownloadAPI(MicroscopeView):
|
|||
else:
|
||||
img = capture_obj.data
|
||||
|
||||
return send_file(
|
||||
img,
|
||||
mimetype='image/jpeg')
|
||||
return send_file(img, mimetype="image/jpeg")
|
||||
|
||||
|
||||
class MetadataRedirectAPI(MicroscopeView):
|
||||
|
|
@ -374,14 +383,17 @@ class MetadataRedirectAPI(MicroscopeView):
|
|||
"""
|
||||
capture_obj = self.microscope.camera.image_from_id(capture_id)
|
||||
|
||||
if not capture_obj or not capture_obj.state['available']:
|
||||
if not capture_obj or not capture_obj.state["available"]:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
return redirect(url_for(
|
||||
'.metadata_download',
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.metadataname
|
||||
), code=307)
|
||||
return redirect(
|
||||
url_for(
|
||||
".metadata_download",
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.metadataname,
|
||||
),
|
||||
code=307,
|
||||
)
|
||||
|
||||
|
||||
class MetadataAPI(MicroscopeView):
|
||||
|
|
@ -389,23 +401,24 @@ class MetadataAPI(MicroscopeView):
|
|||
|
||||
capture_obj = self.microscope.camera.image_from_id(capture_id)
|
||||
|
||||
if not capture_obj or not capture_obj.state['available']:
|
||||
if not capture_obj or not capture_obj.state["available"]:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
# If no filename is specified, redirect to the capture's currently set filename
|
||||
if not filename:
|
||||
return redirect(url_for(
|
||||
'capture_download',
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.metadataname
|
||||
), code=307)
|
||||
return redirect(
|
||||
url_for(
|
||||
"capture_download",
|
||||
capture_id=capture_id,
|
||||
filename=capture_obj.metadataname,
|
||||
),
|
||||
code=307,
|
||||
)
|
||||
|
||||
# Download the metadata using the requested filename
|
||||
data = capture_obj.yaml
|
||||
|
||||
return Response(
|
||||
data,
|
||||
mimetype="text/yaml")
|
||||
return Response(data, mimetype="text/yaml")
|
||||
|
||||
|
||||
class TagsAPI(MicroscopeView):
|
||||
|
|
@ -430,13 +443,13 @@ class TagsAPI(MicroscopeView):
|
|||
"""
|
||||
capture_obj = self.microscope.camera.image_from_id(capture_id)
|
||||
|
||||
if not capture_obj or not capture_obj.state['available']:
|
||||
if not capture_obj or not capture_obj.state["available"]:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
metadata_tags = filter_dict(capture_obj.state, ['metadata', 'tags'])
|
||||
metadata_tags = filter_dict(capture_obj.state, ["metadata", "tags"])
|
||||
|
||||
return jsonify(metadata_tags)
|
||||
|
||||
|
||||
def put(self, capture_id):
|
||||
"""
|
||||
Add tags to the capture
|
||||
|
|
@ -460,9 +473,9 @@ class TagsAPI(MicroscopeView):
|
|||
|
||||
capture_obj = self.microscope.camera.image_from_id(capture_id)
|
||||
|
||||
if not capture_obj or not capture_obj.state['available']:
|
||||
if not capture_obj or not capture_obj.state["available"]:
|
||||
return abort(404) # 404 Not Found
|
||||
|
||||
|
||||
data_dict = JsonResponse(request).json
|
||||
|
||||
if type(data_dict) != list:
|
||||
|
|
@ -470,7 +483,7 @@ class TagsAPI(MicroscopeView):
|
|||
|
||||
capture_obj.put_tags(data_dict)
|
||||
|
||||
metadata_tags = filter_dict(capture_obj.state, ['metadata', 'tags'])
|
||||
metadata_tags = filter_dict(capture_obj.state, ["metadata", "tags"])
|
||||
|
||||
return jsonify(metadata_tags)
|
||||
|
||||
|
|
@ -507,6 +520,6 @@ class TagsAPI(MicroscopeView):
|
|||
for tag in data_dict:
|
||||
capture_obj.delete_tag(str(tag))
|
||||
|
||||
metadata_tags = filter_dict(capture_obj.state, ['metadata', 'tags'])
|
||||
metadata_tags = filter_dict(capture_obj.state, ["metadata", "tags"])
|
||||
|
||||
return jsonify(metadata_tags)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ from flask import jsonify, request
|
|||
|
||||
|
||||
class ZoomAPI(MicroscopeView):
|
||||
|
||||
def get(self):
|
||||
"""
|
||||
Get the current zoom value
|
||||
|
|
@ -17,9 +16,9 @@ class ZoomAPI(MicroscopeView):
|
|||
:<header Content-Type: application/json
|
||||
:status 200: preview started/stopped
|
||||
"""
|
||||
zoom_value = self.microscope.camera.state['zoom_value']
|
||||
zoom_value = self.microscope.camera.state["zoom_value"]
|
||||
|
||||
return jsonify({'zoom_value': zoom_value})
|
||||
return jsonify({"zoom_value": zoom_value})
|
||||
|
||||
def post(self):
|
||||
"""
|
||||
|
|
@ -44,7 +43,7 @@ class ZoomAPI(MicroscopeView):
|
|||
:status 200: preview started/stopped
|
||||
"""
|
||||
payload = JsonResponse(request)
|
||||
zoom_value = payload.param('zoom_value', default=1.0, convert=float)
|
||||
zoom_value = payload.param("zoom_value", default=1.0, convert=float)
|
||||
|
||||
self.microscope.camera.set_zoom(zoom_value)
|
||||
|
||||
|
|
@ -52,7 +51,6 @@ class ZoomAPI(MicroscopeView):
|
|||
|
||||
|
||||
class OverlayAPI(MicroscopeView):
|
||||
|
||||
def get(self):
|
||||
"""
|
||||
Get overlay text
|
||||
|
|
@ -67,7 +65,7 @@ class OverlayAPI(MicroscopeView):
|
|||
text = self.microscope.camera.camera.annotate_text
|
||||
size = self.microscope.camera.camera.annotate_text_size
|
||||
|
||||
return jsonify({'text': text, 'size': size})
|
||||
return jsonify({"text": text, "size": size})
|
||||
|
||||
def post(self):
|
||||
"""
|
||||
|
|
@ -94,10 +92,10 @@ class OverlayAPI(MicroscopeView):
|
|||
"""
|
||||
|
||||
payload = JsonResponse(request)
|
||||
text = payload.param('text', default="", convert=str)
|
||||
size = payload.param('size', default=50, convert=int)
|
||||
text = payload.param("text", default="", convert=str)
|
||||
size = payload.param("size", default=50, convert=int)
|
||||
|
||||
self.microscope.camera.camera.annotate_text = text
|
||||
self.microscope.camera.camera.annotate_text_size = size
|
||||
|
||||
return jsonify({'text': text, 'size': size})
|
||||
return jsonify({"text": text, "size": size})
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import logging
|
|||
|
||||
|
||||
class GPUPreviewAPI(MicroscopeView):
|
||||
|
||||
def post(self, operation):
|
||||
"""
|
||||
Start or stop the onboard GPU preview.
|
||||
|
|
@ -39,7 +38,7 @@ class GPUPreviewAPI(MicroscopeView):
|
|||
if operation == "start":
|
||||
payload = JsonResponse(request)
|
||||
|
||||
window = payload.param('window', default=[])
|
||||
window = payload.param("window", default=[])
|
||||
logging.debug(window)
|
||||
|
||||
if len(window) != 4:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue