DAQ: temporarily added timing log statements to evaluate how long steps take during automation

This commit is contained in:
2025-10-24 17:34:34 +02:00
parent 68fafa6b4e
commit e1f353f611
+17 -9
View File
@@ -1027,14 +1027,20 @@ class AareDAQ:
boxes = {}
angles = (90, 75, 60, 45, 30, 15, 0, -15, -30, -45, -60, -75, -90)
for angle in angles:
logger.debug(f'moving to angle: {angle}')
rotate_time = time.perf_counter()
self.__devs.aerotech.move(angle, wait=True)
logger.info(f"time to rotate 15 degrees: {time.perf_counter() - rotate_time}")
curr_image = cv2.cvtColor(self.camera_image, cv2.COLOR_RGB2BGR)
box_time = time.perf_counter()
box = self.__mlbox.predict(curr_image, "", pref_class = (3,0))
logger.info(f"time to predict: {time.perf_counter() - box_time}")
if box:
logger.info(f'found box: {box}')
cls, x1, y1, x2, y2 = box
boxes[angle] = (x1, y1, x2, y2)
if cls == 0:
#logger.info(f"loop all for angle {angle}")
logger.info(f"loop all for angle {angle}")
boxes[angle] = (x1, y1, x2, y2)
logger.info(f'box added to boxes: {boxes}')
elif cls == 3:
@@ -1140,13 +1146,13 @@ class AareDAQ:
found_angle = angle
found += 1
targets_found_this_attempt += 1
time_to_move_smargon = time.perf_counter()
self.__devs.smargon.target = target
self.__devs.smargon.wait(60)
logger.info(f"time to move smargon: {time.perf_counter() - time_to_move_smargon}")
if sample_id is not None:
print(sample_id)
self.__aare.sample_centered(self.__cfg.current_sample)
time.sleep(0.1)
self.save_screenshot_db(sample_id, f"{sample_id}_{angle}_{zoom_value:.0f}_{exp}_{gn}")
@@ -1195,12 +1201,12 @@ class AareDAQ:
return end - start
def save_screenshot(self, filename: str):
time.sleep(0.2) # Wait 200 ms to ensure camera image is stable
#time.sleep(0.2) # Wait 200 ms to ensure camera image is stable
bgr_image = cv2.cvtColor(self.camera_image, cv2.COLOR_RGB2BGR)
cv2.imwrite(f"{filename}.jpg", bgr_image)
def save_screenshot_db(self, sample_id: int, filename: str):
time.sleep(0.2) # Wait 200 ms to ensure camera image is stable
#time.sleep(0.2) # Wait 200 ms to ensure camera image is stable
bgr_image = cv2.cvtColor(self.camera_image, cv2.COLOR_RGB2BGR)
self.__aare.upload_image(sample_id, filename, bgr_image)
@@ -1249,16 +1255,16 @@ class AareDAQ:
self.__face_detection_sequence()
logger.info(f"face_detection done at {time.perf_counter() - start}")
self.zoom = 500
time.sleep(0.5)
hex_string = secrets.token_hex(3) # 3 bytes = 6 hex characters
print(hex_string.upper())
# self.__ml_bounding_box(sample.db_id, f"ml_{geom.omega_deg:.2f}deg")
#self.__ml_bounding_box(sample.db_id, f"ml_{geom.omega_deg:.2f}deg")
low_resolution_flag=False #False for high resolution
if low_resolution_flag:
det_dist = 300.0
else:
det_dist = 110.0
if self.__auto_center(RasterGridRequest(
exp_time_s=0.02,
file_prefix=sample_prefix + f"_{hex_string}",
@@ -1269,8 +1275,9 @@ class AareDAQ:
grid_size_mm=Coordinate(x=geom.beam_size_mm.x * 0.5, y=geom.beam_size_mm.y * 0.5),
omega_deg=0
)):
logger.info(f"raster scans done at {time.perf_counter() - start}")
params = self.smart_params
print(params)
logger.info(f"data collection stratergy params: {params}")
self.__cfg.zoom_mode = ZoomModeEnum.User
self.__devs.samcam_settings = self.__cfg.zoom_settings.get_camera_settings(self.zoom)
self.__rotation( RotationScanRequest(start_omega_deg=0,
@@ -1278,7 +1285,8 @@ class AareDAQ:
file_prefix=sample_prefix + f"_{hex_string}",
exp_time_s=0.04,
incr_omega_deg=0.2,
steps=900,))
steps=900,))
logger.info(f"rotation done at {time.perf_counter() - start}")
else:
print("auto center failed")
self.__aare.axc_failed(sample)