Skip to content

Commit

Permalink
debug(laser af): only catch Exception, print exec_info, indicate fail…
Browse files Browse the repository at this point in the history
…ure for caller in autofocus method
  • Loading branch information
ianohara committed Jan 20, 2025
1 parent 560142b commit ea3ad25
Showing 1 changed file with 11 additions and 5 deletions.
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

0 comments on commit ea3ad25

Please sign in to comment.