DAQ: fix bug in facedetection if result is None.
Build and Publish / test (push) Successful in 1m30s
Build and Publish / build (push) Successful in 17s
Build and Publish / Build and Deploy Docs (push) Successful in 36s

This commit is contained in:
2026-05-01 14:24:57 +02:00
parent 34e8a4bfd5
commit 16fe6e9ef4
+51 -19
View File
@@ -49,7 +49,7 @@ from aare.common.automation_models import (
from aare.common.raster_grid import RasterGridRequest, CompletedRasterGrid, CompletedRasterGridElem, grid_to_image_id
from aare.common.rotation_scan import RotationScanRequest, CompletedRotationScan
from aare.common.sample_geometry import SampleGeometryModel
from aare.daq.operations.face_detection import FaceDetectionContext, FaceDetectionService
from aare.daq.operations.face_detection import FaceDetectionContext, FaceDetectionService, FaceDetectionResult
from aare.daq.operations.loop_centering import LoopCenteringService, LoopCenteringContext
from aare.daq.operations.loop_centering.models import LoopCenteringSettings
@@ -545,10 +545,17 @@ class AareDAQ:
FaceDetectionResult
"""
self.__set_state(BeamlineStateEnum.SampleAlignment)
result = None
result: FaceDetectionResult | None = None
try:
self.__aare.send_sample_event(self.sample, SampleEventType.LOOPFACEDETECTING)
try:
sample = self.sample
except Exception:
sample = None
aare = getattr(self, "_AareDAQ__aare", None)
if aare is not None:
aare.send_sample_event(sample, SampleEventType.LOOPFACEDETECTING)
result = self._create_face_detection_service().run(
steps=steps,
@@ -556,30 +563,55 @@ class AareDAQ:
face_min_ratio=face_min_ratio,
)
if not result.success and report_error:
self._handle_operation_error(
operation=DAQOperation.FACE_CENTERING,
sample=self.sample,
error=result.error or Exception("Face detection failed"),
event_type=SampleEventType.LOOPFACEDETECTFAILED,
additional_comment=result.comment,
)
return False
if not result.success:
if report_error:
self._handle_operation_error(
operation=DAQOperation.FACE_CENTERING,
sample=sample,
error=result.error or Exception("Face detection failed"),
event_type=SampleEventType.LOOPFACEDETECTFAILED,
additional_comment=result.comment,
)
return result
self.__aare.send_sample_event(self.sample, SampleEventType.LOOPFACEDETECTED)
if aare is not None:
aare.send_sample_event(sample, SampleEventType.LOOPFACEDETECTED)
return result
except Exception as e:
logger.error(f"Face detection failed: {e}")
additional_comment = f"{e}" if e is not None else ""
self._handle_operation_error(
operation=DAQOperation.FACE_CENTERING,
sample=self.sample,
try:
sample = self.sample
except Exception:
sample = None
if report_error:
self._handle_operation_error(
operation=DAQOperation.FACE_CENTERING,
sample=sample,
error=e,
event_type=SampleEventType.LOOPFACEDETECTFAILED,
additional_comment=additional_comment,
)
payload = (
result.payload
if result is not None
else {
"running": False,
"samples": [],
"height_fit": {},
"area_fit": {},
}
)
return FaceDetectionResult(
success=False,
payload=payload,
error=e,
event_type=SampleEventType.LOOPFACEDETECTFAILED,
additional_comment=additional_comment,
comment=additional_comment,
)
return False
def _execute_raster_sequence(self, grid_request: RasterGridRequest,
auto_center: bool = False) -> CompletedRasterGrid | None: