From e11fb31386a4dd3f16fccb58162ee3b47ef85f22 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Mon, 16 Jun 2025 22:36:00 +0200 Subject: [PATCH] wip --- tomcat_bec/scans/simple_scans.py | 64 ++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/tomcat_bec/scans/simple_scans.py b/tomcat_bec/scans/simple_scans.py index 96a758a..7344d0e 100644 --- a/tomcat_bec/scans/simple_scans.py +++ b/tomcat_bec/scans/simple_scans.py @@ -49,6 +49,16 @@ class TomoComponents: file_path: str = "", frames_per_trigger: int = 1, ): + """ + Restart the cameras with a new configuration. + This is typically used to reset the cameras during another scan, e.g. before acquiring dark or flat images. + Args: + name (str): Name of the configuration to restart with. + num_images (int): Number of images to acquire. + prefix (str): Prefix for the file names. + file_path (str): Path where the files will be saved. + frames_per_trigger (int): Number of frames to acquire per trigger. + """ if not prefix: return for cam in self.cameras: @@ -64,24 +74,32 @@ class TomoComponents: def scan_report_instructions(self): """ - Generate scan report instructions for the dark image acquisition. + Generate scan report instructions for the acquisition. This method provides the necessary instructions to listen to the camera progress during the scan. """ - if not self.components.cameras: - yield from super().scan_report_instructions() + if not self.cameras: return # Use the first camera or "gfcam" if available for reporting - report_camera = ( - "gfcam" if "gfcam" in self.components.cameras else self.components.cameras[0] - ) + report_camera = "gfcam" if "gfcam" in self.cameras else self.cameras[0] yield from self.stubs.scan_report_instruction({"device_progress": [report_camera]}) def complete(self): + """ + Complete the acquisition by sending an RPC to each camera. + This method is typically called after the acquisition is done to finalize the process and start + writing the virtual dataset. + """ 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): + """ + Restore the camera configurations after an acquisition. + + Args: + name (str): Name of the configuration to restore. + """ for cam in self.cameras: yield from self.stubs.send_rpc_and_wait( device=cam, func_name="restore_config", name=name @@ -121,7 +139,7 @@ class TomoComponents: name=name, prefix=name, num_images=num_images, frames_per_trigger=num_images ) # yield from self.close_shutter() - yield from self.stubs.trigger(min_wait=exposure_time) + yield from self.stubs.trigger(min_wait=exposure_time * num_images) yield from self.complete() yield from self.update_live_processing_references(ref_type="dark") if restart: @@ -149,7 +167,7 @@ class TomoComponents: name=name, prefix=name, num_images=num_images, frames_per_trigger=num_images ) # yield from self.open_shutter() - yield from self.stubs.trigger(min_wait=exposure_time) + yield from self.stubs.trigger(min_wait=exposure_time * num_images) yield from self.complete() yield from self.update_live_processing_references(ref_type="flat") @@ -165,8 +183,9 @@ class TomoComponents: class AcquireDark(ScanBase): scan_name = "acquire_dark" + gui_config = {"Acquisition Parameters": ["num_images", "exp_time"]} - def __init__(self, exp_time: float, frames_per_trigger: int = 1, **kwargs): + def __init__(self, num_images: int, exp_time: float, **kwargs): """ Acquire dark images. @@ -177,6 +196,7 @@ class AcquireDark(ScanBase): Returns: ScanReport """ + frames_per_trigger = num_images if num_images > 0 else 1 super().__init__(frames_per_trigger=frames_per_trigger, exp_time=exp_time, **kwargs) self.components = TomoComponents(self) @@ -184,22 +204,28 @@ class AcquireDark(ScanBase): yield from self.components.scan_report_instructions() def scan_core(self): - yield from self.components.acquire_dark(self.frames_per_trigger, self.exp_time, restart=False) + yield from self.components.acquire_dark( + self.frames_per_trigger, self.exp_time, restart=False + ) + class AcquireFlat(ScanBase): scan_name = "acquire_flat" + gui_config = {"Acquisition Parameters": ["num_images", "exp_time"]} - def __init__(self, exp_time: float, frames_per_trigger: int = 1, **kwargs): + def __init__(self, num_images: int, exp_time: float, **kwargs): """ Acquire flat images. Args: num_images (int): Number of flat images to acquire. exp_time (float): Exposure time for each flat image in seconds. + frames_per_trigger (int): Number of frames to acquire per trigger. Returns: ScanReport """ + frames_per_trigger = num_images if num_images > 0 else 1 super().__init__(frames_per_trigger=frames_per_trigger, exp_time=exp_time, **kwargs) self.components = TomoComponents(self) @@ -207,24 +233,29 @@ class AcquireFlat(ScanBase): yield from self.components.scan_report_instructions() def scan_core(self): - yield from self.components.acquire_flat(self.frames_per_trigger, self.exp_time, restart=False) + yield from self.components.acquire_flat( + self.frames_per_trigger, self.exp_time, restart=False + ) + class AcquireReferences(ScanBase): scan_name = "acquire_refs" + gui_config = {"Acquisition Parameters": ["num_darks", "num_flats", "exp_time"]} - def __init__(self, num_darks:int, num_flats:int, exp_time: float, frames_per_trigger: int = 1, **kwargs): + def __init__(self, num_darks: int, num_flats: int, exp_time: float, **kwargs): """ - Acquire flats and darks. + Acquire flats and darks. Args: num_darks (int): Number of dark images to acquire. num_flats (int): Number of flat images to acquire. exp_time (float): Exposure time for each flat image in seconds. + frames_per_trigger (int): Number of frames to acquire per trigger. Returns: ScanReport """ - super().__init__(frames_per_trigger=frames_per_trigger, exp_time=exp_time, **kwargs) + super().__init__(exp_time=exp_time, **kwargs) self.num_darks = num_darks self.num_flats = num_flats self.components = TomoComponents(self) @@ -233,7 +264,8 @@ class AcquireReferences(ScanBase): yield from self.components.scan_report_instructions() def scan_core(self): - yield from self.components.acquire_references(self.num_darks, self.num_flats, self.frames_per_trigger, self.exp_time, restart=False) + yield from self.components.acquire_references(self.num_darks, self.num_flats, self.exp_time) + class TomoScan(LineScan): scan_name = "tomo_line_scan"