Ruff formating
This commit is contained in:
parent
17f3bbe646
commit
f5c1ff2621
4 changed files with 28 additions and 17 deletions
|
|
@ -294,7 +294,7 @@ class AutofocusThing(Thing):
|
||||||
capture: CaptureDep,
|
capture: CaptureDep,
|
||||||
images_dir: str,
|
images_dir: str,
|
||||||
stack_dir: str,
|
stack_dir: str,
|
||||||
capture_method: str = 'array'
|
capture_method: str = "array",
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Run a z stack, saving all images to stack_dir and copying the
|
"""Run a z stack, saving all images to stack_dir and copying the
|
||||||
central image to stack_dir"""
|
central image to stack_dir"""
|
||||||
|
|
@ -308,13 +308,13 @@ class AutofocusThing(Thing):
|
||||||
time.sleep(SETTLING_TIME)
|
time.sleep(SETTLING_TIME)
|
||||||
|
|
||||||
jpeg_path = os.path.join(
|
jpeg_path = os.path.join(
|
||||||
stack_dir,
|
stack_dir,
|
||||||
f"{capture_count}.jpeg",
|
f"{capture_count}.jpeg",
|
||||||
)
|
)
|
||||||
if capture_method == "blob":
|
if capture_method == "blob":
|
||||||
capture.capture_jpeg(filename=jpeg_path, cam=cam)
|
capture.capture_jpeg(filename=jpeg_path, cam=cam)
|
||||||
elif capture_method == "hires_array" or capture_method == "array":
|
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(
|
capture._capture_and_save(
|
||||||
jpeg_path=jpeg_path,
|
jpeg_path=jpeg_path,
|
||||||
cam=cam,
|
cam=cam,
|
||||||
|
|
@ -323,7 +323,9 @@ class AutofocusThing(Thing):
|
||||||
stream_name=stream,
|
stream_name=stream,
|
||||||
)
|
)
|
||||||
else:
|
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 the stack isn't complete yet, move
|
||||||
if capture_count + 1 < images_to_capture:
|
if capture_count + 1 < images_to_capture:
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ class CameraProtocol(Protocol):
|
||||||
configuration which balances stream and capture quality"""
|
configuration which balances stream and capture quality"""
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class BaseCamera(Thing):
|
class BaseCamera(Thing):
|
||||||
"""A Thing representing a camera
|
"""A Thing representing a camera
|
||||||
|
|
||||||
|
|
@ -204,5 +205,6 @@ class CameraStub(BaseCamera):
|
||||||
configuration which balances stream and capture quality"""
|
configuration which balances stream and capture quality"""
|
||||||
raise NotImplementedError("Cameras must not inherit from CameraStub")
|
raise NotImplementedError("Cameras must not inherit from CameraStub")
|
||||||
|
|
||||||
|
|
||||||
CameraDependency = direct_thing_client_dependency(CameraStub, "/camera/")
|
CameraDependency = direct_thing_client_dependency(CameraStub, "/camera/")
|
||||||
RawCameraDependency = raw_thing_dependency(CameraProtocol)
|
RawCameraDependency = raw_thing_dependency(CameraProtocol)
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,9 @@ class CaptureThing(Thing):
|
||||||
jpeg.save(filename)
|
jpeg.save(filename)
|
||||||
return
|
return
|
||||||
except TimeoutError:
|
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:
|
except Exception as e:
|
||||||
logger.warning(e)
|
logger.warning(e)
|
||||||
raise CaptureError("An error occurred while capturing after 5 attempts")
|
raise CaptureError("An error occurred while capturing after 5 attempts")
|
||||||
|
|
@ -70,11 +72,17 @@ class CaptureThing(Thing):
|
||||||
cam.stop_streaming()
|
cam.stop_streaming()
|
||||||
|
|
||||||
@thing_action
|
@thing_action
|
||||||
def restart_stream(self, cam:CamDep):
|
def restart_stream(self, cam: CamDep):
|
||||||
cam.restart_stream()
|
cam.restart_stream()
|
||||||
|
|
||||||
@thing_action
|
@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
|
"""Capture an image in memory and return it with metadata
|
||||||
CaptureError raised if the capture fails for any reason
|
CaptureError raised if the capture fails for any reason
|
||||||
returns tuple with numpy array of image data, and dict of metadata
|
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]
|
image = cam.capture_array(stream_name=stream, wait=5)[..., :3]
|
||||||
return image, metadata
|
return image, metadata
|
||||||
except TimeoutError:
|
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")
|
raise CaptureError("An error occurred while capturing after 5 attempts")
|
||||||
|
|
||||||
def _save_capture(
|
def _save_capture(
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,6 @@ class SmartScanThing(Thing):
|
||||||
test_image_res = list(test_image.shape)
|
test_image_res = list(test_image.shape)
|
||||||
csm_image_res = [int(i) for i in self._csm.image_resolution]
|
csm_image_res = [int(i) for i in self._csm.image_resolution]
|
||||||
|
|
||||||
|
|
||||||
# If current stream width is different to csm calibration width,
|
# If current stream width is different to csm calibration width,
|
||||||
# perform the conversion here
|
# perform the conversion here
|
||||||
res_ratio = csm_image_res[0] / test_image_res[0]
|
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 = self._calc_resize_from_test_image()
|
||||||
self._stitch_resize = 0.25
|
self._stitch_resize = 0.25
|
||||||
|
|
||||||
self._scan_logger.info(
|
self._scan_logger.info(f"Resizing images by {self._stitch_resize}")
|
||||||
f'Resizing images by {self._stitch_resize}'
|
|
||||||
)
|
|
||||||
|
|
||||||
self._scan_logger.info(
|
self._scan_logger.info(
|
||||||
f"Based on an overlap of {overlap}, we will make steps of {dx}, {dy}"
|
f"Based on an overlap of {overlap}, we will make steps of {dx}, {dy}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue