From 44d02790f471839018166d06d19b4228f47b43f2 Mon Sep 17 00:00:00 2001 From: gac-x02da Date: Mon, 16 Jun 2025 20:29:59 +0200 Subject: [PATCH] fix(scan components): separate complete and restore config --- tomcat_bec/scans/simple_scans.py | 44 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/tomcat_bec/scans/simple_scans.py b/tomcat_bec/scans/simple_scans.py index 695dff8..243aa05 100644 --- a/tomcat_bec/scans/simple_scans.py +++ b/tomcat_bec/scans/simple_scans.py @@ -16,6 +16,7 @@ class TomoComponents: self.scan = scan self.stubs = scan.stubs self.device_manager = scan.device_manager + self.connector = scan.device_manager.connector # Update the available cameras for the current scan self.cameras = self._get_cameras() @@ -61,12 +62,15 @@ class TomoComponents: frames_per_trigger=frames_per_trigger, ) - def complete_and_restore_configs(self, name: str): + def complete(self): for cam in self.cameras: yield from self.stubs.send_rpc_and_wait(device=cam, func_name="on_complete") + + def restore_configs(self, name: str): + for cam in self.cameras: yield from self.stubs.send_rpc_and_wait( device=cam, func_name="restore_config", name=name - ) + ) def update_live_processing_references(self, ref_type: Literal["dark", "flat"]): """ @@ -95,6 +99,7 @@ class TomoComponents: if not num_images: return logger.info(f"Acquiring {num_images} dark images with exposure time {exposure_time}s.") + self.connector.send_client_info(f"Acquiring {num_images} dark images.") yield from self.restart_cameras( name=name, prefix=name, num_images=num_images, frames_per_trigger=1 @@ -103,12 +108,12 @@ class TomoComponents: for i in range(num_images): logger.debug(f"Acquiring dark image {i+1}/{num_images}.") yield from self.stubs.trigger(min_wait=exposure_time) - yield from self.stubs.read(group="monitored", point_id=self.scan.point_id) - self.scan.point_id += 1 - yield from self.complete_and_restore_configs(name=name) + yield from self.complete() yield from self.update_live_processing_references(ref_type="dark") + yield from self.restore_configs(name=name) # yield from self.open_shutter() + self.connector.send_client_info("") logger.info("Dark image acquisition complete.") def acquire_flat(self, num_images: int, exposure_time: float, name="flat"): @@ -122,6 +127,7 @@ class TomoComponents: if not num_images: return logger.info(f"Acquiring {num_images} flat images with exposure time {exposure_time}s.") + self.connector.send_client_info(f"Acquiring {num_images} flat images.") yield from self.restart_cameras( name=name, prefix=name, num_images=num_images, frames_per_trigger=1 @@ -130,11 +136,11 @@ class TomoComponents: for i in range(num_images): logger.debug(f"Acquiring flat image {i+1}/{num_images}.") yield from self.stubs.trigger(min_wait=exposure_time) - yield from self.stubs.read(group="monitored", point_id=self.scan.point_id) - self.scan.point_id += 1 - yield from self.complete_and_restore_configs(name=name) - yield from self.update_live_processing_references(ref_type="dark") + yield from self.complete() + yield from self.update_live_processing_references(ref_type="flat") + yield from self.restore_configs(name=name) logger.info("Flat image acquisition complete.") + self.connector.send_client_info("") def acquire_references(self, num_darks: int, num_flats: int, exp_time: float, name: str): yield from self.acquire_dark(num_darks, exposure_time=exp_time, name=name) @@ -184,23 +190,19 @@ class TomoScan(LineScan): self.num_flats = num_flats self.components = TomoComponents(self) - def prepare_positions(self): - yield from super().prepare_positions() - self.num_pos += 2 * (self.num_darks + self.num_flats) - def pre_scan(self): yield from self.components.acquire_dark(self.num_darks, self.exp_time, name="pre_scan_dark") yield from self.components.acquire_flat(self.num_flats, self.exp_time, name="pre_scan_flat") yield from super().pre_scan() - def finalize(self): - yield from super().finalize() - yield from self.components.acquire_dark( - self.num_darks, self.exp_time, name="post_scan_dark" - ) - yield from self.components.acquire_flat( - self.num_flats, self.exp_time, name="post_scan_flat" - ) + # def finalize(self): + # yield from super().finalize() + # yield from self.components.acquire_dark( + # self.num_darks, self.exp_time, name="post_scan_dark" + # ) + # yield from self.components.acquire_flat( + # self.num_flats, self.exp_time, name="post_scan_flat" + # ) class TomoFlyScan(AsyncFlyScanBase):