From 628fd145f335823b68b2d95240b4249253a904b6 Mon Sep 17 00:00:00 2001 From: jaknapper Date: Tue, 20 May 2025 14:42:02 +0100 Subject: [PATCH] Cleaned up settling time maths to only calculate once --- src/openflexure_microscope_server/things/autofocus.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/openflexure_microscope_server/things/autofocus.py b/src/openflexure_microscope_server/things/autofocus.py index c5848e23..b651085a 100644 --- a/src/openflexure_microscope_server/things/autofocus.py +++ b/src/openflexure_microscope_server/things/autofocus.py @@ -318,7 +318,7 @@ class AutofocusThing(Thing): logger=logger, ) captured_time = time.time() - # There's an unnecessary move up at the end of the stack + if capture_count + 1 < images_to_capture: stage.move_relative(z=stack_dz) moved_time = time.time() @@ -332,11 +332,10 @@ class AutofocusThing(Thing): logger=logger, ) saved_time = time.time() - if saved_time - start_time < SETTLING_TIME: - time.sleep(SETTLING_TIME - (saved_time - start_time)) - logger.info( - f"Settled for an extra {round(SETTLING_TIME - (saved_time - start_time), 3)} seconds" - ) + time_remaining = SETTLING_TIME - (saved_time - start_time) + if time_remaining > 0: + time.sleep(time_remaining) + logger.info(f"Settled for an extra {round(time_remaining, 3)} seconds") logger.debug(f"Capturing took {round(captured_time - start_time, 2)} s") logger.debug(f"Resizing took {round(downsampled_time - moved_time, 2)} s") logger.debug(f"Saving took {round(saved_time - downsampled_time, 2)} s")