Merge branch 'autofocus-error-messages' into 'master'

Autofocus error messages

See merge request openflexure/openflexure-microscope-server!54
This commit is contained in:
Joel Collins 2020-04-24 15:14:37 +00:00
commit 6fcd8caf91

View file

@ -50,6 +50,9 @@ class JPEGSharpnessMonitor:
def start(self):
"Start monitoring sharpness by looking at JPEG size"
if not self.camera.stream_active:
logging.warn("Autofocus sharpness monitor was started but the camera isn't streaming. Attempting to start the stream...")
self.camera.start_stream_recording()
self.background_thread = Thread(target=self._measure_jpegs)
self.background_thread.start()
return self
@ -92,15 +95,20 @@ class JPEGSharpnessMonitor:
def move_data(self, istart, istop=None):
"Extract sharpness as a function of (interpolated) z"
global np, logging
if istop is None:
istop = istart + 2
jpeg_times = np.array(self.jpeg_times)
jpeg_sizes = np.array(self.jpeg_sizes)
stage_times = np.array(self.stage_times)[istart:istop]
stage_zs = np.array(self.stage_positions)[istart:istop, 2]
start = np.argmax(jpeg_times > stage_times[0])
stop = np.argmax(jpeg_times > stage_times[1])
try:
start = np.argmax(jpeg_times > stage_times[0])
stop = np.argmax(jpeg_times > stage_times[1])
except ValueError as e:
if np.sum(jpeg_times > stage_times[0]) == 0:
raise ValueError("No images were captured during the move of the stage. Perhaps the camera is not streaming images?")
else:
raise e
if stop < 1:
stop = len(jpeg_times)
logging.debug("changing stop to {}".format(stop))
@ -111,6 +119,8 @@ class JPEGSharpnessMonitor:
def sharpest_z_on_move(self, index):
"""Return the z position of the sharpest image on a given move"""
jt, jz, js = self.move_data(index)
if len(js) == 0:
raise ValueError("No images were captured during the move of the stage. Perhaps the camera is not streaming images?")
return jz[np.argmax(js)]
def data_dict(self):
@ -372,7 +382,8 @@ class FastAutofocusAPI(View):
autofocus_extension_v2 = BaseExtension(
"org.openflexure.autofocus", version="2.0.0"
"org.openflexure.autofocus", version="2.0.0",
description="Actions to move the microscope in Z and pick the point with the sharpest image."
)
autofocus_extension_v2.add_method(fast_autofocus, "fast_autofocus")