DAQ: fixed bugs in raster calls and updated error handling in raster and rotation scans

This commit is contained in:
2026-04-23 11:00:32 +02:00
parent 17815b1503
commit d7c7d03788
+49 -27
View File
@@ -50,7 +50,8 @@ from aare.common.exception_handler import (
AXCFailed,
SmargonCommunicationError,
TellCommunicationError,
JFJochCommunicationError, AerotechCommunicationError, MagnetPositionSensorErorr, UnmountingFailed
JFJochCommunicationError, AerotechCommunicationError, MagnetPositionSensorErorr, UnmountingFailed,
DataCollectionException, RasterScanException
)
logger = setup_logger("aareDAQ")
@@ -280,6 +281,16 @@ class AareDAQ:
self.__aare.ingest_scan(sample=self.sample, result=result.result,
geom=self.sample_geometry, beam_mark_pxl=self.__cfg.get_beam_mark(self.zoom))
return result
except JFJochCommunicationError as e:
logger.error(f"Rotation sequence failed due to JFJoch Communication error: {e}")
self._handle_operation_error(
operation=DAQOperation.ROTATION,
sample=self.sample,
error=e,
event_type=SampleEventType.COLLECTIONFAILED,
additional_comment=f"JFJoch communication error: {e}"
)
return None
except Exception as e:
logger.error(f"Rotation sequence failed: {e}")
self._handle_operation_error(
@@ -807,6 +818,7 @@ class AareDAQ:
res1 = self.__raster(grid)
grid.omega_deg += 90
self.__devs.aerotech_omega = grid.omega_deg
self.__set_state(BeamlineStateEnum.XtalSnapshot)
grid.n_x = 1
#TODO generate y scan rather than had code for 1x50
@@ -942,12 +954,10 @@ class AareDAQ:
if request.n_x == 1:
x = request.grid_size_mm.x / 2.0
y = ((request.n_y - 1) * request.grid_size_mm.y) / 2.0
grid_centre_offset = self.sample_geometry.smargon_nudge(Coordinate(x=x, y=y))
else:
x = ((request.n_x - 1) * request.grid_size_mm.x) / 2.0
y = ((request.n_y - 1) * request.grid_size_mm.y) / 2.0
grid_centre_offset = self.sample_geometry.smargon_nudge(Coordinate(x=x, y=y))
y = ((request.n_y - 1) * request.grid_size_mm.y) / 2.0
grid_centre_offset = self.sample_geometry.smargon_nudge(Coordinate(x=x, y=y))
logger.info(f"moving Smargon to grid centre offset {grid_centre_offset}")
@@ -967,15 +977,16 @@ class AareDAQ:
else:
scan_result = self.__jfjoch.wait_till_done(60)
if scan_result is None:
logger.warning("JFJoch returned no ScanResult; using fake result for raster scan.")
scan_result = self._build_fake_scan_result(
file_prefix=request.file_prefix,
image_count=request.n_x * request.n_y,
)
logger.warning("JFJoch returned no ScanResult")#; using fake result for raster scan.")
# scan_result = self._build_fake_scan_result(
# file_prefix=request.file_prefix,
# image_count=request.n_x * request.n_y,
# )
sample_id = self.sample.db_id if self.sample and self.sample.db_id is not None else None
if sample_id:
self.__set_state(BeamlineStateEnum.SampleAlignment)
logger.debug(f"moving to XtalSnapshot to take a screenshot of the sample")
self.__set_state(BeamlineStateEnum.XtalSnapshot)
self.save_screenshot_db(sample_id, f"{sample_id}_post_raster_{request.omega_deg}deg")
self.__aare.ingest_gridscan(
sample=self.sample,
@@ -1016,7 +1027,7 @@ class AareDAQ:
result = self._execute_raster_sequence(r, auto_center=auto_center)
if result is None:
raise Exception("Raster scan failed")
raise RasterScanException("Raster scan failed")
self.__set_state(BeamlineStateEnum.SampleAlignment)
self.__cfg.state_busy = False
return result
@@ -1078,23 +1089,10 @@ class AareDAQ:
result = self.__jfjoch.wait_till_done(60)
except JFJochCommunicationError as e:
self._handle_operation_error(
operation=DAQOperation.ROTATION,
sample=self.sample,
error=e,
event_type=SampleEventType.COLLECTIONFAILED,
additional_comment="JFJoch Communication Error",
)
logger.error(f"Exception during rotation scan related to JFJoch: {e}")
raise
except Exception as e:
logger.error(f"Exception during rotation scan: {e}")
self._handle_operation_error(
operation=DAQOperation.ROTATION,
sample=self.sample,
error=e,
event_type=SampleEventType.COLLECTIONFAILED,
additional_comment=None,
)
raise
return result
@@ -1117,7 +1115,8 @@ class AareDAQ:
result = self._execute_rotation_sequence(request)
if result is None:
raise Exception("Rotation scan failed")
raise DataCollectionException("Rotation scan failed, no result returned")
self.__set_state(BeamlineStateEnum.SampleAlignment)
self.__cfg.state_busy = False
return result
except Exception as e:
@@ -1941,6 +1940,7 @@ class AareDAQ:
if error:
msg += f"with an error"
self.__set_state(BeamlineStateEnum.RobotSampleExchange)
else:
msg += f"successfully"
logger.error(f"{msg}, time taken {time.perf_counter() - start} seconds.")
@@ -1975,6 +1975,7 @@ class AareDAQ:
if not self._execute_mount_and_prepare(sample):
return self._end_operation(start, DAQOperation.MOUNT, error=True)
self.__set_state(BeamlineStateEnum.SampleAlignment)
logger.info(f"mounting done at {time.perf_counter() - start}")
@@ -2010,6 +2011,7 @@ class AareDAQ:
if raster_result is None:
logger.error("Raster result was None")
return self._end_operation(start, DAQOperation.RASTER, error=True)
self.__set_state(BeamlineStateEnum.DataCollection)
logger.info(f"Raster scans completed at {time.perf_counter() - start}")
@@ -2089,6 +2091,12 @@ class AareDAQ:
case BeamlineStateEnum.DewarTransfer:
if target == BeamlineStateEnum.SampleAlignment:
workflows.dh2sa(self.__devs, self.__cfg)
elif target == BeamlineStateEnum.RobotSampleExchange:
workflows.dh2sa(self.__devs, self.__cfg)
workflows.sa2rse(self.__devs, self.__cfg)
elif target == BeamlineStateEnum.SampleExchange:
workflows.dh2sa(self.__devs, self.__cfg)
workflows.sa2se(self.__devs, self.__cfg)
else:
raise TransformationInvalidException()
case BeamlineStateEnum.DataCollection:
@@ -2096,6 +2104,8 @@ class AareDAQ:
workflows.dc2sa(self.__devs, self.__cfg)
elif target == BeamlineStateEnum.RobotSampleExchange:
workflows.dc2rse(self.__devs, self.__cfg)
elif target == BeamlineStateEnum.XtalSnapshot:
workflows.sa2xtal_snapshot(self.__devs, self.__cfg)
else:
raise TransformationInvalidException()
case BeamlineStateEnum.BeamLocation:
@@ -2119,6 +2129,8 @@ class AareDAQ:
workflows.sa2xrf(self.__devs, self.__cfg)
elif target == BeamlineStateEnum.BeamLocation:
workflows.sa2bl(self.__devs, self.__cfg)
elif target == BeamlineStateEnum.XtalSnapshot:
workflows.sa2xtal_snapshot(self.__devs, self.__cfg)
else:
raise TransformationInvalidException()
case BeamlineStateEnum.XrayFluorescence:
@@ -2131,6 +2143,16 @@ class AareDAQ:
workflows.rse2sa(self.__devs, self.__cfg)
else:
raise TransformationInvalidException()
case BeamlineStateEnum.XtalSnapshot:
if target == BeamlineStateEnum.SampleAlignment:
workflows.xtal_snapshot2sa(self.__devs, self.__cfg)
elif target == BeamlineStateEnum.SampleExchange:
workflows.xtal_snapshot2sa(self.__devs, self.__cfg)
workflows.sa2se(self.__devs, self.__cfg)
elif target == BeamlineStateEnum.DataCollection:
workflows.xtal_snapshot2dc(self.__devs, self.__cfg)
else:
raise TransformationInvalidException()
self.__cfg.state = target
except TransformationInvalidException as e:
self.__cfg.state = curr_state