Code format

This commit is contained in:
Joel Collins 2020-04-28 13:20:38 +01:00
parent ed8057ce04
commit 9646058c37
14 changed files with 381 additions and 201 deletions

View file

@ -13,7 +13,12 @@ import logging
# Type hinting
from typing import Tuple
from .recalibrate_utils import recalibrate_camera, auto_expose_and_freeze_settings, flat_lens_shading_table
from .recalibrate_utils import (
recalibrate_camera,
auto_expose_and_freeze_settings,
flat_lens_shading_table,
)
@contextmanager
def pause_stream(scamera, resolution: Tuple[int, int] = None):
@ -23,7 +28,9 @@ def pause_stream(scamera, resolution: Tuple[int, int] = None):
block has finished.
"""
with scamera.lock:
assert not scamera.record_active, "We can't pause the camera's video stream while a recording is in progress."
assert (
not scamera.record_active
), "We can't pause the camera's video stream while a recording is in progress."
streaming = scamera.stream_active
old_resolution = scamera.camera.resolution
if streaming:
@ -37,6 +44,7 @@ def pause_stream(scamera, resolution: Tuple[int, int] = None):
logging.info("Restarting stream in pause_stream context manager")
scamera.start_stream_recording()
def recalibrate(microscope):
"""Reset the camera's settings.
@ -45,7 +53,9 @@ def recalibrate(microscope):
with a gray level of 230. It takes a little while to run.
"""
with pause_stream(microscope.camera) as scamera:
auto_expose_and_freeze_settings(scamera.camera) # scamera.camera is the PiCamera object
auto_expose_and_freeze_settings(
scamera.camera
) # scamera.camera is the PiCamera object
recalibrate_camera(scamera.camera)
microscope.save_settings()
@ -63,13 +73,17 @@ class RecalibrateView(View):
return taskify(recalibrate)(microscope)
@ThingAction
class FlattenLSTView(View):
def post(self):
microscope = find_component("org.openflexure.microscope")
if not microscope:
abort(503, "No microscope connected. Unable to flatten the lens shading table.")
abort(
503,
"No microscope connected. Unable to flatten the lens shading table.",
)
try:
with pause_stream(microscope.camera) as scamera:
@ -78,7 +92,11 @@ class FlattenLSTView(View):
microscope.save_settings()
except:
logging.exception("Error flattening the lens shading table.")
abort(503, "Couldn't flatten the lens shading table - do you have the forked PiCamera library installed?")
abort(
503,
"Couldn't flatten the lens shading table - do you have the forked PiCamera library installed?",
)
@ThingAction
class DeleteLSTView(View):
@ -86,7 +104,10 @@ class DeleteLSTView(View):
microscope = find_component("org.openflexure.microscope")
if not microscope:
abort(503, "No microscope connected. Unable to flatten the lens shading table.")
abort(
503,
"No microscope connected. Unable to flatten the lens shading table.",
)
try:
with pause_stream(microscope.camera) as scamera:
@ -94,11 +115,16 @@ class DeleteLSTView(View):
microscope.save_settings()
except:
logging.exception("Error deleting the lens shading table.")
abort(503, "Couldn't flatten the lens shading table - do you have the forked PiCamera library installed?")
abort(
503,
"Couldn't flatten the lens shading table - do you have the forked PiCamera library installed?",
)
lst_extension_v2 = BaseExtension(
"org.openflexure.calibration.picamera", version="2.0.0-beta.1", description="Routines to perform flat-field correction on the camera."
"org.openflexure.calibration.picamera",
version="2.0.0-beta.1",
description="Routines to perform flat-field correction on the camera.",
)
lst_extension_v2.add_method(