From 265eed7bfac79ea03140cca1c540e9f3a9738d84 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 29 Jan 2020 16:16:09 +0000 Subject: [PATCH] Fixed picamera setup --- .../picamera_autocalibrate/extension.py | 4 ++-- .../api/v2/views/actions/stage.py | 2 +- openflexure_microscope/camera/pi.py | 10 ++++---- openflexure_microscope/microscope.py | 23 ++++++++----------- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/openflexure_microscope/api/default_extensions/picamera_autocalibrate/extension.py b/openflexure_microscope/api/default_extensions/picamera_autocalibrate/extension.py index 37cbe8cb..343a2c02 100644 --- a/openflexure_microscope/api/default_extensions/picamera_autocalibrate/extension.py +++ b/openflexure_microscope/api/default_extensions/picamera_autocalibrate/extension.py @@ -21,8 +21,8 @@ def recalibrate(microscope): """ scamera = microscope.camera with scamera.lock: - assert not scamera.status["record_active"], "Can't recalibrate while recording!" - streaming = scamera.status["stream_active"] + assert not scamera.record_active, "Can't recalibrate while recording!" + streaming = scamera.stream_active if streaming: logging.info("Stopping stream before recalibration") scamera.stop_stream_recording(resolution=(640, 480)) diff --git a/openflexure_microscope/api/v2/views/actions/stage.py b/openflexure_microscope/api/v2/views/actions/stage.py index 8b1020eb..6aa969bb 100644 --- a/openflexure_microscope/api/v2/views/actions/stage.py +++ b/openflexure_microscope/api/v2/views/actions/stage.py @@ -53,7 +53,7 @@ class MoveStageAPI(View): logging.warning("Unable to move. No stage found.") # TODO: Make schema for microscope status - return jsonify(microscope.status["stage"]["position"]) + return jsonify(microscope.state["stage"]["position"]) @ThingAction diff --git a/openflexure_microscope/camera/pi.py b/openflexure_microscope/camera/pi.py index 8f2a4d94..d1b71141 100644 --- a/openflexure_microscope/camera/pi.py +++ b/openflexure_microscope/camera/pi.py @@ -333,13 +333,13 @@ class PiCameraStreamer(BaseCamera): Change the camera zoom, handling re-centering and scaling. """ with self.lock: - self.status["zoom_value"] = float(zoom_value) - if self.status["zoom_value"] < 1: - self.status["zoom_value"] = 1 + self.zoom_value = float(zoom_value) + if self.zoom_value < 1: + self.zoom_value = 1 # Richard's code for zooming ! fov = self.camera.zoom centre = np.array([fov[0] + fov[2] / 2.0, fov[1] + fov[3] / 2.0]) - size = 1.0 / self.status["zoom_value"] + size = 1.0 / self.zoom_value # If the new zoom value would be invalid, move the centre to # keep it within the camera's sensor (this is only relevant # when zooming out, if the FoV is not centred on (0.5, 0.5) @@ -552,7 +552,7 @@ class PiCameraStreamer(BaseCamera): if isinstance(output, CaptureObject): target = output.file else: - target = target + target = output with self.lock: logging.info("Capturing to {}".format(output)) diff --git a/openflexure_microscope/microscope.py b/openflexure_microscope/microscope.py index b061bf32..f1023e13 100644 --- a/openflexure_microscope/microscope.py +++ b/openflexure_microscope/microscope.py @@ -76,7 +76,7 @@ class Microscope: ### Detector if configuration.get("camera"): camera_type = configuration["camera"].get("type") - if camera_type == "PiCamera" or camera_type == "PiCameraStreamer": + if camera_type in ("PiCamera", "PiCameraStreamer"): try: self.camera = PiCameraStreamer() except Exception as e: @@ -87,12 +87,8 @@ class Microscope: if configuration.get("stage"): stage_type = configuration["stage"].get("type") stage_port = configuration["stage"].get("port") - if stage_type == "SangaBoard" or camera_type == "SangaStage": - try: - self.stage = SangaStage(port=stage_port) - except Exception as e: - logging.error(e) - logging.warning("No compatible stage hardware found.") + if stage_type in ("SangaBoard", "SangaStage"): + self.stage = SangaStage(port=stage_port) ### Fallbacks if not self.camera: @@ -180,13 +176,14 @@ class Microscope: # Read LST. Returns None if no LST is active lst_arr = self.camera.read_lens_shading_table() - b64_string, dtype, shape = serialise_array_b64(lst_arr) + if lst_arr: + b64_string, dtype, shape = serialise_array_b64(lst_arr) - settings_current["camera"]["lens_shading_table"] = { - "b64_string": b64_string, - "dtype": dtype, - "shape": shape, - } + settings_current["camera"]["lens_shading_table"] = { + "b64_string": b64_string, + "dtype": dtype, + "shape": shape, + } # If attached to a stage if self.stage: