Loading openflexure_microscope/api/v1/blueprints/base.py +41 −3 Original line number Diff line number Diff line from openflexure_microscope.api.utilities import gen from openflexure_microscope.api.utilities import gen, JsonPayload from openflexure_microscope.api.v1.views import MicroscopeView from flask import Response, Blueprint, jsonify from flask import Response, Blueprint, jsonify, request class StreamAPI(MicroscopeView): Loading Loading @@ -81,7 +81,7 @@ class ConfigAPI(MicroscopeView): """ JSON representation of the microscope config. .. :quickref: Config; Microscope config .. :quickref: Config; Get microscope config **Example request**: Loading Loading @@ -138,6 +138,44 @@ class ConfigAPI(MicroscopeView): """ return jsonify(self.microscope.config) def post(self): """ Modify microscope configuration .. :quickref: Config; Set microscope config **Example request**: .. sourcecode:: http POST /config HTTP/1.1 Accept: application/json { "analog_gain": 1.0, "digital_gain": 1.0, "jpeg_quality": 75, "picamera_params": { "framerate": 24.0, "saturation": 0, "shutter_speed": 5000 } } :>header Accept: application/json :<header Content-Type: application/json :status 200: capture created """ payload = JsonPayload(request) print(payload.json) self.microscope.config = payload.json return jsonify(self.microscope.config) def construct_blueprint(microscope_obj): blueprint = Blueprint('base_blueprint', __name__) Loading openflexure_microscope/api/v1/blueprints/camera/__init__.py +0 −5 Original line number Diff line number Diff line Loading @@ -31,9 +31,4 @@ def construct_blueprint(microscope_obj): '/preview/<string:operation>', view_func=preview.GPUPreviewAPI.as_view('gpu_preview', microscope=microscope_obj)) # Config routes blueprint.add_url_rule( '/config', view_func=config.ConfigAPI.as_view('camera_config', microscope=microscope_obj)) return(blueprint) No newline at end of file openflexure_microscope/api/v1/blueprints/camera/config.pydeleted 100644 → 0 +0 −73 Original line number Diff line number Diff line from openflexure_microscope.api.utilities import JsonPayload from openflexure_microscope.api.v1.views import MicroscopeView from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file import logging class ConfigAPI(MicroscopeView): def get(self): """ Get camera configuration .. :quickref: Camera config; Get camera configuration """ return jsonify(self.microscope.camera.config) def post(self): """ Modify camera configuration .. :quickref: Camera config; Set camera configuration **Example request**: .. sourcecode:: http POST /camera/capture HTTP/1.1 Accept: application/json { "analog_gain": 1.0, "digital_gain": 1.0, "jpeg_quality": 75, "picamera_params": { "framerate": 24.0, "saturation": 0, "shutter_speed": 5000 } } :>header Accept: application/json :<json float analog_gain: Analog gain :<json float digital_gain: Digital gain :<json list image_resolution: Image resolution in format [x, y] :<json list video_resolution: Video resolution in format [x, y] :<json list numpy_resolution: Raw numpy array resolution in format [x, y] :<json int jpeg_quality: JPEG quality (1-100) :<json string shading_table_path: Full path on the Pi to the lens shading table npy file :<json json picamera_param: - **awb_gains** *(list)*: Auto-white-balance gains in format [r, g, b] **awb_mode** *(string)*: PiCamera AWB mode **exposure_mode** *(string)*: PiCamera exposure mode **framerate** *(float)*: PiCamera framerate **saturation** *(int)*: PiCamera saturation **shutter_speed** *(string)*: PiCamera shutter speed :<header Content-Type: application/json :status 200: capture created """ payload = JsonPayload(request) print(payload.json) self.microscope.camera.config = payload.json return jsonify(self.microscope.camera.config) No newline at end of file openflexure_microscope/microscope.py +24 −5 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ class Microscope(object): self.attach(camera, stage) # Store entire runtime-config self.config = config self._config = config # Create plugin mountpoint self.plugin = PluginMount(self) #: :py:class:`openflexure_microscope.plugins.PluginMount`: Mounting point for all microscope plugins Loading @@ -42,8 +42,8 @@ class Microscope(object): self.attach_plugins() # Get name from config, or generate if not 'name' in self.config: self.config['name'] = uuid.uuid4().hex if not 'name' in self._config: self._config['name'] = uuid.uuid4().hex def __enter__(self): """Create microscope on context enter.""" Loading Loading @@ -105,8 +105,8 @@ class Microscope(object): """ Automatically search for plugin maps in self.config, and attach. """ if 'plugins' in self.config: self.attach_plugin_maps(self.config['plugins']) if 'plugins' in self._config: self.attach_plugin_maps(self._config['plugins']) else: logging.warning("No plugins specified in microscoperc.yaml. Skipping.") Loading Loading @@ -152,3 +152,22 @@ class Microscope(object): state['camera'] = self.camera.state return state @property def config(self): # If attached to a camera if self.camera: # Update camera config params from StreamingCamera object self._config.update(self.camera.config) return self._config @config.setter def config(self, config: dict) -> None: # If attached to a camera if self.camera: # Update camera config self.camera.config = config # Cache config self._config.update(config) No newline at end of file Loading
openflexure_microscope/api/v1/blueprints/base.py +41 −3 Original line number Diff line number Diff line from openflexure_microscope.api.utilities import gen from openflexure_microscope.api.utilities import gen, JsonPayload from openflexure_microscope.api.v1.views import MicroscopeView from flask import Response, Blueprint, jsonify from flask import Response, Blueprint, jsonify, request class StreamAPI(MicroscopeView): Loading Loading @@ -81,7 +81,7 @@ class ConfigAPI(MicroscopeView): """ JSON representation of the microscope config. .. :quickref: Config; Microscope config .. :quickref: Config; Get microscope config **Example request**: Loading Loading @@ -138,6 +138,44 @@ class ConfigAPI(MicroscopeView): """ return jsonify(self.microscope.config) def post(self): """ Modify microscope configuration .. :quickref: Config; Set microscope config **Example request**: .. sourcecode:: http POST /config HTTP/1.1 Accept: application/json { "analog_gain": 1.0, "digital_gain": 1.0, "jpeg_quality": 75, "picamera_params": { "framerate": 24.0, "saturation": 0, "shutter_speed": 5000 } } :>header Accept: application/json :<header Content-Type: application/json :status 200: capture created """ payload = JsonPayload(request) print(payload.json) self.microscope.config = payload.json return jsonify(self.microscope.config) def construct_blueprint(microscope_obj): blueprint = Blueprint('base_blueprint', __name__) Loading
openflexure_microscope/api/v1/blueprints/camera/__init__.py +0 −5 Original line number Diff line number Diff line Loading @@ -31,9 +31,4 @@ def construct_blueprint(microscope_obj): '/preview/<string:operation>', view_func=preview.GPUPreviewAPI.as_view('gpu_preview', microscope=microscope_obj)) # Config routes blueprint.add_url_rule( '/config', view_func=config.ConfigAPI.as_view('camera_config', microscope=microscope_obj)) return(blueprint) No newline at end of file
openflexure_microscope/api/v1/blueprints/camera/config.pydeleted 100644 → 0 +0 −73 Original line number Diff line number Diff line from openflexure_microscope.api.utilities import JsonPayload from openflexure_microscope.api.v1.views import MicroscopeView from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file import logging class ConfigAPI(MicroscopeView): def get(self): """ Get camera configuration .. :quickref: Camera config; Get camera configuration """ return jsonify(self.microscope.camera.config) def post(self): """ Modify camera configuration .. :quickref: Camera config; Set camera configuration **Example request**: .. sourcecode:: http POST /camera/capture HTTP/1.1 Accept: application/json { "analog_gain": 1.0, "digital_gain": 1.0, "jpeg_quality": 75, "picamera_params": { "framerate": 24.0, "saturation": 0, "shutter_speed": 5000 } } :>header Accept: application/json :<json float analog_gain: Analog gain :<json float digital_gain: Digital gain :<json list image_resolution: Image resolution in format [x, y] :<json list video_resolution: Video resolution in format [x, y] :<json list numpy_resolution: Raw numpy array resolution in format [x, y] :<json int jpeg_quality: JPEG quality (1-100) :<json string shading_table_path: Full path on the Pi to the lens shading table npy file :<json json picamera_param: - **awb_gains** *(list)*: Auto-white-balance gains in format [r, g, b] **awb_mode** *(string)*: PiCamera AWB mode **exposure_mode** *(string)*: PiCamera exposure mode **framerate** *(float)*: PiCamera framerate **saturation** *(int)*: PiCamera saturation **shutter_speed** *(string)*: PiCamera shutter speed :<header Content-Type: application/json :status 200: capture created """ payload = JsonPayload(request) print(payload.json) self.microscope.camera.config = payload.json return jsonify(self.microscope.camera.config) No newline at end of file
openflexure_microscope/microscope.py +24 −5 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ class Microscope(object): self.attach(camera, stage) # Store entire runtime-config self.config = config self._config = config # Create plugin mountpoint self.plugin = PluginMount(self) #: :py:class:`openflexure_microscope.plugins.PluginMount`: Mounting point for all microscope plugins Loading @@ -42,8 +42,8 @@ class Microscope(object): self.attach_plugins() # Get name from config, or generate if not 'name' in self.config: self.config['name'] = uuid.uuid4().hex if not 'name' in self._config: self._config['name'] = uuid.uuid4().hex def __enter__(self): """Create microscope on context enter.""" Loading Loading @@ -105,8 +105,8 @@ class Microscope(object): """ Automatically search for plugin maps in self.config, and attach. """ if 'plugins' in self.config: self.attach_plugin_maps(self.config['plugins']) if 'plugins' in self._config: self.attach_plugin_maps(self._config['plugins']) else: logging.warning("No plugins specified in microscoperc.yaml. Skipping.") Loading Loading @@ -152,3 +152,22 @@ class Microscope(object): state['camera'] = self.camera.state return state @property def config(self): # If attached to a camera if self.camera: # Update camera config params from StreamingCamera object self._config.update(self.camera.config) return self._config @config.setter def config(self, config: dict) -> None: # If attached to a camera if self.camera: # Update camera config self.camera.config = config # Cache config self._config.update(config) No newline at end of file