Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug(laser af): only catch Exception, print exec_info, indicate failure for caller in autofocus method #75

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions software/control/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,10 @@ def acquire_at_position(self, region_id, current_path, fov):
multipoint_custom_script_entry(self, current_path, region_id, fov)
return

self.perform_autofocus(region_id, fov)
if not self.perform_autofocus(region_id, fov):
self._log.error(
f"Autofocus failed in acquire_at_position. Continuing to acquire anyway using the current z position (z={self.stage.get_pos().z_mm} [mm])"
)

if self.NZ > 1:
self.prepare_z_stack()
Expand Down Expand Up @@ -1742,7 +1745,7 @@ def run_real_time_processing(self, current_round_images, z_level):
print(repr(e))

def perform_autofocus(self, region_id, fov):
if self.do_reflection_af == False:
if not self.do_reflection_af:
# contrast-based AF; perform AF only if when not taking z stack or doing z stack from center
if (
((self.NZ == 1) or self.z_stacking_config == "FROM CENTER")
Expand All @@ -1765,7 +1768,7 @@ def perform_autofocus(self, region_id, fov):
self.autofocusController.wait_till_autofocus_has_completed()
else:
# initialize laser autofocus if it has not been done
if self.microscope.laserAutofocusController.is_initialized == False:
if not self.microscope.laserAutofocusController.is_initialized:
self._log.info("init reflection af")
# initialize the reflection AF
self.microscope.laserAutofocusController.initialize_auto()
Expand All @@ -1792,13 +1795,16 @@ def perform_autofocus(self, region_id, fov):
self.microscope.laserAutofocusController.move_to_target(
0
) # for stepper in open loop mode, repeat the operation to counter backlash. It's harmless if any other case.
except:
except Exception as e:
file_ID = f"{region_id}_focus_camera.bmp"
saving_path = os.path.join(self.base_path, self.experiment_ID, str(self.time_point), file_ID)
iio.imwrite(saving_path, self.microscope.laserAutofocusController.image)
self._log.error(
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! laser AF failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! laser AF failed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
exc_info=e,
)
return False
return True

def prepare_z_stack(self):
# move to bottom of the z stack
Expand Down
Loading