Skip to content

Commit 071617f

Browse files
committed
fixed variable names and type hints
1 parent b03a875 commit 071617f

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/qt3utils/datagenerators/princeton.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
from time import sleep
66
from pathlib import Path
7+
from qt3utils.errors import QT3Error
78
from typing import Any, Tuple, List, Union
89

910
logging.basicConfig(level=logging.INFO)
@@ -110,54 +111,54 @@ def start_acquisition_and_wait(self) -> None:
110111
"""
111112
Starts the acquisition process and waits until it is completed before carrying on.
112113
"""
113-
acquisition_time = self.get(lf.AddIns.CameraSettings.ShutterTimingExposureTime)
114+
acquisition_time_seconds = self.get(lf.AddIns.CameraSettings.ShutterTimingExposureTime) / 1000.0
114115
num_frames = self.get(lf.AddIns.ExperimentSettings.AcquisitionFramesToStore)
115116
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)
118119

119120
while self.experiment.IsRunning:
120121
sleep(0.1) # checking if the experiment is still running
121122

122-
def process_acquired_data(self) -> Union[np.ndarray, Any]:
123+
def process_acquired_data(self) -> np.ndarray:
123124
"""
124125
Processes the most recently acquired data and returns it as a numpy array.
125126
"""
126127
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)
128129

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)
132133
else:
133-
return self._process_multiple_frames(curr_image)
134+
return self._process_multiple_frames(image_dataset)
134135
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")
136137

137-
def _process_single_frame(self, curr_image: Any) -> np.ndarray:
138+
def _process_single_frame(self, image_dataset: Any) -> np.ndarray:
138139
"""
139140
**Single Frame**:
140141
- Data is returned as a 2D array representing raw counts from each pixel.
141142
- A vertical section (spanning 400 pixels) represents a range for wavelength averaging.
142143
"""
143-
frame = curr_image.GetFrame(0, 0)
144+
frame = image_dataset.GetFrame(0, 0)
144145
return np.reshape(np.fromiter(frame.GetData(), dtype='uint16'), [frame.Width, frame.Height], order='F')
145146

146-
def _process_multiple_frames(self, curr_image: Any) -> np.ndarray:
147+
def _process_multiple_frames(self, image_dataset: Any) -> np.ndarray:
147148
"""
148149
**Multiple Frames**:
149150
- Data from successive exposures is added as a new dimension, then returns a 3D array.
150151
- Averaging across frames can be done by summing over this additional dimension.
151152
"""
152153
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)
155156
new_frame = np.reshape(np.fromiter(frame.GetData(), dtype='uint16'), [frame.Width, frame.Height], order='F')
156157
data = np.dstack((data, new_frame)) if data.size else new_frame
157158
return data
158159

159160
#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:
161162
"""
162163
Acquires image data from the spectrometer.
163164
"""
@@ -240,14 +241,14 @@ def grating(self) -> str:
240241
return self.light.get(lf.AddIns.SpectrometerSettings.GratingSelected)
241242

242243
@grating.setter
243-
def grating(self, grating_string: str) -> None:
244+
def grating(self, value: str) -> None:
244245
"""
245246
Sets the current grating to be the one specified by parameter grating.
246247
"""
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)
249250
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}")
251252

252253
@property
253254
def grating_options(self) -> List[str]:
@@ -311,7 +312,7 @@ def acquire_frame(self) -> Tuple[np.ndarray, np.ndarray]:
311312
"""
312313
return self.light.acquire(), self.get_wavelengths()
313314

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]:
315316
"""
316317
Acquires a step and glue (wavelength sweep) over the specified range.
317318
Wavelength range must have two elements (both in nm), corresponding

0 commit comments

Comments
 (0)