Added calibration data download view
This commit is contained in:
parent
cda5cdbb44
commit
a1f3dd1624
1 changed files with 31 additions and 4 deletions
|
|
@ -6,26 +6,32 @@ This file contains the HTTP API for camera/stage calibration.
|
||||||
from labthings.server.view import View
|
from labthings.server.view import View
|
||||||
from labthings.server.find import find_component
|
from labthings.server.find import find_component
|
||||||
from labthings.server.extensions import BaseExtension
|
from labthings.server.extensions import BaseExtension
|
||||||
from labthings.server.decorators import marshal_task, ThingAction, use_args
|
from labthings.server.decorators import marshal_task, ThingAction, use_args, ThingProperty
|
||||||
from labthings.server import fields
|
from labthings.server import fields
|
||||||
|
|
||||||
from labthings.core.tasks import taskify
|
from labthings.core.tasks import taskify
|
||||||
from labthings.core.utilities import get_by_path, set_by_path, create_from_path
|
from labthings.core.utilities import get_by_path, set_by_path, create_from_path
|
||||||
|
|
||||||
|
|
||||||
from flask import abort, jsonify
|
from flask import abort, send_file
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import PIL
|
import PIL
|
||||||
import io
|
import io
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
from .camera_stage_calibration_1d import calibrate_backlash_1d, image_to_stage_displacement_from_1d
|
from .camera_stage_calibration_1d import calibrate_backlash_1d, image_to_stage_displacement_from_1d
|
||||||
from .camera_stage_tracker import Tracker
|
from .camera_stage_tracker import Tracker
|
||||||
|
|
||||||
from openflexure_microscope.utilities import axes_to_array
|
from openflexure_microscope.utilities import axes_to_array
|
||||||
|
from openflexure_microscope.paths import data_file_path
|
||||||
|
from openflexure_microscope.config import JSONEncoder
|
||||||
|
|
||||||
|
CSM_DATAFILE_NAME = "csm_calibration.json"
|
||||||
|
CSM_DATAFILE_PATH = data_file_path(CSM_DATAFILE_NAME)
|
||||||
|
|
||||||
class CSMExtension(BaseExtension):
|
class CSMExtension(BaseExtension):
|
||||||
"""
|
"""
|
||||||
|
|
@ -39,6 +45,7 @@ class CSMExtension(BaseExtension):
|
||||||
)
|
)
|
||||||
|
|
||||||
_microscope = None
|
_microscope = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def microscope(self):
|
def microscope(self):
|
||||||
# TODO: does caching the microscope actually help?
|
# TODO: does caching the microscope actually help?
|
||||||
|
|
@ -96,12 +103,18 @@ class CSMExtension(BaseExtension):
|
||||||
# Combine X and Y calibrations to make a 2D calibration
|
# Combine X and Y calibrations to make a 2D calibration
|
||||||
cal_xy = image_to_stage_displacement_from_1d([cal_x, cal_y])
|
cal_xy = image_to_stage_displacement_from_1d([cal_x, cal_y])
|
||||||
self.update_settings(cal_xy)
|
self.update_settings(cal_xy)
|
||||||
return {
|
|
||||||
|
data = {
|
||||||
"camera_stage_mapping_calibration": cal_xy,
|
"camera_stage_mapping_calibration": cal_xy,
|
||||||
"linear_calibration_x": cal_x,
|
"linear_calibration_x": cal_x,
|
||||||
"linear_calibration_y": cal_y,
|
"linear_calibration_y": cal_y,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
with open(CSM_DATAFILE_PATH, 'w') as f:
|
||||||
|
json.dump(data, f, cls=JSONEncoder)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def image_to_stage_displacement_matrix(self):
|
def image_to_stage_displacement_matrix(self):
|
||||||
try:
|
try:
|
||||||
|
|
@ -161,7 +174,21 @@ class MoveInImageCoordinatesView(View):
|
||||||
"""Move the microscope stage, such that we move by a given number of pixels on the camera"""
|
"""Move the microscope stage, such that we move by a given number of pixels on the camera"""
|
||||||
csm_extension.move_in_image_coordinates(np.array([args.get("x"), args.get("y")]))
|
csm_extension.move_in_image_coordinates(np.array([args.get("x"), args.get("y")]))
|
||||||
|
|
||||||
return jsonify(csm_extension.microscope.state["stage"]["position"])
|
return csm_extension.microscope.state["stage"]["position"]
|
||||||
|
|
||||||
csm_extension.add_view(MoveInImageCoordinatesView, "/move_in_image_coordinates")
|
csm_extension.add_view(MoveInImageCoordinatesView, "/move_in_image_coordinates")
|
||||||
|
|
||||||
|
@ThingProperty
|
||||||
|
class GetCalibrationFile(View):
|
||||||
|
def get(self):
|
||||||
|
"""Get the calibration data in JSON format."""
|
||||||
|
datafile_name = CSM_DATAFILE_NAME
|
||||||
|
datafile_path = CSM_DATAFILE_PATH
|
||||||
|
|
||||||
|
if os.path.isfile(datafile_path):
|
||||||
|
with open(datafile_path, 'rb') as f:
|
||||||
|
return json.load(f)
|
||||||
|
else:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
csm_extension.add_view(GetCalibrationFile, "/get_calibration")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue