More input validation and comments

This commit is contained in:
jaknapper 2025-06-23 12:01:41 +01:00
parent 7a7547542c
commit 333ea1b644
2 changed files with 8 additions and 0 deletions

View file

@ -212,6 +212,8 @@ class ScanPlanner:
def select_nearby_focus_site(self, xy_pos: XYPos) -> Optional[XYZPos]: def select_nearby_focus_site(self, xy_pos: XYPos) -> Optional[XYZPos]:
""" """
Return the xyz position of the nearby site with the lowest z position. Return the xyz position of the nearby site with the lowest z position.
Lowest position is best, as starting too high causes smart stacking to
autofocus and restart. Starting too low just requires extra movements in +z.
Nearby is defined as within 1.6 times the distance to the closest neighbour. Nearby is defined as within 1.6 times the distance to the closest neighbour.
Returns None if there if no focussed locations are present Returns None if there if no focussed locations are present

View file

@ -313,6 +313,10 @@ class AutofocusThing(Thing):
images_to_test = self.stack_images_to_test images_to_test = self.stack_images_to_test
stack_z_range = stack_dz * (images_to_test - 1) stack_z_range = stack_dz * (images_to_test - 1)
# Starting too low by "overshoot" makes smart stacking faster.
# Starting a stack too high requires it to move to the start,
# autofocus and then re-stack. Starting slightly too low only
# requires extra +z movements and captures.
overshoot = stack_dz * 5 overshoot = stack_dz * 5
# Ensure the stack settings are appropriate # Ensure the stack settings are appropriate
@ -533,6 +537,8 @@ class AutofocusThing(Thing):
) )
if images_to_test % 2 == 0: if images_to_test % 2 == 0:
raise RuntimeError("Images to test should be odd") raise RuntimeError("Images to test should be odd")
if images_to_test <= 0 or images_to_capture <= 0:
raise RuntimeError("Stack parameters need to be at least 1")
def check_stack_result(self, sharpnesses: list[int]) -> str: def check_stack_result(self, sharpnesses: list[int]) -> str:
"""Test a list of sharpnesses, to decide whether the sharpest image from a stack is within them """Test a list of sharpnesses, to decide whether the sharpest image from a stack is within them