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)]
def data_dict(self) -> SharpnessDataArrays:
"""Return the gathered data as a single convenient dictionary."""
def data_to_array(self) -> SharpnessDataArrays:
"""Return the gathered data as SharpnessDataArrays."""
data = {}
for k in ["jpeg_times", "jpeg_sizes", "stage_times", "stage_positions"]:
data[k] = getattr(self, k)
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):
"""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))
sharpness_monitor.focus_rel(peak_z - base_z)
# Return all focus data
return sharpness_monitor.data_dict()
return sharpness_monitor.data_to_array()
@lt.action
def z_move_and_measure_sharpness(
@ -461,7 +465,7 @@ class AutofocusThing(lt.Thing):
if move_index > 0 and wait > 0:
time.sleep(wait)
sharpness_monitor.focus_rel(current_dz)
return sharpness_monitor.data_dict()
return sharpness_monitor.data_to_array()
@lt.action
def looping_autofocus(
@ -841,7 +845,9 @@ class AutofocusThing(lt.Thing):
return final_z, z_positions
@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.
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.hold(delay)
return sharpness_monitor.data_dict()
return sharpness_monitor.data_to_array()
class NotAPeakError(lt.exceptions.InvocationError):