|
4 | 4 | import numpy as np
|
5 | 5 | from time import sleep
|
6 | 6 | from pathlib import Path
|
| 7 | +from qt3utils.errors import QT3Error |
7 | 8 | from typing import Any, Tuple, List, Union
|
8 | 9 |
|
9 | 10 | logging.basicConfig(level=logging.INFO)
|
@@ -110,54 +111,54 @@ def start_acquisition_and_wait(self) -> None:
|
110 | 111 | """
|
111 | 112 | Starts the acquisition process and waits until it is completed before carrying on.
|
112 | 113 | """
|
113 |
| - acquisition_time = self.get(lf.AddIns.CameraSettings.ShutterTimingExposureTime) |
| 114 | + acquisition_time_seconds = self.get(lf.AddIns.CameraSettings.ShutterTimingExposureTime) / 1000.0 |
114 | 115 | num_frames = self.get(lf.AddIns.ExperimentSettings.AcquisitionFramesToStore)
|
115 | 116 | self.experiment.Acquire()
|
116 |
| - |
117 |
| - sleep(0.001 * acquisition_time * num_frames) # waiting for the exposure duration |
| 117 | + |
| 118 | + sleep(num_frames * acquisition_time_seconds) |
118 | 119 |
|
119 | 120 | while self.experiment.IsRunning:
|
120 | 121 | sleep(0.1) # checking if the experiment is still running
|
121 | 122 |
|
122 |
| - def process_acquired_data(self) -> Union[np.ndarray, Any]: |
| 123 | + def process_acquired_data(self) -> np.ndarray: |
123 | 124 | """
|
124 | 125 | Processes the most recently acquired data and returns it as a numpy array.
|
125 | 126 | """
|
126 | 127 | last_file = self._application.FileManager.GetRecentlyAcquiredFileNames()[0]
|
127 |
| - curr_image = self._application.FileManager.OpenFile(last_file, FileAccess.Read) |
| 128 | + image_dataset = self._application.FileManager.OpenFile(last_file, FileAccess.Read) |
128 | 129 |
|
129 |
| - if curr_image.Regions.Length == 1: |
130 |
| - if curr_image.Frames == 1: |
131 |
| - return self._process_single_frame(curr_image) |
| 130 | + if image_dataset.Regions.Length == 1: |
| 131 | + if image_dataset.Frames == 1: |
| 132 | + return self._process_single_frame(image_dataset) |
132 | 133 | else:
|
133 |
| - return self._process_multiple_frames(curr_image) |
| 134 | + return self._process_multiple_frames(image_dataset) |
134 | 135 | else:
|
135 |
| - raise Exception('curr_image.Regions is not valid. Please retry.') |
| 136 | + raise QT3Error(f"LightField FileManager OpenFile error. Unsupported value for Regions.Length: {image_dataset.Regions.Length}.Should be == 1") |
136 | 137 |
|
137 |
| - def _process_single_frame(self, curr_image: Any) -> np.ndarray: |
| 138 | + def _process_single_frame(self, image_dataset: Any) -> np.ndarray: |
138 | 139 | """
|
139 | 140 | **Single Frame**:
|
140 | 141 | - Data is returned as a 2D array representing raw counts from each pixel.
|
141 | 142 | - A vertical section (spanning 400 pixels) represents a range for wavelength averaging.
|
142 | 143 | """
|
143 |
| - frame = curr_image.GetFrame(0, 0) |
| 144 | + frame = image_dataset.GetFrame(0, 0) |
144 | 145 | return np.reshape(np.fromiter(frame.GetData(), dtype='uint16'), [frame.Width, frame.Height], order='F')
|
145 | 146 |
|
146 |
| - def _process_multiple_frames(self, curr_image: Any) -> np.ndarray: |
| 147 | + def _process_multiple_frames(self, image_dataset: Any) -> np.ndarray: |
147 | 148 | """
|
148 | 149 | **Multiple Frames**:
|
149 | 150 | - Data from successive exposures is added as a new dimension, then returns a 3D array.
|
150 | 151 | - Averaging across frames can be done by summing over this additional dimension.
|
151 | 152 | """
|
152 | 153 | data = np.array([])
|
153 |
| - for i in range(curr_image.Frames): |
154 |
| - frame = curr_image.GetFrame(0, i) |
| 154 | + for i in range(image_dataset.Frames): |
| 155 | + frame = image_dataset.GetFrame(0, i) |
155 | 156 | new_frame = np.reshape(np.fromiter(frame.GetData(), dtype='uint16'), [frame.Width, frame.Height], order='F')
|
156 | 157 | data = np.dstack((data, new_frame)) if data.size else new_frame
|
157 | 158 | return data
|
158 | 159 |
|
159 | 160 | #NOTE: May not need to call the 'start_acquisition_and_wait' method if you fix the 'FileNameGeneration' issue
|
160 |
| - def acquire(self) -> Union[np.array, None]: |
| 161 | + def acquire(self) -> np.ndarray: |
161 | 162 | """
|
162 | 163 | Acquires image data from the spectrometer.
|
163 | 164 | """
|
@@ -240,14 +241,14 @@ def grating(self) -> str:
|
240 | 241 | return self.light.get(lf.AddIns.SpectrometerSettings.GratingSelected)
|
241 | 242 |
|
242 | 243 | @grating.setter
|
243 |
| - def grating(self, grating_string: str) -> None: |
| 244 | + def grating(self, value: str) -> None: |
244 | 245 | """
|
245 | 246 | Sets the current grating to be the one specified by parameter grating.
|
246 | 247 | """
|
247 |
| - if grating_string in self.grating_options: |
248 |
| - self.light.set(lf.AddIns.SpectrometerSettings.GratingSelected, grating_string) |
| 248 | + if value in self.grating_options: |
| 249 | + self.light.set(lf.AddIns.SpectrometerSettings.GratingSelected, value) |
249 | 250 | else:
|
250 |
| - logger.error(f"Grating {grating_string} is not an options. The options are: {self.grating_options}") |
| 251 | + logger.error(f"Grating {value} is not an options. The options are: {self.grating_options}") |
251 | 252 |
|
252 | 253 | @property
|
253 | 254 | def grating_options(self) -> List[str]:
|
@@ -311,7 +312,7 @@ def acquire_frame(self) -> Tuple[np.ndarray, np.ndarray]:
|
311 | 312 | """
|
312 | 313 | return self.light.acquire(), self.get_wavelengths()
|
313 | 314 |
|
314 |
| - def acquire_step_and_glue(self, wavelength_range: List[float]) -> Tuple[np.ndarray, np.ndarray]: |
| 315 | + def acquire_step_and_glue(self, wavelength_range: Tuple[float, float]) -> Tuple[np.ndarray, np.ndarray]: |
315 | 316 | """
|
316 | 317 | Acquires a step and glue (wavelength sweep) over the specified range.
|
317 | 318 | Wavelength range must have two elements (both in nm), corresponding
|
|
0 commit comments