Code formatting

This commit is contained in:
Joel Collins 2020-10-13 15:02:19 +01:00
parent 0234b20ce3
commit 2bfb988460
60 changed files with 392 additions and 396 deletions

View file

@ -1,5 +1,5 @@
from labthings.extensions import BaseExtension
from labthings import find_component from labthings import find_component
from labthings.extensions import BaseExtension
def identify(): def identify():

View file

@ -1,5 +1,5 @@
from labthings.extensions import BaseExtension
from labthings import find_component from labthings import find_component
from labthings.extensions import BaseExtension
# Create the extension class # Create the extension class

View file

@ -1,5 +1,5 @@
from labthings import fields, find_component
from labthings.extensions import BaseExtension from labthings.extensions import BaseExtension
from labthings import find_component, fields
from labthings.views import View from labthings.views import View
## Extension methods ## Extension methods
@ -41,7 +41,7 @@ class ExampleIdentifyView(View):
class ExampleRenameView(View): class ExampleRenameView(View):
# Expect a request parameter called "name", which is a string. # Expect a request parameter called "name", which is a string.
# Passed to the argument "args". # Passed to the argument "args".
args = fields.String(required=True, example="My Example Microscope") args = fields.String(required=True, example="My Example Microscope")

View file

@ -1,5 +1,5 @@
from labthings import Schema, fields, find_component
from labthings.extensions import BaseExtension from labthings.extensions import BaseExtension
from labthings import find_component, Schema, fields
from labthings.views import View from labthings.views import View
## Extension methods ## Extension methods
@ -26,6 +26,7 @@ def rename(microscope, new_name):
## Extension views ## Extension views
class ExampleIdentifyView(View): class ExampleIdentifyView(View):
# Format our returned object using MicroscopeIdentifySchema # Format our returned object using MicroscopeIdentifySchema
schema = MicroscopeIdentifySchema() schema = MicroscopeIdentifySchema()

View file

@ -1,6 +1,6 @@
from labthings import Schema, fields, find_component
from labthings.extensions import BaseExtension from labthings.extensions import BaseExtension
from labthings import find_component, Schema, fields from labthings.views import PropertyView, View
from labthings.views import View, PropertyView
## Extension methods ## Extension methods

View file

@ -1,9 +1,9 @@
from labthings.extensions import BaseExtension import io # Used in our capture action
from labthings import find_component, Schema, fields
from labthings.views import View, ActionView, PropertyView
from flask import send_file # Used to send images from our server from flask import send_file # Used to send images from our server
import io # Used in our capture action from labthings import Schema, fields, find_component
from labthings.extensions import BaseExtension
from labthings.views import ActionView, PropertyView, View
## Extension methods ## Extension methods
@ -46,7 +46,6 @@ class ExampleIdentifyView(PropertyView):
return microscope return microscope
# We can use a single schema as the input and output will be formatted identically # We can use a single schema as the input and output will be formatted identically
# Eg. We always expect a "name" string argument, and always return a "name" string attribute # Eg. We always expect a "name" string argument, and always return a "name" string attribute
class ExampleRenameView(PropertyView): class ExampleRenameView(PropertyView):
@ -83,13 +82,12 @@ class QuickCaptureAPI(ActionView):
""" """
Take an image capture and return it without saving Take an image capture and return it without saving
""" """
# Expect a "use_video_port" boolean, which defaults to True if none is given # Expect a "use_video_port" boolean, which defaults to True if none is given
args = {"use_video_port": fields.Boolean(missing=True)} args = {"use_video_port": fields.Boolean(missing=True)}
# Our success response (200) returns an image (image/jpeg mimetype) # Our success response (200) returns an image (image/jpeg mimetype)
responses = { responses = {200: {"content_type": "image/jpeg"}}
200: {"content_type": "image/jpeg"}
}
def post(self, args): def post(self, args):
""" """

View file

@ -1,15 +1,20 @@
from labthings.extensions import BaseExtension
from labthings import find_component, Schema, fields, update_action_progress, current_action
from labthings.views import View, ActionView, PropertyView
from flask import send_file # Used to send images from our server
import io # Used in our capture action import io # Used in our capture action
import time # Used in our timelapse function import time # Used in our timelapse function
from flask import send_file # Used to send images from our server
from labthings import (
Schema,
current_action,
fields,
find_component,
update_action_progress,
)
from labthings.extensions import BaseExtension
from labthings.views import ActionView, PropertyView, View
# Used in our timelapse function # Used in our timelapse function
from openflexure_microscope.captures.capture_manager import generate_basename from openflexure_microscope.captures.capture_manager import generate_basename
## Extension methods ## Extension methods
@ -59,6 +64,7 @@ class TimelapseAPI(ActionView):
""" """
Take a series of images in a timelapse Take a series of images in a timelapse
""" """
args = { args = {
"n_images": fields.Integer( "n_images": fields.Integer(
required=True, example=5, description="Number of images" required=True, example=5, description="Number of images"
@ -73,9 +79,7 @@ class TimelapseAPI(ActionView):
microscope = find_component("org.openflexure.microscope") microscope = find_component("org.openflexure.microscope")
# Start "timelapse" # Start "timelapse"
return timelapse( return timelapse(microscope, args.get("n_images"), args.get("t_between"))
microscope, args.get("n_images"), args.get("t_between")
)
## Create extension ## Create extension

View file

@ -1,17 +1,23 @@
from labthings.extensions import BaseExtension
from labthings import find_component, Schema, fields, update_action_progress, current_action
from labthings.views import View, ActionView, PropertyView
from flask import send_file # Used to send images from our server
import io # Used in our capture action import io # Used in our capture action
import time # Used in our timelapse function import time # Used in our timelapse function
# Used in our timelapse function from flask import send_file # Used to send images from our server
from openflexure_microscope.captures.capture_manager import generate_basename from labthings import (
Schema,
current_action,
fields,
find_component,
update_action_progress,
)
from labthings.extensions import BaseExtension
from labthings.views import ActionView, PropertyView, View
# Used to convert our GUI dictionary into a complete eV extension GUI # Used to convert our GUI dictionary into a complete eV extension GUI
from openflexure_microscope.api.utilities.gui import build_gui from openflexure_microscope.api.utilities.gui import build_gui
# Used in our timelapse function
from openflexure_microscope.captures.capture_manager import generate_basename
## Extension methods ## Extension methods
@ -61,6 +67,7 @@ class TimelapseAPI(ActionView):
""" """
Take a series of images in a timelapse, running as a background task Take a series of images in a timelapse, running as a background task
""" """
args = { args = {
"n_images": fields.Integer( "n_images": fields.Integer(
required=True, example=5, description="Number of images" required=True, example=5, description="Number of images"
@ -75,9 +82,7 @@ class TimelapseAPI(ActionView):
microscope = find_component("org.openflexure.microscope") microscope = find_component("org.openflexure.microscope")
# Create and start "timelapse", running in a background task # Create and start "timelapse", running in a background task
return timelapse( return timelapse(microscope, args.get("n_images"), args.get("t_between"))
microscope, args.get("n_images"), args.get("t_between")
)
## Extension GUI (OpenFlexure eV) ## Extension GUI (OpenFlexure eV)

View file

@ -1,8 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
import atexit
import logging
import logging.handlers
import sys import sys
import time import time
import atexit
import logging, logging.handlers
# Look for debug flag # Look for debug flag
if "-d" in sys.argv or "--debug" in sys.argv: if "-d" in sys.argv or "--debug" in sys.argv:
@ -17,33 +18,27 @@ root_log.setLevel(log_level)
import os import os
import pkg_resources
from flask import Flask, send_file, abort
from datetime import datetime from datetime import datetime
import pkg_resources
from flask import Flask, abort, send_file
from flask_cors import CORS, cross_origin from flask_cors import CORS, cross_origin
from openflexure_microscope.api.utilities import list_routes, init_default_extensions
from openflexure_microscope.config import JSONEncoder
from openflexure_microscope.paths import (
OPENFLEXURE_VAR_PATH,
OPENFLEXURE_EXTENSIONS_PATH,
settings_file_path,
logs_file_path,
)
from labthings import create_app from labthings import create_app
from labthings.extensions import find_extensions from labthings.extensions import find_extensions
from openflexure_microscope.api.microscope import default_microscope as api_microscope from openflexure_microscope.api.microscope import default_microscope as api_microscope
from openflexure_microscope.api.utilities import init_default_extensions, list_routes
from openflexure_microscope.api.v2 import views from openflexure_microscope.api.v2 import views
from openflexure_microscope.config import JSONEncoder
from openflexure_microscope.paths import (
OPENFLEXURE_EXTENSIONS_PATH,
OPENFLEXURE_VAR_PATH,
logs_file_path,
settings_file_path,
)
# Handle logging # Handle logging
access_log = logging.getLogger('werkzeug') access_log = logging.getLogger("werkzeug")
# Block the access logs from propagating up to the root logger # Block the access logs from propagating up to the root logger
access_log.propagate = False access_log.propagate = False
@ -207,6 +202,7 @@ atexit.register(cleanup)
# Start the app # Start the app
if __name__ == "__main__": if __name__ == "__main__":
from labthings import Server from labthings import Server
logging.info("Starting OpenFlexure Microscope Server...") logging.info("Starting OpenFlexure Microscope Server...")
server = Server(app) server = Server(app)
server.run(host="0.0.0.0", port=5000, debug=False, zeroconf=True) server.run(host="0.0.0.0", port=5000, debug=False, zeroconf=True)

View file

@ -1,18 +1,16 @@
from labthings import fields, find_component, current_action
from labthings.extensions import BaseExtension
from labthings.views import View, ActionView, PropertyView
from openflexure_microscope.devel import JsonResponse, request, abort
from openflexure_microscope.utilities import set_properties
import time
import numpy as np
import logging import logging
from scipy import ndimage import time
from contextlib import contextmanager from contextlib import contextmanager
from threading import Event, Thread
from threading import Thread, Event import numpy as np
from labthings import current_action, fields, find_component
from labthings.extensions import BaseExtension
from labthings.views import ActionView, PropertyView, View
from scipy import ndimage
from openflexure_microscope.devel import JsonResponse, abort, request
from openflexure_microscope.utilities import set_properties
### Autofocus utilities ### Autofocus utilities
@ -447,4 +445,3 @@ autofocus_extension_v2.add_view(
autofocus_extension_v2.add_view( autofocus_extension_v2.add_view(
MoveAndMeasureAPI, "/move_and_measure", endpoint="move_and_measure" MoveAndMeasureAPI, "/move_and_measure", endpoint="move_and_measure"
) )

View file

@ -1,21 +1,18 @@
from labthings.extensions import BaseExtension
from labthings.views import View, PropertyView
from labthings import fields, find_component
from openflexure_microscope.paths import settings_file_path, check_rw
from openflexure_microscope.config import OpenflexureSettingsFile
from openflexure_microscope.captures.capture_manager import BASE_CAPTURE_PATH
from openflexure_microscope.captures.capture import build_captures_from_exif
from openflexure_microscope.api.utilities.gui import build_gui
from flask import abort
import logging import logging
import os import os
import psutil
from sys import platform from sys import platform
import psutil
from flask import abort
from labthings import fields, find_component
from labthings.extensions import BaseExtension
from labthings.views import PropertyView, View
from openflexure_microscope.api.utilities.gui import build_gui
from openflexure_microscope.captures.capture import build_captures_from_exif
from openflexure_microscope.captures.capture_manager import BASE_CAPTURE_PATH
from openflexure_microscope.config import OpenflexureSettingsFile
from openflexure_microscope.paths import check_rw, settings_file_path
AS_SETTINGS_PATH = settings_file_path("autostorage_settings.json") AS_SETTINGS_PATH = settings_file_path("autostorage_settings.json")

View file

@ -1,19 +1,18 @@
from labthings import find_component
from labthings.views import View, ActionView
from labthings.extensions import BaseExtension
from flask import abort
from contextlib import contextmanager
import logging import logging
from contextlib import contextmanager
# Type hinting # Type hinting
from typing import Tuple from typing import Tuple
from flask import abort
from labthings import find_component
from labthings.extensions import BaseExtension
from labthings.views import ActionView, View
from .recalibrate_utils import ( from .recalibrate_utils import (
recalibrate_camera,
auto_expose_and_freeze_settings, auto_expose_and_freeze_settings,
flat_lens_shading_table, flat_lens_shading_table,
recalibrate_camera,
) )
@ -125,5 +124,9 @@ lst_extension_v2.add_method(
) )
lst_extension_v2.add_view(RecalibrateView, "/recalibrate", endpoint="recalibrate") lst_extension_v2.add_view(RecalibrateView, "/recalibrate", endpoint="recalibrate")
lst_extension_v2.add_view(FlattenLSTView, "/flatten_lens_shading_table", endpoint="flatten_lens_shading_table") lst_extension_v2.add_view(
lst_extension_v2.add_view(DeleteLSTView, "/delete_lens_shading_table", endpoint="delete_lens_shading_table") FlattenLSTView, "/flatten_lens_shading_table", endpoint="flatten_lens_shading_table"
)
lst_extension_v2.add_view(
DeleteLSTView, "/delete_lens_shading_table", endpoint="delete_lens_shading_table"
)

View file

@ -1,9 +1,9 @@
import numpy as np
import time
import logging import logging
import time
import numpy as np
from picamerax import PiCamera from picamerax import PiCamera
from picamerax.array import PiRGBArray, PiBayerArray from picamerax.array import PiBayerArray, PiRGBArray
def rgb_image(camera, resize=None, **kwargs): def rgb_image(camera, resize=None, **kwargs):

View file

@ -1,21 +1,24 @@
import datetime
import itertools import itertools
import logging import logging
import time
import uuid import uuid
import datetime
from typing import Tuple
from functools import reduce from functools import reduce
from typing import Tuple
from labthings import (
current_action,
fields,
find_component,
find_extension,
update_action_progress,
)
from labthings.extensions import BaseExtension
from labthings.views import ActionView, View
from openflexure_microscope.captures.capture_manager import generate_basename from openflexure_microscope.captures.capture_manager import generate_basename
from labthings import fields, find_component, find_extension, current_action, update_action_progress
from labthings.views import View, ActionView
from labthings.extensions import BaseExtension
from openflexure_microscope.devel import abort from openflexure_microscope.devel import abort
import time
### Grid construction ### Grid construction
@ -56,9 +59,6 @@ def flatten_grid(grid):
### Capturing ### Capturing
class ScanExtension(BaseExtension): class ScanExtension(BaseExtension):
def __init__(self): def __init__(self):
self._images_to_be_captured: int = 1 self._images_to_be_captured: int = 1
@ -83,7 +83,12 @@ class ScanExtension(BaseExtension):
if namemode == "coordinates": if namemode == "coordinates":
filename = "{}_{}_{}_{}".format(basename, *microscope.stage.position) filename = "{}_{}_{}_{}".format(basename, *microscope.stage.position)
else: else:
filename = "{}_{}".format(basename, str(self._images_captured_so_far).zfill(len(str(self._images_to_be_captured)))) filename = "{}_{}".format(
basename,
str(self._images_captured_so_far).zfill(
len(str(self._images_to_be_captured))
),
)
folder = "SCAN_{}".format(basename) folder = "SCAN_{}".format(basename)
# Do capture # Do capture
@ -97,14 +102,14 @@ class ScanExtension(BaseExtension):
annotations=annotations, annotations=annotations,
tags=tags, tags=tags,
metadata=metadata, metadata=metadata,
cache_key=folder cache_key=folder,
) )
def progress(self): def progress(self):
progress = (self._images_captured_so_far / self._images_to_be_captured) * 100 progress = (self._images_captured_so_far / self._images_to_be_captured) * 100
logging.info(progress) logging.info(progress)
return progress return progress
### Scanning ### Scanning
def tile( def tile(
self, self,
@ -164,7 +169,9 @@ class ScanExtension(BaseExtension):
autofocus_enabled = False autofocus_enabled = False
# Construct an x-y grid (worry about z later) # Construct an x-y grid (worry about z later)
x_y_grid = construct_grid(initial_position, stride_size[:2], grid[:2], style=style) x_y_grid = construct_grid(
initial_position, stride_size[:2], grid[:2], style=style
)
# Keep the initial Z position the same as our current position # Keep the initial Z position the same as our current position
initial_z = initial_position[2] initial_z = initial_position[2]
@ -245,7 +252,6 @@ class ScanExtension(BaseExtension):
end = time.time() end = time.time()
logging.info(f"Scan took {end - start} seconds") logging.info(f"Scan took {end - start} seconds")
def stack( def stack(
self, self,
microscope, microscope,
@ -304,6 +310,7 @@ class ScanExtension(BaseExtension):
scan_extension_v2 = ScanExtension() scan_extension_v2 = ScanExtension()
class TileScanAPI(ActionView): class TileScanAPI(ActionView):
args = { args = {
"filename": fields.String(missing=None, example=None), "filename": fields.String(missing=None, example=None),
@ -365,4 +372,5 @@ class TileScanAPI(ActionView):
tags=args.get("tags"), tags=args.get("tags"),
) )
scan_extension_v2.add_view(TileScanAPI, "/tile", endpoint="tile") scan_extension_v2.add_view(TileScanAPI, "/tile", endpoint="tile")

View file

@ -1,21 +1,17 @@
from openflexure_microscope.devel import (
JsonResponse,
request,
)
from flask import send_file, abort, url_for
import uuid
import os
import zipfile
import tempfile
import logging import logging
import os
import tempfile
import uuid
import zipfile
from flask import abort, send_file, url_for
from labthings import fields, find_component, update_action_progress from labthings import fields, find_component, update_action_progress
from labthings.views import View, ActionView, PropertyView
from labthings.schema import Schema, pre_dump
from labthings.extensions import BaseExtension from labthings.extensions import BaseExtension
from labthings.schema import Schema, pre_dump
from labthings.utilities import description_from_view from labthings.utilities import description_from_view
from labthings.views import ActionView, PropertyView, View
from openflexure_microscope.devel import JsonResponse, request
class ZipObjectSchema(Schema): class ZipObjectSchema(Schema):
@ -137,9 +133,7 @@ class ZipBuilderAPIView(ActionView):
microscope = find_component("org.openflexure.microscope") microscope = find_component("org.openflexure.microscope")
# Return a handle on the autofocus task # Return a handle on the autofocus task
return default_zip_manager.marshaled_build_zip_from_capture_ids( return default_zip_manager.marshaled_build_zip_from_capture_ids(microscope, ids)
microscope, ids
)
class ZipListAPIView(PropertyView): class ZipListAPIView(PropertyView):
@ -191,7 +185,9 @@ zip_extension_v2 = BaseExtension(
description="Build and download capture collections as ZIP files", description="Build and download capture collections as ZIP files",
) )
zip_extension_v2.add_view(ZipGetterAPIView, "/get/<string:session_id>", endpoint="get_id") zip_extension_v2.add_view(
ZipGetterAPIView, "/get/<string:session_id>", endpoint="get_id"
)
zip_extension_v2.add_view(ZipListAPIView, "/get", endpoint="get") zip_extension_v2.add_view(ZipListAPIView, "/get", endpoint="get")
zip_extension_v2.add_view(ZipBuilderAPIView, "/build", endpoint="build") zip_extension_v2.add_view(ZipBuilderAPIView, "/build", endpoint="build")

View file

@ -1 +1 @@
from .tools import devtools_extension_v2 from .tools import devtools_extension_v2

View file

@ -1,14 +1,16 @@
import logging
import time
from labthings import fields from labthings import fields
from labthings.extensions import BaseExtension from labthings.extensions import BaseExtension
from labthings.views import ActionView from labthings.views import ActionView
import logging
import time
class RaiseException(ActionView): class RaiseException(ActionView):
def post(self): def post(self):
raise Exception("The developer raised an exception") raise Exception("The developer raised an exception")
class SleepFor(ActionView): class SleepFor(ActionView):
schema = {"TimeAsleep": fields.Float()} schema = {"TimeAsleep": fields.Float()}
args = {"time": fields.Float(description="Time to sleep, in seconds", example=0.5)} args = {"time": fields.Float(description="Time to sleep, in seconds", example=0.5)}
@ -22,6 +24,7 @@ class SleepFor(ActionView):
logging.info("Waking up!") logging.info("Waking up!")
return {"TimeAsleep": (end - start)} return {"TimeAsleep": (end - start)}
devtools_extension_v2 = BaseExtension( devtools_extension_v2 = BaseExtension(
"org.openflexure.dev.tools", "org.openflexure.dev.tools",
version="0.1.0", version="0.1.0",
@ -29,4 +32,4 @@ devtools_extension_v2 = BaseExtension(
) )
devtools_extension_v2.add_view(RaiseException, "/raise") devtools_extension_v2.add_view(RaiseException, "/raise")
devtools_extension_v2.add_view(SleepFor, "/sleep") devtools_extension_v2.add_view(SleepFor, "/sleep")

View file

@ -1,7 +1,6 @@
from openflexure_microscope.microscope import Microscope
import logging import logging
from openflexure_microscope.microscope import Microscope
default_microscope = Microscope() default_microscope = Microscope()

View file

@ -1,8 +1,9 @@
import errno
import logging import logging
import os import os
import errno
from flask import Blueprint, current_app, url_for
from werkzeug.exceptions import BadRequest from werkzeug.exceptions import BadRequest
from flask import url_for, Blueprint, current_app
from . import gui from . import gui

View file

@ -1,5 +1,5 @@
from .actions import enabled_root_actions from .actions import enabled_root_actions
from .captures import * from .captures import *
from .instrument import * from .instrument import *
from .streams import *
from .stage import * from .stage import *
from .streams import *

View file

@ -2,11 +2,11 @@
Top-level representation of enabled actions Top-level representation of enabled actions
""" """
from flask import url_for from flask import url_for
from . import camera, stage, system
from labthings import current_labthing from labthings import current_labthing
from labthings.views import View
from labthings.utilities import description_from_view from labthings.utilities import description_from_view
from labthings.views import View
from . import camera, stage, system
_actions = { _actions = {
"capture": { "capture": {

View file

@ -1,14 +1,13 @@
from openflexure_microscope.api.utilities import get_bool, JsonResponse
from labthings.views import View, ActionView
from labthings import find_component, fields
from openflexure_microscope.utilities import filter_dict
from openflexure_microscope.api.v2.views.captures import CaptureSchema
import logging
import io import io
from flask import request, abort, url_for, redirect, send_file import logging
from flask import abort, redirect, request, send_file, url_for
from labthings import fields, find_component
from labthings.views import ActionView, View
from openflexure_microscope.api.utilities import JsonResponse, get_bool
from openflexure_microscope.api.v2.views.captures import CaptureSchema
from openflexure_microscope.utilities import filter_dict
class CaptureAPI(ActionView): class CaptureAPI(ActionView):
@ -58,11 +57,10 @@ class CaptureAPI(ActionView):
resize=resize, resize=resize,
bayer=args.get("bayer"), bayer=args.get("bayer"),
annotations=args.get("annotations"), annotations=args.get("annotations"),
tags=args.get("tags") tags=args.get("tags"),
) )
class RAMCaptureAPI(ActionView): class RAMCaptureAPI(ActionView):
""" """
Take a non-persistant image capture. Take a non-persistant image capture.
@ -77,12 +75,8 @@ class RAMCaptureAPI(ActionView):
missing=None, example={"width": 640, "height": 480} missing=None, example={"width": 640, "height": 480}
), # TODO: Validate keys ), # TODO: Validate keys
} }
responses = { responses = {200: {"content_type": "image/jpeg"}}
200: {
"content_type": "image/jpeg"
}
}
def post(self, args): def post(self, args):
""" """

View file

@ -1,12 +1,11 @@
from openflexure_microscope.api.utilities import JsonResponse import logging
from labthings.views import View, ActionView
from labthings import find_component, fields
from openflexure_microscope.utilities import axes_to_array, filter_dict
from flask import Blueprint, request from flask import Blueprint, request
from labthings import fields, find_component
from labthings.views import ActionView, View
import logging from openflexure_microscope.api.utilities import JsonResponse
from openflexure_microscope.utilities import axes_to_array, filter_dict
class MoveStageAPI(ActionView): class MoveStageAPI(ActionView):
@ -65,5 +64,3 @@ class ZeroStageAPI(ActionView):
# TODO: Make schema for microscope state # TODO: Make schema for microscope state
return microscope.state["stage"] return microscope.state["stage"]

View file

@ -1,8 +1,9 @@
from labthings.views import View, ActionView
import subprocess
import os import os
import subprocess
from sys import platform from sys import platform
from labthings.views import ActionView, View
def is_raspberrypi(raise_on_errors=False): def is_raspberrypi(raise_on_errors=False):
""" """

View file

@ -1,15 +1,14 @@
import logging import logging
from flask import abort, request, redirect, url_for, send_file
from openflexure_microscope.api.utilities import get_bool, JsonResponse
from flask import abort, redirect, request, send_file, url_for
from labthings import Schema, fields, find_component from labthings import Schema, fields, find_component
from labthings.views import View, PropertyView
from labthings.utilities import description_from_view
from labthings.marshalling import marshal_with from labthings.marshalling import marshal_with
from labthings.utilities import description_from_view
from labthings.views import PropertyView, View
from marshmallow import pre_dump from marshmallow import pre_dump
from openflexure_microscope.api.utilities import JsonResponse, get_bool
class InstrumentSchema(Schema): class InstrumentSchema(Schema):
id = fields.UUID() id = fields.UUID()
@ -130,11 +129,7 @@ class CaptureView(View):
class CaptureDownload(View): class CaptureDownload(View):
tags = ["captures"] tags = ["captures"]
responses = { responses = {200: {"content_type": "image/jpeg"}}
200: {
"content_type": "image/jpeg"
}
}
def get(self, id, filename): def get(self, id, filename):
""" """

View file

@ -1,12 +1,12 @@
from openflexure_microscope.api.utilities import JsonResponse
from labthings import find_component
from labthings.views import View, PropertyView
from labthings.utilities import get_by_path, set_by_path, create_from_path
from flask import request, abort
import logging import logging
from flask import abort, request
from labthings import find_component
from labthings.utilities import create_from_path, get_by_path, set_by_path
from labthings.views import PropertyView, View
from openflexure_microscope.api.utilities import JsonResponse
class SettingsProperty(PropertyView): class SettingsProperty(PropertyView):
def get(self): def get(self):
@ -34,9 +34,7 @@ class SettingsProperty(PropertyView):
class NestedSettingsProperty(View): class NestedSettingsProperty(View):
tags = ["properties"] tags = ["properties"]
responses = { responses = {404: {"description": "Settings key cannot be found"}}
404: {"description": "Settings key cannot be found"}
}
def get(self, route): def get(self, route):
""" """
@ -80,9 +78,7 @@ class StateProperty(PropertyView):
class NestedStateProperty(View): class NestedStateProperty(View):
tags = ["properties"] tags = ["properties"]
responses = { responses = {404: {"description": "Status key cannot be found"}}
404: {"description": "Status key cannot be found"}
}
def get(self, route): def get(self, route):
""" """
@ -110,9 +106,7 @@ class ConfigurationProperty(PropertyView):
class NestedConfigurationProperty(View): class NestedConfigurationProperty(View):
tags = ["properties"] tags = ["properties"]
responses = { responses = {404: {"description": "Status key cannot be found"}}
404: {"description": "Status key cannot be found"}
}
def get(self, route): def get(self, route):
""" """

View file

@ -1,8 +1,8 @@
from labthings import find_component, fields, schema
from labthings.views import PropertyView
import logging import logging
from labthings import fields, find_component, schema
from labthings.views import PropertyView
class StageTypeProperty(PropertyView): class StageTypeProperty(PropertyView):
"""The type of the stage""" """The type of the stage"""

View file

@ -1,21 +1,17 @@
from openflexure_microscope.api.utilities import gen, JsonResponse
from labthings import find_component
from labthings.utilities import get_by_path, set_by_path, create_from_path
from labthings.views import View, PropertyView
from flask import Response from flask import Response
from labthings import find_component
from labthings.utilities import create_from_path, get_by_path, set_by_path
from labthings.views import PropertyView, View
from openflexure_microscope.api.utilities import JsonResponse, gen
class MjpegStream(PropertyView): class MjpegStream(PropertyView):
""" """
Real-time MJPEG stream from the microscope camera Real-time MJPEG stream from the microscope camera
""" """
responses = {
200: { responses = {200: {"content_type": "multipart/x-mixed-replace"}}
"content_type": "multipart/x-mixed-replace"
}
}
def get(self): def get(self):
""" """
@ -44,12 +40,7 @@ class SnapshotStream(PropertyView):
Single JPEG snapshot from the camera stream Single JPEG snapshot from the camera stream
""" """
responses = { responses = {200: {"content_type": "image/jpeg", "description": "Snapshot taken"}}
200: {
"content_type": "image/jpeg",
"description": "Snapshot taken"
}
}
def get(self): def get(self):
""" """

View file

@ -1,15 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import time
import os
import shutil
import datetime import datetime
import logging import logging
import os
import shutil
import threading import threading
import time
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from labthings import StrictLock, ClientEvent from labthings import ClientEvent, StrictLock
class BaseCamera(metaclass=ABCMeta): class BaseCamera(metaclass=ABCMeta):

View file

@ -6,20 +6,19 @@
from __future__ import division from __future__ import division
import io import io
import time
import numpy as np
from PIL import Image, ImageFont, ImageDraw
from datetime import datetime
import logging import logging
import time
from datetime import datetime
# Type hinting # Type hinting
from typing import Tuple from typing import Tuple
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from openflexure_microscope.camera.base import BaseCamera from openflexure_microscope.camera.base import BaseCamera
from openflexure_microscope.captures import CaptureObject from openflexure_microscope.captures import CaptureObject
""" """
PIL spams the logger with debug-level information. This is a pain when debugging api.app. PIL spams the logger with debug-level information. This is a pain when debugging api.app.
We override the logging settings in api.app by setting a level for PIL here. We override the logging settings in api.app by setting a level for PIL here.

View file

@ -29,31 +29,31 @@ to temporarily increase the capture resolution.
from __future__ import division from __future__ import division
import io import io
import time
import numpy as np
import os
import logging import logging
import os
import time
# Type hinting
from typing import Tuple
import numpy as np
# Pi camera # Pi camera
import picamerax import picamerax
import picamerax.array import picamerax.array
# Type hinting
from typing import Tuple
from openflexure_microscope.camera.base import BaseCamera from openflexure_microscope.camera.base import BaseCamera
from openflexure_microscope.captures import CaptureObject from openflexure_microscope.captures import CaptureObject
from openflexure_microscope.paths import settings_file_path
from openflexure_microscope.utilities import (
json_to_ndarray,
ndarray_to_json,
serialise_array_b64,
)
# Richard's fix gain # Richard's fix gain
from .set_picamera_gain import set_analog_gain, set_digital_gain from .set_picamera_gain import set_analog_gain, set_digital_gain
from openflexure_microscope.paths import settings_file_path
from openflexure_microscope.utilities import (
serialise_array_b64,
ndarray_to_json,
json_to_ndarray,
)
# MAIN CLASS # MAIN CLASS
class PiCameraStreamer(BaseCamera): class PiCameraStreamer(BaseCamera):
@ -115,7 +115,7 @@ class PiCameraStreamer(BaseCamera):
self.picamera_lst_path = settings_file_path( self.picamera_lst_path = settings_file_path(
"picamera_lst.npy" "picamera_lst.npy"
) #: str: Path of .npy lens shading table file ) #: str: Path of .npy lens shading table file
# Start the stream worker on init # Start the stream worker on init
self.start_worker() self.start_worker()
@ -348,7 +348,7 @@ class PiCameraStreamer(BaseCamera):
"Suppressed a ValueError exception in start_preview. Exception: {}".format( "Suppressed a ValueError exception in start_preview. Exception: {}".format(
e e
) )
) )
def stop_preview(self): def stop_preview(self):
"""Stop the on board GPU camera preview.""" """Stop the on board GPU camera preview."""
@ -538,7 +538,7 @@ class PiCameraStreamer(BaseCamera):
bayer=(not use_video_port) and bayer, bayer=(not use_video_port) and bayer,
use_video_port=use_video_port, use_video_port=use_video_port,
) )
#time.sleep(0.1) # time.sleep(0.1)
# Set resolution and start stream recording if necessary # Set resolution and start stream recording if necessary
if not use_video_port: if not use_video_port:

View file

@ -1,10 +1,9 @@
from ._remove import remove
from ._load import load
from ._dump import dump from ._dump import dump
from ._transplant import transplant
from ._insert import insert
from ._exif import *
from ._exceptions import * from ._exceptions import *
from ._exif import *
from ._insert import insert
from ._load import load
from ._remove import remove
from ._transplant import transplant
VERSION = "1.1.2" VERSION = "1.1.2"

View file

@ -5,7 +5,6 @@ import struct
from ._common import * from ._common import *
from ._exif import * from ._exif import *
TIFF_HEADER_LENGTH = 8 TIFF_HEADER_LENGTH = 8

View file

@ -2,9 +2,9 @@ import io
import struct import struct
import sys import sys
from . import _webp
from ._common import * from ._common import *
from ._exceptions import InvalidImageDataError from ._exceptions import InvalidImageDataError
from . import _webp
def insert(exif, image, new_file=None): def insert(exif, image, new_file=None):

View file

@ -1,10 +1,10 @@
import struct import struct
import sys import sys
from . import _webp
from ._common import * from ._common import *
from ._exceptions import InvalidImageDataError from ._exceptions import InvalidImageDataError
from ._exif import * from ._exif import *
from . import _webp
LITTLE_ENDIAN = b"\x49\x49" LITTLE_ENDIAN = b"\x49\x49"

View file

@ -1,7 +1,7 @@
import io import io
from ._common import *
from . import _webp from . import _webp
from ._common import *
def remove(src, new_file=None): def remove(src, new_file=None):

View file

@ -1,10 +1,11 @@
from __future__ import print_function from __future__ import print_function
import picamerax
from picamerax import mmal, mmalobj, exc
from picamerax.mmalobj import to_rational
import time
import logging import logging
import time
import picamerax
from picamerax import exc, mmal, mmalobj
from picamerax.mmalobj import to_rational
MMAL_PARAMETER_ANALOG_GAIN = mmal.MMAL_PARAMETER_GROUP_CAMERA + 0x59 MMAL_PARAMETER_ANALOG_GAIN = mmal.MMAL_PARAMETER_GROUP_CAMERA + 0x59
MMAL_PARAMETER_DIGITAL_GAIN = mmal.MMAL_PARAMETER_GROUP_CAMERA + 0x5A MMAL_PARAMETER_DIGITAL_GAIN = mmal.MMAL_PARAMETER_GROUP_CAMERA + 0x5A

View file

@ -1,3 +1,3 @@
from .capture_manager import CaptureManager from . import capture, capture_manager
from .capture import CaptureObject from .capture import CaptureObject
from . import capture_manager, capture from .capture_manager import CaptureManager

View file

@ -1,17 +1,17 @@
import uuid import atexit
import io
import os
import shutil
import glob
import datetime import datetime
import glob
import io
import json import json
import logging import logging
from PIL import Image import os
import dateutil.parser import shutil
import atexit import uuid
from collections import OrderedDict from collections import OrderedDict
import dateutil.parser
from PIL import Image
from openflexure_microscope.camera import piexif from openflexure_microscope.camera import piexif
from openflexure_microscope.camera.piexif._exceptions import InvalidImageDataError from openflexure_microscope.camera.piexif._exceptions import InvalidImageDataError
from openflexure_microscope.config import JSONEncoder from openflexure_microscope.config import JSONEncoder
@ -156,7 +156,7 @@ class CaptureObject(object):
def flush(self): def flush(self):
logging.info(f"Writing to disk {self.file}") logging.info(f"Writing to disk {self.file}")
with open(self.file, "wb") as outfile: with open(self.file, "wb") as outfile:
outfile.write(self.stream.getbuffer()) outfile.write(self.stream.getbuffer())
self.stream.close() self.stream.close()
logging.info(f"Finished writing to disk {self.file}") logging.info(f"Finished writing to disk {self.file}")
@ -233,7 +233,9 @@ class CaptureObject(object):
self._metadata.update(data) self._metadata.update(data)
self.save_metadata() self.save_metadata()
def put_and_save(self, tags: list = None, annotations: dict = None, metadata: dict = None): def put_and_save(
self, tags: list = None, annotations: dict = None, metadata: dict = None
):
""" """
Batch-write tags, metadata, and annotations in a single disk operation Batch-write tags, metadata, and annotations in a single disk operation
""" """
@ -243,7 +245,7 @@ class CaptureObject(object):
annotations = {} annotations = {}
if not metadata: if not metadata:
metadata = {} metadata = {}
# Tags # Tags
for tag in tags: for tag in tags:
if tag not in self.tags: if tag not in self.tags:

View file

@ -1,13 +1,13 @@
import os
import datetime import datetime
import shutil
import logging import logging
import os
import shutil
from collections import OrderedDict from collections import OrderedDict
from labthings import StrictLock from labthings import StrictLock
from openflexure_microscope.utilities import entry_by_uuid
from openflexure_microscope.paths import data_file_path from openflexure_microscope.paths import data_file_path
from openflexure_microscope.utilities import entry_by_uuid
from .capture import CaptureObject, build_captures_from_exif from .capture import CaptureObject, build_captures_from_exif

View file

@ -1,20 +1,20 @@
import json
import flask
import os
import errno import errno
import json
import logging import logging
import os
import shutil import shutil
from uuid import UUID
import numpy as np
from fractions import Fraction from fractions import Fraction
from uuid import UUID
import flask
import numpy as np
from labthings.json import LabThingsJSONEncoder from labthings.json import LabThingsJSONEncoder
from .paths import ( from .paths import (
SETTINGS_FILE_PATH,
DEFAULT_SETTINGS_FILE_PATH,
CONFIGURATION_FILE_PATH, CONFIGURATION_FILE_PATH,
DEFAULT_CONFIGURATION_FILE_PATH, DEFAULT_CONFIGURATION_FILE_PATH,
DEFAULT_SETTINGS_FILE_PATH,
SETTINGS_FILE_PATH,
) )

View file

@ -5,19 +5,15 @@ Here we include some classes used frequently in plugin development,
as well as some Flask imports to simplify API route development as well as some Flask imports to simplify API route development
""" """
from openflexure_microscope.api.utilities import JsonResponse # Flask things
from flask import Response, abort, escape, request
# Task management # Task management
from labthings import ( from labthings import current_action as current_task
current_action as current_task, from labthings import update_action_data as update_task_data
update_action_progress as update_task_progress, from labthings import update_action_progress as update_task_progress
update_action_data as update_task_data,
)
# Flask things
from flask import abort, escape, Response, request
from openflexure_microscope.api.utilities import JsonResponse
__all__ = [ __all__ = [
"current_task", "current_task",

View file

@ -1,14 +1,17 @@
import os
from pynpm import NPMPackage from pynpm import NPMPackage
import os
dir_path = os.path.dirname(os.path.realpath(__file__)) dir_path = os.path.dirname(os.path.realpath(__file__))
pkg_path = os.path.join(dir_path, "api", "static", "package.json") pkg_path = os.path.join(dir_path, "api", "static", "package.json")
pkg = NPMPackage(pkg_path) pkg = NPMPackage(pkg_path)
def install(): def install():
pkg.install() pkg.install()
def build(): def build():
pkg.install() pkg.install()
pkg.run_script('build') pkg.run_script("build")

View file

@ -3,29 +3,28 @@
Defines a microscope object, binding a camera and stage with basic functionality. Defines a microscope object, binding a camera and stage with basic functionality.
""" """
import logging import logging
import pkg_resources
import uuid import uuid
from typing import Tuple from typing import Tuple
import pkg_resources
from expiringdict import ExpiringDict from expiringdict import ExpiringDict
from openflexure_microscope.captures import CaptureManager
from openflexure_microscope.stage.mock import MissingStage
from openflexure_microscope.camera.mock import MissingCamera from openflexure_microscope.camera.mock import MissingCamera
from openflexure_microscope.stage.sanga import SangaStage, SangaDeltaStage from openflexure_microscope.captures import CaptureManager
from openflexure_microscope.stage.mock import MissingStage
from openflexure_microscope.stage.sanga import SangaDeltaStage, SangaStage
try: try:
from openflexure_microscope.camera.pi import PiCameraStreamer from openflexure_microscope.camera.pi import PiCameraStreamer
except Exception as e: except Exception as e:
logging.error(e) logging.error(e)
logging.warning("Unable to import PiCameraStreamer") logging.warning("Unable to import PiCameraStreamer")
from openflexure_microscope.camera.mock import MissingCamera
from openflexure_microscope.utilities import serialise_array_b64, Timer
from openflexure_microscope.config import user_settings, user_configuration
from labthings import CompositeLock from labthings import CompositeLock
from openflexure_microscope.camera.mock import MissingCamera
from openflexure_microscope.config import user_configuration, user_settings
from openflexure_microscope.utilities import Timer, serialise_array_b64
class Microscope: class Microscope:
""" """
@ -106,7 +105,6 @@ class Microscope:
### Stage ### Stage
self.set_stage(configuration=configuration) self.set_stage(configuration=configuration)
logging.info("Handling fallbacks") logging.info("Handling fallbacks")
### Fallbacks ### Fallbacks
@ -131,20 +129,19 @@ class Microscope:
if stage_type: if stage_type:
if stage_type == configuration["stage"].get("type"): if stage_type == configuration["stage"].get("type"):
logging.info("Stage already set to that stage type") logging.info("Stage already set to that stage type")
return return
else: else:
stage_type = configuration["stage"].get("type") stage_type = configuration["stage"].get("type")
### Close any existing stages ### Close any existing stages
if self.stage: if self.stage:
stage_port = self.stage.port stage_port = self.stage.port
self.stage.close() self.stage.close()
logging.info("Setting stage") logging.info("Setting stage")
stage_port = configuration["stage"].get("port") stage_port = configuration["stage"].get("port")
if stage_type in ("SangaBoard", "SangaStage"): if stage_type in ("SangaBoard", "SangaStage"):
try: try:
logging.info("Trying SangaStage") logging.info("Trying SangaStage")
@ -156,17 +153,17 @@ class Microscope:
try: try:
logging.info("Trying SangaDeltaStage") logging.info("Trying SangaDeltaStage")
self.stage = SangaDeltaStage(port=stage_port) self.stage = SangaDeltaStage(port=stage_port)
except Exception as e: except Exception as e:
logging.error(e) logging.error(e)
logging.warning("No compatible Sangaboard hardware found.") logging.warning("No compatible Sangaboard hardware found.")
else: else:
logging.warning("The stage type is incorrectly defined.") logging.warning("The stage type is incorrectly defined.")
logging.info("Saving new stage type configuration") logging.info("Saving new stage type configuration")
configuration["stage"]["type"] = stage_type configuration["stage"]["type"] = stage_type
self.configuration_file.save(configuration) self.configuration_file.save(configuration)
def has_real_stage(self) -> bool: def has_real_stage(self) -> bool:
""" """
Check if a real (non-mock) stage is currently attached. Check if a real (non-mock) stage is currently attached.
@ -249,13 +246,13 @@ class Microscope:
with self.lock: with self.lock:
# If attached to a camera # If attached to a camera
if self.camera: if self.camera:
settings_current_camera = self.camera.read_settings() settings_current_camera = self.camera.read_settings()
settings_current["camera"] = settings_current_camera settings_current["camera"] = settings_current_camera
# If attached to a stage # If attached to a stage
if self.stage: if self.stage:
settings_current_stage = self.stage.read_settings() settings_current_stage = self.stage.read_settings()
settings_current["stage"] = settings_current_stage settings_current["stage"] = settings_current_stage
# Capture manager # Capture manager
settings_current_captures = self.captures.read_settings() settings_current_captures = self.captures.read_settings()
@ -346,11 +343,9 @@ class Microscope:
else: else:
logging.debug(f"Building microscope metadata: {cache_key}") logging.debug(f"Building microscope metadata: {cache_key}")
metadata = self.force_get_metadata() metadata = self.force_get_metadata()
# Keys that should never be cached # Keys that should never be cached
metadata.update({ metadata.update({"state": self.state})
"state": self.state,
})
return metadata return metadata
@ -370,7 +365,7 @@ class Microscope:
annotations: dict = None, annotations: dict = None,
tags: list = None, tags: list = None,
metadata: dict = None, metadata: dict = None,
cache_key: str = None cache_key: str = None,
): ):
logging.debug(f"Microscope capturing to {filename}") logging.debug(f"Microscope capturing to {filename}")
if not annotations: if not annotations:

View file

@ -1,5 +1,5 @@
import os
import logging import logging
import os
# UTILITIES # UTILITIES

View file

@ -1,11 +1,12 @@
import logging
import os
from openflexure_microscope.paths import ( from openflexure_microscope.paths import (
FALLBACK_OPENFLEXURE_VAR_PATH, FALLBACK_OPENFLEXURE_VAR_PATH,
PREFERRED_OPENFLEXURE_VAR_PATH, PREFERRED_OPENFLEXURE_VAR_PATH,
) )
import logging
import os
from . import check_settings, check_capture_reload from . import check_capture_reload, check_settings
# Paths for suggestions # Paths for suggestions
LOGS_PATHS = [ LOGS_PATHS = [

View file

@ -1,10 +1,10 @@
from openflexure_microscope.rescue.monitor_timeout import launch_timeout_test_process
from openflexure_microscope.captures.capture_manager import BASE_CAPTURE_PATH
from openflexure_microscope.captures.capture import build_captures_from_exif
from openflexure_microscope.config import user_settings
import logging import logging
from openflexure_microscope.captures.capture import build_captures_from_exif
from openflexure_microscope.captures.capture_manager import BASE_CAPTURE_PATH
from openflexure_microscope.config import user_settings
from openflexure_microscope.rescue.monitor_timeout import launch_timeout_test_process
def check_capture_rebuild(timeout=10): def check_capture_rebuild(timeout=10):
logging.info("Loading user settings...") logging.info("Loading user settings...")

View file

@ -1,5 +1,5 @@
import logging
import json import json
import logging
ERROR_SOURCES = [] ERROR_SOURCES = []

View file

@ -20,8 +20,8 @@
# */5 * * * * /root/bin/monitor_service.py prosody > /dev/null 2>&1 # */5 * * * * /root/bin/monitor_service.py prosody > /dev/null 2>&1
# #
import sys
import subprocess import subprocess
import sys
class ServiceMonitor(object): class ServiceMonitor(object):

View file

@ -1,7 +1,8 @@
import multiprocessing
import logging import logging
import multiprocessing
import time import time
# bar # bar
def test_long_fn(): def test_long_fn():
for _ in range(100): for _ in range(100):

View file

@ -1,5 +1,6 @@
import numpy as np
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import numpy as np
from labthings import StrictLock from labthings import StrictLock

View file

@ -1,11 +1,12 @@
import logging
import time
from collections.abc import Iterable
import numpy as np
from openflexure_microscope.stage.base import BaseStage from openflexure_microscope.stage.base import BaseStage
from openflexure_microscope.utilities import axes_to_array from openflexure_microscope.utilities import axes_to_array
from collections.abc import Iterable
import numpy as np
import time
import logging
class MissingStage(BaseStage): class MissingStage(BaseStage):
def __init__(self, port=None, **kwargs): def __init__(self, port=None, **kwargs):

View file

@ -1,8 +1,10 @@
import numpy as np
import time
import logging import logging
import time
from collections.abc import Iterable from collections.abc import Iterable
import numpy as np
from sangaboard import Sangaboard from sangaboard import Sangaboard
from openflexure_microscope.stage.base import BaseStage from openflexure_microscope.stage.base import BaseStage
from openflexure_microscope.utilities import axes_to_array from openflexure_microscope.utilities import axes_to_array
@ -189,39 +191,48 @@ class SangaStage(BaseStage):
print("Move completed, raising exception...") print("Move completed, raising exception...")
raise value # Propagate the exception raise value # Propagate the exception
class SangaDeltaStage(SangaStage): class SangaDeltaStage(SangaStage):
def __init__(self, port=None, flex_h=80, flex_a=50, flex_b=50, camera_angle=0, **kwargs): def __init__(
self, port=None, flex_h=80, flex_a=50, flex_b=50, camera_angle=0, **kwargs
):
self.flex_h = flex_h self.flex_h = flex_h
self.flex_a = flex_a self.flex_a = flex_a
self.flex_b = flex_b self.flex_b = flex_b
# Set up camera rotation relative to stage # Set up camera rotation relative to stage
camera_theta = (camera_angle/180)*np.pi camera_theta = (camera_angle / 180) * np.pi
self.R_camera = np.array([ self.R_camera = np.array(
[np.cos(camera_theta), -np.sin(camera_theta), 0], [
[np.sin(camera_theta), np.cos(camera_theta), 0], [np.cos(camera_theta), -np.sin(camera_theta), 0],
[0, 0, 1] [np.sin(camera_theta), np.cos(camera_theta), 0],
]) [0, 0, 1],
]
)
logging.debug(self.R_camera) logging.debug(self.R_camera)
# Transformation matrix converting delta into cartesian # Transformation matrix converting delta into cartesian
x_fac = -1 * np.multiply(np.divide(2, np.sqrt(3)), np.divide(self.flex_b, self.flex_h)) x_fac = -1 * np.multiply(
np.divide(2, np.sqrt(3)), np.divide(self.flex_b, self.flex_h)
)
y_fac = -1 * np.divide(self.flex_b, self.flex_h) y_fac = -1 * np.divide(self.flex_b, self.flex_h)
z_fac = np.multiply(np.divide(1, 3), np.divide(self.flex_b, self.flex_a)) z_fac = np.multiply(np.divide(1, 3), np.divide(self.flex_b, self.flex_a))
self.Tvd = np.array([ self.Tvd = np.array(
[-x_fac, x_fac, 0], [
[0.5 * y_fac, 0.5 * y_fac, -y_fac], [-x_fac, x_fac, 0],
[z_fac, z_fac, z_fac] [0.5 * y_fac, 0.5 * y_fac, -y_fac],
]) [z_fac, z_fac, z_fac],
]
)
logging.debug(self.Tvd) logging.debug(self.Tvd)
self.Tdv = np.linalg.inv(self.Tvd) self.Tdv = np.linalg.inv(self.Tvd)
logging.debug(self.Tdv) logging.debug(self.Tdv)
SangaStage.__init__(self, port=port, **kwargs) SangaStage.__init__(self, port=port, **kwargs)
@property @property
def position(self): def position(self):
# TODO: Account for camera rotation # TODO: Account for camera rotation
@ -253,4 +264,4 @@ class SangaDeltaStage(SangaStage):
logging.debug("Delta final: {}".format(final)) logging.debug("Delta final: {}".format(final))
# Do the move # Do the move
SangaStage.move_abs(self, final, **kwargs) SangaStage.move_abs(self, final, **kwargs)

View file

@ -1,22 +1,26 @@
import re
import copy
import operator
import base64 import base64
from uuid import UUID import copy
import numpy as np
import logging import logging
import operator
import re
import time import time
from collections import abc from collections import abc
from functools import reduce
from contextlib import contextmanager from contextlib import contextmanager
from functools import reduce
from uuid import UUID
import numpy as np
class Timer(object): class Timer(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
self.start = None self.start = None
self.end = None self.end = None
def __enter__(self): def __enter__(self):
self.start = time.time() self.start = time.time()
def __exit__(self, type, value, traceback): def __exit__(self, type, value, traceback):
self.end = time.time() self.end = time.time()
logging.debug(f"{self.name} time: {self.end - self.start}") logging.debug(f"{self.name} time: {self.end - self.start}")

View file

@ -61,3 +61,14 @@ sphinxcontrib-httpdomain = "^1.7"
rope = "^0.14.0" rope = "^0.14.0"
pylint = "^2.3" pylint = "^2.3"
black = {version = "^18.3-alpha.0",allow-prereleases = true} black = {version = "^18.3-alpha.0",allow-prereleases = true}
[tool.black]
exclude = '(\.eggs|\.git|\.venv)'
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88

View file

@ -1,7 +1,8 @@
from io import BytesIO
import numpy as np
import requests import requests
from PIL import Image from PIL import Image
from io import BytesIO
import numpy as np
class APIconnection: class APIconnection:

View file

@ -1,11 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from api_client import APIconnection
import numpy as np
import unittest
import logging import logging
import sys import sys
import unittest
import numpy as np
from api_client import APIconnection
logging.basicConfig(stream=sys.stderr, level=logging.INFO) logging.basicConfig(stream=sys.stderr, level=logging.INFO)

View file

@ -1,17 +1,15 @@
#!/usr/bin/env python #!/usr/bin/env python
from openflexure_microscope.camera.pi import PiCameraStreamer, CaptureObject
import os
import io import io
import logging
import os
import sys
import time import time
import numpy as np
from PIL import Image
import unittest import unittest
import logging import numpy as np
import sys from PIL import Image
from openflexure_microscope.camera.pi import CaptureObject, PiCameraStreamer
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
@ -30,9 +28,7 @@ class TestCaptureMethods(unittest.TestCase):
# Capture to a context (auto-deletes files when done) # Capture to a context (auto-deletes files when done)
with camera.new_image() as output: with camera.new_image() as output:
camera.capture( camera.capture(output, use_video_port=use_video_port, resize=resize)
output, use_video_port=use_video_port, resize=resize
)
# Ensure file deletion fails and returns False # Ensure file deletion fails and returns False
self.assertFalse(output.delete_file()) self.assertFalse(output.delete_file())

View file

@ -1,13 +1,13 @@
#!/usr/bin/env python #!/usr/bin/env python
from openflexure_microscope.camera.pi import PiCameraStreamer
from openflexure_stage import OpenFlexureStage
from openflexure_microscope import Microscope, config
import atexit import atexit
import logging
import sys
import unittest import unittest
import logging, sys from openflexure_stage import OpenFlexureStage
from openflexure_microscope import Microscope, config
from openflexure_microscope.camera.pi import PiCameraStreamer
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

View file

@ -1,12 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from openflexure_stage import OpenFlexureStage
import numpy as np
import unittest
import logging import logging
import sys import sys
import unittest
import numpy as np
from openflexure_stage import OpenFlexureStage
logging.basicConfig(stream=sys.stderr, level=logging.INFO) logging.basicConfig(stream=sys.stderr, level=logging.INFO)