diff --git a/docs/source/extensions/example_extension/03_marshaling_data.py b/docs/source/extensions/example_extension/03_marshaling_data.py index f9ad668d..d3179c10 100644 --- a/docs/source/extensions/example_extension/03_marshaling_data.py +++ b/docs/source/extensions/example_extension/03_marshaling_data.py @@ -14,7 +14,7 @@ from labthings.server import fields class MicroscopeIdentifySchema(Schema): name = fields.String() # Microscopes name id = fields.UUID() # Microscopes unique ID - status = fields.Dict() # Status dictionary + state = fields.Dict() # Status dictionary camera = fields.String() # Camera object (represented as a string) stage = fields.String() # Stage object (represented as a string) diff --git a/docs/source/extensions/example_extension/04_properties.py b/docs/source/extensions/example_extension/04_properties.py index 45ee6c18..922270a5 100644 --- a/docs/source/extensions/example_extension/04_properties.py +++ b/docs/source/extensions/example_extension/04_properties.py @@ -19,7 +19,7 @@ from labthings.server import fields class MicroscopeIdentifySchema(Schema): name = fields.String() # Microscopes name id = fields.UUID() # Microscopes unique ID - status = fields.Dict() # Status dictionary + state = fields.Dict() # Status dictionary camera = fields.String() # Camera object (represented as a string) stage = fields.String() # Stage object (represented as a string) diff --git a/docs/source/extensions/example_extension/05_actions.py b/docs/source/extensions/example_extension/05_actions.py index 027580e8..dc3826a0 100644 --- a/docs/source/extensions/example_extension/05_actions.py +++ b/docs/source/extensions/example_extension/05_actions.py @@ -24,7 +24,7 @@ import io # Used in our capture action class MicroscopeIdentifySchema(Schema): name = fields.String() # Microscopes name id = fields.UUID() # Microscopes unique ID - status = fields.Dict() # Status dictionary + state = fields.Dict() # Status dictionary camera = fields.String() # Camera object (represented as a string) stage = fields.String() # Stage object (represented as a string) diff --git a/docs/source/extensions/marshaling.rst b/docs/source/extensions/marshaling.rst index 10ab188e..1f09162a 100644 --- a/docs/source/extensions/marshaling.rst +++ b/docs/source/extensions/marshaling.rst @@ -107,7 +107,7 @@ We start by creating a schema to describe how to serialise a :py:class:`openflex class MicroscopeIdentifySchema(Schema): name = fields.String() # Microscopes name id = fields.UUID() # Microscopes unique ID - status = fields.Dict() # Status dictionary + state = fields.Dict() # Status dictionary camera = fields.String() # Camera object (represented as a string) stage = fields.String() # Stage object (represented as a string) diff --git a/openflexure_microscope/api/app.py b/openflexure_microscope/api/app.py index e3aa1404..ce0d1068 100644 --- a/openflexure_microscope/api/app.py +++ b/openflexure_microscope/api/app.py @@ -94,16 +94,18 @@ labthing.add_view(views.CaptureDownload, f"/captures//download/") labthing.add_view(views.CaptureTags, f"/captures//tags") labthing.add_view(views.CaptureAnnotations, f"/captures//annotations") -# Attach settings and status resources -labthing.add_view(views.SettingsProperty, f"/settings") -labthing.add_root_link(views.SettingsProperty, "settings") -labthing.add_view(views.NestedSettingsProperty, "/settings/") -labthing.add_view(views.StatusProperty, "/status") -labthing.add_view(views.NestedStatusProperty, "/status/") -labthing.add_root_link(views.StatusProperty, "status") -labthing.add_view(views.ConfigurationProperty, "/configuration") -labthing.add_view(views.NestedConfigurationProperty, "/configuration/") -labthing.add_root_link(views.ConfigurationProperty, "configuration") +# Attach settings and state resources +labthing.add_view(views.SettingsProperty, f"/instrument/settings") +labthing.add_root_link(views.SettingsProperty, "instrumentSettings") +labthing.add_view(views.NestedSettingsProperty, "/instrument/settings/") +labthing.add_view(views.StateProperty, "/instrument/state") +labthing.add_view(views.NestedStateProperty, "/instrument/state/") +labthing.add_root_link(views.StateProperty, "instrumentState") +labthing.add_view(views.ConfigurationProperty, "/instrument/configuration") +labthing.add_view( + views.NestedConfigurationProperty, "/instrument/configuration/" +) +labthing.add_root_link(views.ConfigurationProperty, "instrumentConfiguration") # Attach streams resources diff --git a/openflexure_microscope/api/default_extensions/zip_builder.py b/openflexure_microscope/api/default_extensions/zip_builder.py index 02032c65..a57a3ad1 100644 --- a/openflexure_microscope/api/default_extensions/zip_builder.py +++ b/openflexure_microscope/api/default_extensions/zip_builder.py @@ -73,17 +73,15 @@ class ZipManager: # Update task progress update_task_progress(int((index / n_files) * 100)) - session_id = uuid.uuid4() - session_key = str(session_id) - # self.session_zips[session_id] = fp - self.session_zips[session_key] = { + session_id = str(uuid.uuid4()) + self.session_zips[session_id] = { "id": session_id, "fp": fp, "data_size": data_size_megabytes, "zip_size": os.path.getsize(fp.name) * 1e-6, } - return self.session_zips[session_key] + return self.session_zips[session_id] def zip_from_id(self, session_id): return self.session_zips[session_id]["fp"] @@ -103,13 +101,13 @@ class ZipBuilderAPIView(View): task = taskify(default_zip_manager.build_zip_from_capture_ids)(microscope, ids) # Return a handle on the autofocus task - return jsonify(task.state), 201 + return task.state, 201 @ThingProperty class ZipListAPIView(View): def get(self): - return jsonify(default_zip_manager.session_zips) + return default_zip_manager.session_zips class ZipGetterAPIView(View): @@ -141,7 +139,7 @@ class ZipGetterAPIView(View): del default_zip_manager.session_zips[session_id] - return jsonify({"return": session_id}) + return {"return": session_id} zip_extension_v2 = BaseExtension("org.openflexure.zipbuilder", version="2.0.0-beta.1") diff --git a/openflexure_microscope/api/v2/views/__init__.py b/openflexure_microscope/api/v2/views/__init__.py index a998c703..3c1fae87 100644 --- a/openflexure_microscope/api/v2/views/__init__.py +++ b/openflexure_microscope/api/v2/views/__init__.py @@ -1,4 +1,4 @@ from .actions import enabled_root_actions from .captures import * -from .state import * +from .instrument import * from .streams import * diff --git a/openflexure_microscope/api/v2/views/actions/camera.py b/openflexure_microscope/api/v2/views/actions/camera.py index 8b618193..62f777d7 100644 --- a/openflexure_microscope/api/v2/views/actions/camera.py +++ b/openflexure_microscope/api/v2/views/actions/camera.py @@ -163,8 +163,8 @@ class GPUPreviewStartAPI(View): microscope.camera.start_preview(fullscreen=fullscreen, window=window) - # TODO: Make schema for microscope status - return jsonify(microscope.status) + # TODO: Make schema for microscope state + return jsonify(microscope.state) @ThingAction @@ -175,5 +175,5 @@ class GPUPreviewStopAPI(View): """ microscope = find_component("org.openflexure.microscope") microscope.camera.stop_preview() - # TODO: Make schema for microscope status - return jsonify(microscope.status) + # TODO: Make schema for microscope state + return jsonify(microscope.state) diff --git a/openflexure_microscope/api/v2/views/actions/stage.py b/openflexure_microscope/api/v2/views/actions/stage.py index 6aa969bb..5cf4059e 100644 --- a/openflexure_microscope/api/v2/views/actions/stage.py +++ b/openflexure_microscope/api/v2/views/actions/stage.py @@ -52,7 +52,7 @@ class MoveStageAPI(View): else: logging.warning("Unable to move. No stage found.") - # TODO: Make schema for microscope status + # TODO: Make schema for microscope state return jsonify(microscope.state["stage"]["position"]) @@ -66,5 +66,5 @@ class ZeroStageAPI(View): microscope = find_component("org.openflexure.microscope") microscope.stage.zero_position() - # TODO: Make schema for microscope status - return jsonify(microscope.status["stage"]) + # TODO: Make schema for microscope state + return jsonify(microscope.state["stage"]) diff --git a/openflexure_microscope/api/v2/views/state.py b/openflexure_microscope/api/v2/views/instrument.py similarity index 98% rename from openflexure_microscope/api/v2/views/state.py rename to openflexure_microscope/api/v2/views/instrument.py index 7f22323c..633d73ff 100644 --- a/openflexure_microscope/api/v2/views/state.py +++ b/openflexure_microscope/api/v2/views/instrument.py @@ -72,7 +72,7 @@ class NestedSettingsProperty(View): @ThingProperty -class StatusProperty(View): +class StateProperty(View): def get(self): """ Show current read-only state of the microscope @@ -82,7 +82,7 @@ class StatusProperty(View): @Tag("properties") -class NestedStatusProperty(View): +class NestedStateProperty(View): @doc_response(404, description="Status key cannot be found") def get(self, route): """ diff --git a/openflexure_microscope/camera/base.py b/openflexure_microscope/camera/base.py index e823cfd0..2dd16dc4 100644 --- a/openflexure_microscope/camera/base.py +++ b/openflexure_microscope/camera/base.py @@ -91,20 +91,6 @@ class CameraEvent(object): class BaseCamera(metaclass=ABCMeta): """ Base implementation of StreamingCamera. - - Attributes: - thread: Background thread reading frames from camera - camera: Camera object - lock (:py:class:`labthings.lock.StrictLock`): Strict lock controlling thread - access to stage hardware - frame (bytes): Current frame is stored here by background thread - last_access (time): Time of last client access to the camera - stream_timeout (int): Number of inactive seconds before timing out the stream - stream_timeout_enabled (bool): Enable or disable timing out the stream - status (dict): Dictionary for capture state - paths (dict): Dictionary of capture paths - images (list): List of image capture objects - videos (list): List of video capture objects """ def __init__(self): diff --git a/openflexure_microscope/camera/pi.py b/openflexure_microscope/camera/pi.py index d1b71141..85628042 100644 --- a/openflexure_microscope/camera/pi.py +++ b/openflexure_microscope/camera/pi.py @@ -85,7 +85,7 @@ class PiCameraStreamer(BaseCamera): picamera.PiCamera() ) #: :py:class:`picamera.PiCamera`: Picamera object - # Store status of PiCameraStreamer + # Store state of PiCameraStreamer self.preview_active = False # Reset variable states @@ -157,7 +157,7 @@ class PiCameraStreamer(BaseCamera): "picamera_lst_path": self.picamera_lst_path if os.path.isfile(self.picamera_lst_path) else None, - "picamera_settings": {}, + "picamera": {}, } ) @@ -166,7 +166,7 @@ class PiCameraStreamer(BaseCamera): try: value = getattr(self.camera, key) logging.debug("Reading PiCamera().{}: {}".format(key, value)) - conf_dict["picamera_settings"][key] = value + conf_dict["picamera"][key] = value except AttributeError: logging.debug("Unable to read PiCamera attribute {}".format(key)) @@ -204,14 +204,14 @@ class PiCameraStreamer(BaseCamera): paused_stream = True # Remember to unpause stream when done # PiCamera parameters - if "picamera_settings" in config: # If new settings are given + if "picamera" in config: # If new settings are given self.apply_picamera_settings( - config["picamera_settings"], pause_for_effect=True + config["picamera"], pause_for_effect=True ) # PiCameraStreamer parameters for key, value in config.items(): # For each provided setting - if (key != "picamera_settings") and hasattr(self, key): + if (key != "picamera") and hasattr(self, key): setattr(self, key, value) # Handle lens shading if camera supports it @@ -412,7 +412,7 @@ class PiCameraStreamer(BaseCamera): quality=quality, ) - # Update status dictionary + # Update state self.record_active = True return output @@ -432,7 +432,7 @@ class PiCameraStreamer(BaseCamera): self.camera.stop_recording(splitter_port=2) logging.info("Recording stopped") - # Update status dictionary + # Update state self.record_active = False def stop_stream_recording( @@ -681,7 +681,6 @@ class PiCameraStreamer(BaseCamera): # Start stream recording (and set resolution) self.start_stream_recording() - # Update status logging.debug("STREAM ACTIVE") # While the iterator is not closed diff --git a/openflexure_microscope/config.py b/openflexure_microscope/config.py index 5172a07c..8bbe796a 100644 --- a/openflexure_microscope/config.py +++ b/openflexure_microscope/config.py @@ -94,11 +94,14 @@ class JSONEncoder(flask.json.JSONEncoder): # Numpy arrays elif isinstance(o, np.ndarray): return o.tolist() + # UUIDs + elif isinstance(o, UUID): + return str(o) else: # call base class implementation which takes care of # raising exceptions for unsupported types try: - return json.JSONEncoder.default(self, o) + return flask.json.JSONEncoder.default(self, o) # if it's some mystery object, just return a string representation except TypeError: return str(o) diff --git a/openflexure_microscope/microscope.py b/openflexure_microscope/microscope.py index 19c01be7..1e397339 100644 --- a/openflexure_microscope/microscope.py +++ b/openflexure_microscope/microscope.py @@ -120,13 +120,13 @@ class Microscope: else: return False - # Create unified status + # Create unified state @property def state(self): - """Dictionary of the basic microscope status. + """Dictionary of the basic microscope state. Return: - dict: Dictionary containing complete microscope status + dict: Dictionary containing complete microscope state """ state = {"camera": self.camera.state, "stage": self.stage.state} return state @@ -216,7 +216,7 @@ class Microscope: initial_configuration = self.configuration_file.load() current_configuration = { - "@application": { + "application": { "name": "openflexure_microscope", "version": pkg_resources.get_distribution( "openflexure_microscope" diff --git a/openflexure_microscope/stage/mock.py b/openflexure_microscope/stage/mock.py index e4810f3c..fe523c64 100644 --- a/openflexure_microscope/stage/mock.py +++ b/openflexure_microscope/stage/mock.py @@ -18,9 +18,9 @@ class MissingStage(BaseStage): @property def state(self): - """The general status dictionary of the board.""" - status = {"position": self.position_map} - return status + """The general state dictionary of the board.""" + state = {"position": self.position_map} + return state @property def configuration(self): diff --git a/openflexure_microscope/stage/sanga.py b/openflexure_microscope/stage/sanga.py index 11ffbbc6..d5ffcf15 100644 --- a/openflexure_microscope/stage/sanga.py +++ b/openflexure_microscope/stage/sanga.py @@ -33,7 +33,7 @@ class SangaStage(BaseStage): @property def state(self): - """The general status dictionary of the board.""" + """The general state dictionary of the board.""" return {"position": self.position_map} @property