Correct data types in sharpness monitors

This commit is contained in:
jaknapper 2026-04-09 12:01:57 +01:00 committed by Joe Knapper
parent 500e08555c
commit ffa023dfa9

View file

@ -389,13 +389,17 @@ class JPEGSharpnessMonitor:
) )
return jpeg_heights[np.argmax(jpeg_sizes)] return jpeg_heights[np.argmax(jpeg_sizes)]
def data_dict(self) -> SharpnessDataArrays: def data_to_array(self) -> SharpnessDataArrays:
"""Return the gathered data as a single convenient dictionary.""" """Return the gathered data as SharpnessDataArrays."""
data = {} data = {}
for k in ["jpeg_times", "jpeg_sizes", "stage_times", "stage_positions"]: for k in ["jpeg_times", "jpeg_sizes", "stage_times", "stage_positions"]:
data[k] = getattr(self, k) data[k] = getattr(self, k)
return SharpnessDataArrays(**data) return SharpnessDataArrays(**data)
def data_dict(self) -> dict:
"""Return the gathered data as dict."""
return self.data_to_array().model_dump()
class AutofocusThing(lt.Thing): class AutofocusThing(lt.Thing):
"""The Thing concerned with combinations of z axis movements and the camera. """The Thing concerned with combinations of z axis movements and the camera.
@ -436,7 +440,7 @@ class AutofocusThing(lt.Thing):
# Move to the target position fz (relative move of (peak - current z)) # Move to the target position fz (relative move of (peak - current z))
sharpness_monitor.focus_rel(peak_z - base_z) sharpness_monitor.focus_rel(peak_z - base_z)
# Return all focus data # Return all focus data
return sharpness_monitor.data_dict() return sharpness_monitor.data_to_array()
@lt.action @lt.action
def z_move_and_measure_sharpness( def z_move_and_measure_sharpness(
@ -461,7 +465,7 @@ class AutofocusThing(lt.Thing):
if move_index > 0 and wait > 0: if move_index > 0 and wait > 0:
time.sleep(wait) time.sleep(wait)
sharpness_monitor.focus_rel(current_dz) sharpness_monitor.focus_rel(current_dz)
return sharpness_monitor.data_dict() return sharpness_monitor.data_to_array()
@lt.action @lt.action
def looping_autofocus( def looping_autofocus(
@ -841,7 +845,9 @@ class AutofocusThing(lt.Thing):
return final_z, z_positions return final_z, z_positions
@lt.action @lt.action
def measure_settling_time(self, delay: float = 2, dz: int = 800) -> dict: def measure_settling_time(
self, delay: float = 2, dz: int = 800
) -> SharpnessDataArrays:
"""Make a Z move down then up by dz, then pause for delay while monitoring sharpness. """Make a Z move down then up by dz, then pause for delay while monitoring sharpness.
This is useful to see how long to wait for the sharpness value to converge This is useful to see how long to wait for the sharpness value to converge
@ -850,7 +856,7 @@ class AutofocusThing(lt.Thing):
sharpness_monitor.focus_rel(-dz) sharpness_monitor.focus_rel(-dz)
sharpness_monitor.focus_rel(dz) sharpness_monitor.focus_rel(dz)
sharpness_monitor.hold(delay) sharpness_monitor.hold(delay)
return sharpness_monitor.data_dict() return sharpness_monitor.data_to_array()
class NotAPeakError(lt.exceptions.InvocationError): class NotAPeakError(lt.exceptions.InvocationError):