Ruff formating

This commit is contained in:
jaknapper 2025-05-07 10:44:54 +01:00 committed by Julian Stirling
parent 17f3bbe646
commit f5c1ff2621
4 changed files with 28 additions and 17 deletions

View file

@ -294,7 +294,7 @@ class AutofocusThing(Thing):
capture: CaptureDep,
images_dir: str,
stack_dir: str,
capture_method: str = 'array'
capture_method: str = "array",
) -> None:
"""Run a z stack, saving all images to stack_dir and copying the
central image to stack_dir"""
@ -308,13 +308,13 @@ class AutofocusThing(Thing):
time.sleep(SETTLING_TIME)
jpeg_path = os.path.join(
stack_dir,
f"{capture_count}.jpeg",
)
if capture_method == "blob":
stack_dir,
f"{capture_count}.jpeg",
)
if capture_method == "blob":
capture.capture_jpeg(filename=jpeg_path, cam=cam)
elif capture_method == "hires_array" or capture_method == "array":
stream = 'main' if capture_method == "array" else "full"
stream = "main" if capture_method == "array" else "full"
capture._capture_and_save(
jpeg_path=jpeg_path,
cam=cam,
@ -323,7 +323,9 @@ class AutofocusThing(Thing):
stream_name=stream,
)
else:
raise ValueError('Capture method must be one of "array", "blob" or "hires_array"')
raise ValueError(
'Capture method must be one of "array", "blob" or "hires_array"'
)
# If the stack isn't complete yet, move
if capture_count + 1 < images_to_capture:

View file

@ -83,12 +83,13 @@ class CameraProtocol(Protocol):
"""Start (or stop and restart) the camera in a configuration for low
res streaming and instant high res captures"""
...
def start_streaming(self) -> None:
"""Start (or stop and restart) the camera in the default streaming
configuration which balances stream and capture quality"""
...
class BaseCamera(Thing):
"""A Thing representing a camera
@ -197,12 +198,13 @@ class CameraStub(BaseCamera):
"""Start (or stop and restart) the camera in a configuration for low
res streaming and instant high res captures"""
raise NotImplementedError("Cameras must not inherit from CameraStub")
@thing_action
def start_streaming(self) -> None:
"""Start (or stop and restart) the camera in the default streaming
configuration which balances stream and capture quality"""
raise NotImplementedError("Cameras must not inherit from CameraStub")
CameraDependency = direct_thing_client_dependency(CameraStub, "/camera/")
RawCameraDependency = raw_thing_dependency(CameraProtocol)

View file

@ -60,7 +60,9 @@ class CaptureThing(Thing):
jpeg.save(filename)
return
except TimeoutError:
logger.warning(f'Attempt {capture_attempts+1} to capture image timed out. Do you have enough RAM?')
logger.warning(
f"Attempt {capture_attempts + 1} to capture image timed out. Do you have enough RAM?"
)
except Exception as e:
logger.warning(e)
raise CaptureError("An error occurred while capturing after 5 attempts")
@ -70,11 +72,17 @@ class CaptureThing(Thing):
cam.stop_streaming()
@thing_action
def restart_stream(self, cam:CamDep):
def restart_stream(self, cam: CamDep):
cam.restart_stream()
@thing_action
def _capture_array(self, cam: CamDep, metadata_getter: GetThingStates, logger: InvocationLogger, stream: str = 'main'):
def _capture_array(
self,
cam: CamDep,
metadata_getter: GetThingStates,
logger: InvocationLogger,
stream: str = "main",
):
"""Capture an image in memory and return it with metadata
CaptureError raised if the capture fails for any reason
returns tuple with numpy array of image data, and dict of metadata
@ -85,7 +93,9 @@ class CaptureThing(Thing):
image = cam.capture_array(stream_name=stream, wait=5)[..., :3]
return image, metadata
except TimeoutError:
logger.warning(f'Attempt {capture_attempts+1} to capture image timed out. Do you have enough RAM?')
logger.warning(
f"Attempt {capture_attempts + 1} to capture image timed out. Do you have enough RAM?"
)
raise CaptureError("An error occurred while capturing after 5 attempts")
def _save_capture(

View file

@ -410,7 +410,6 @@ class SmartScanThing(Thing):
test_image_res = list(test_image.shape)
csm_image_res = [int(i) for i in self._csm.image_resolution]
# If current stream width is different to csm calibration width,
# perform the conversion here
res_ratio = csm_image_res[0] / test_image_res[0]
@ -445,9 +444,7 @@ class SmartScanThing(Thing):
# self._stitch_resize = self._calc_resize_from_test_image()
self._stitch_resize = 0.25
self._scan_logger.info(
f'Resizing images by {self._stitch_resize}'
)
self._scan_logger.info(f"Resizing images by {self._stitch_resize}")
self._scan_logger.info(
f"Based on an overlap of {overlap}, we will make steps of {dx}, {dy}"