From 05f3f679f1b8d7b6ebec911b602f79cc3c13ef91 Mon Sep 17 00:00:00 2001 From: Johannes Schabbauer <johannes.schabbauer@tuwien.ac.at> Date: Wed, 5 Mar 2025 09:53:53 +0100 Subject: [PATCH] DCAM: Added using bright pic for calculating occupation matrix. --- DCAMCamera/blacs_workers.py | 13 ++++++++----- DCAMCamera/labscript_devices.py | 23 ++++++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/DCAMCamera/blacs_workers.py b/DCAMCamera/blacs_workers.py index a98ac13..65f655f 100644 --- a/DCAMCamera/blacs_workers.py +++ b/DCAMCamera/blacs_workers.py @@ -213,7 +213,7 @@ class DCAM_Camera(object): return image - def grab_multiple(self, n_images, images, tweezer_socket=None, tweezer_img_no=None, get_occupation=None): + def grab_multiple(self, n_images, images, tweezer_socket=None, tweezer_img_no=None, bright_img_no=None, get_occupation=None): """Grab n_images into images array during buffered acquistion. Grab method involves a continuous loop with fast timeout in order to @@ -233,7 +233,10 @@ class DCAM_Camera(object): images.append(self.grab(bufferNo=i)) # Send image to occupation receiver if tweezer_socket and tweezer_img_no==i: - occupation = get_occupation(images[-1]) + if bright_img_no is not None: + occupation = get_occupation(images[-1]-images[bright_img_no]) + else: + occupation = get_occupation(images[-1]-200) metadata = dict(dtype=str(occupation.dtype), shape=occupation.shape) tweezer_socket.send_json(metadata, zmq.SNDMORE) tweezer_socket.send(occupation, copy=False) @@ -319,10 +322,10 @@ class DCAMCameraWorker(IMAQdxCameraWorker): self.images = [] if properties["occupation_receiver_image_index"] is not None: tweezers_centers = f["globals"].attrs["tweezers_centers"] - thresholds = f["globals"].attrs["thresholds"] - ROI_size = f["globals"].attrs["ROI_size"] + thresholds = f["globals"].attrs["tweezers_thresholds"] + ROI_size = f["globals"].attrs["tweezers_ROI"] get_occupation = lambda image: self.get_occupation(image,tweezers_centers,thresholds, ROI_size) - args = (self.n_images, self.images,self.tweezer_socket, properties["occupation_receiver_image_index"], get_occupation) + args = (self.n_images, self.images,self.tweezer_socket, properties["occupation_receiver_image_index"], properties.get("occupation_receiver_bright_index",None), get_occupation) else: # Standard args from IMAQdxCameraWorker args = (self.n_images, self.images) diff --git a/DCAMCamera/labscript_devices.py b/DCAMCamera/labscript_devices.py index bd52783..5845459 100644 --- a/DCAMCamera/labscript_devices.py +++ b/DCAMCamera/labscript_devices.py @@ -30,17 +30,26 @@ class DCAMCamera(IMAQdxCamera): self.exposure_times = [] super().__init__(name, parent_device, connection, serial_number, orientation, pixel_size, magnification, trigger_edge_type, trigger_duration, minimum_recovery_time, camera_attributes, manual_mode_camera_attributes, stop_acquisition_timeout, exception_on_failed_shot, saved_attribute_visibility_level, mock, **kwargs) - def expose(self, t, name, frametype='frame', trigger_duration=None, send_image_to_occupation_receiver=False): + def expose(self, t, name, frametype='frame', trigger_duration=None, occupation_receiver=False): self.exposure_times.append(t) - if send_image_to_occupation_receiver: - if getattr(self,"occupation_receiver_time",None) is not None: - raise LabscriptError(f"{self.name}: In the current implementation only a single image can be sent to the 'occupation receiver'") - self.occupation_receiver_time = t + if occupation_receiver: + if getattr(self,"occupation_receiver_time_"+occupation_receiver,None) is not None: + raise LabscriptError(f"{self.name}: In the current implementation only a single image and bright pic can be sent to the 'occupation receiver'") + if occupation_receiver not in ["atoms","bright"]: + raise LabscriptError(f"'occupation_receiver' can only be 'atoms' or 'bright'.") + setattr(self,"occupation_receiver_time_"+occupation_receiver, t) return super().expose(t, name, frametype, trigger_duration) def generate_code(self, hdf5_file): super().generate_code(hdf5_file) - if getattr(self,"occupation_receiver_time",None) is not None: - self.occupation_receiver_image_index = self.exposure_times.index(self.occupation_receiver_time) + if getattr(self,"occupation_receiver_time_atoms",None) is not None: + self.occupation_receiver_image_index = self.exposure_times.index(self.occupation_receiver_time_atoms) hdf5_file[f"devices/{self.name}"].attrs["occupation_receiver_image_index"] = self.occupation_receiver_image_index + if getattr(self,"occupation_receiver_time_bright",None) is not None: + self.occupation_receiver_bright_index = self.exposure_times.index(self.occupation_receiver_time_bright) + hdf5_file[f"devices/{self.name}"].attrs["occupation_receiver_bright_index"] = self.occupation_receiver_bright_index + # Error check: bright pic must be taken before atoms pic if we want to calculate occupoation matrix mid-shot + if self.occupation_receiver_image_index < self.occupation_receiver_bright_index: + raise LabscriptError("When calculation the occupation mid-shot, the bright pic must be taken before the atom pic!") + -- GitLab