Merge branch 'autofocus-error-messages' into 'master'
Autofocus error messages See merge request openflexure/openflexure-microscope-server!54
This commit is contained in:
commit
6fcd8caf91
1 changed files with 15 additions and 4 deletions
|
|
@ -50,6 +50,9 @@ class JPEGSharpnessMonitor:
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"Start monitoring sharpness by looking at JPEG size"
|
"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 = Thread(target=self._measure_jpegs)
|
||||||
self.background_thread.start()
|
self.background_thread.start()
|
||||||
return self
|
return self
|
||||||
|
|
@ -92,15 +95,20 @@ class JPEGSharpnessMonitor:
|
||||||
|
|
||||||
def move_data(self, istart, istop=None):
|
def move_data(self, istart, istop=None):
|
||||||
"Extract sharpness as a function of (interpolated) z"
|
"Extract sharpness as a function of (interpolated) z"
|
||||||
global np, logging
|
|
||||||
if istop is None:
|
if istop is None:
|
||||||
istop = istart + 2
|
istop = istart + 2
|
||||||
jpeg_times = np.array(self.jpeg_times)
|
jpeg_times = np.array(self.jpeg_times)
|
||||||
jpeg_sizes = np.array(self.jpeg_sizes)
|
jpeg_sizes = np.array(self.jpeg_sizes)
|
||||||
stage_times = np.array(self.stage_times)[istart:istop]
|
stage_times = np.array(self.stage_times)[istart:istop]
|
||||||
stage_zs = np.array(self.stage_positions)[istart:istop, 2]
|
stage_zs = np.array(self.stage_positions)[istart:istop, 2]
|
||||||
start = np.argmax(jpeg_times > stage_times[0])
|
try:
|
||||||
stop = np.argmax(jpeg_times > stage_times[1])
|
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:
|
if stop < 1:
|
||||||
stop = len(jpeg_times)
|
stop = len(jpeg_times)
|
||||||
logging.debug("changing stop to {}".format(stop))
|
logging.debug("changing stop to {}".format(stop))
|
||||||
|
|
@ -111,6 +119,8 @@ class JPEGSharpnessMonitor:
|
||||||
def sharpest_z_on_move(self, index):
|
def sharpest_z_on_move(self, index):
|
||||||
"""Return the z position of the sharpest image on a given move"""
|
"""Return the z position of the sharpest image on a given move"""
|
||||||
jt, jz, js = self.move_data(index)
|
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)]
|
return jz[np.argmax(js)]
|
||||||
|
|
||||||
def data_dict(self):
|
def data_dict(self):
|
||||||
|
|
@ -372,7 +382,8 @@ class FastAutofocusAPI(View):
|
||||||
|
|
||||||
|
|
||||||
autofocus_extension_v2 = BaseExtension(
|
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")
|
autofocus_extension_v2.add_method(fast_autofocus, "fast_autofocus")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue