BioImager  4.9.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
microscope.simulators.SimulatedCamera Class Reference
Inheritance diagram for microscope.simulators.SimulatedCamera:
microscope._utils.OnlyTriggersOnceOnSoftwareMixin microscope.abc.Camera microscope.abc.TriggerTargetMixin microscope.abc.TriggerTargetMixin microscope.abc.DataDevice microscope.abc.Device microscope.simulators.stage_aware_camera.StageAwareCamera microscope.testsuite.devices.TestCamera

Public Member Functions

 __init__ (self, **kwargs)
 
 abort (self)
 
 set_exposure_time (self, value)
 
 get_exposure_time (self)
 
 get_cycle_time (self)
 
 soft_trigger (self)
 
- Public Member Functions inherited from microscope._utils.OnlyTriggersOnceOnSoftwareMixin
microscope.TriggerType trigger_type (self)
 
microscope.TriggerMode trigger_mode (self)
 
None set_trigger (self, microscope.TriggerType ttype, microscope.TriggerMode tmode)
 
- Public Member Functions inherited from microscope.abc.TriggerTargetMixin
None trigger (self)
 
- Public Member Functions inherited from microscope.abc.Camera
 set_readout_mode (self, description)
 
 get_transform (self)
 
 set_transform (self, transform)
 
typing.Tuple[int, int] get_sensor_shape (self)
 
microscope.Binning get_binning (self)
 
None set_binning (self, microscope.Binning binning)
 
microscope.ROI get_roi (self)
 
None set_roi (self, microscope.ROI roi)
 
- Public Member Functions inherited from microscope.abc.DataDevice
 __del__ (self)
 
None enable (self)
 
None disable (self)
 
None set_client (self, new_client)
 
None update_settings (self, settings, bool init=False)
 
None receiveClient (self, str client_uri)
 
 grab_next_data (self, bool soft_trigger=True)
 
None receiveData (self, data, timestamp)
 
- Public Member Functions inherited from microscope.abc.Device
bool get_is_enabled (self)
 
None initialize (self)
 
None shutdown (self)
 
None add_setting (self, name, dtype, get_func, set_func, values, typing.Optional[typing.Callable[[], bool]] readonly=None)
 
 get_setting (self, str name)
 
 get_all_settings (self)
 
None set_setting (self, str name, value)
 
 describe_setting (self, str name)
 
 describe_settings (self)
 

Public Attributes

int _acquiring = 1
 
- Public Attributes inherited from microscope.abc.Camera
 set_readout_mode
 
 get_roi
 
 set_roi
 
- Public Attributes inherited from microscope.abc.DataDevice
bool enabled = False
 
bool _fetch_thread = True
 
bool _dispatch_thread = True
 
None _fetch_thread_run = self._fetch_data()
 
- Public Attributes inherited from microscope.abc.Device
bool enabled = False
 

Protected Member Functions

 _set_error_percent (self, value)
 
 _set_gain (self, value)
 
 _purge_buffers (self)
 
 _create_buffers (self)
 
 _fetch_data (self)
 
 _do_disable (self)
 
 _do_enable (self)
 
 _get_sensor_shape (self)
 
None _do_trigger (self)
 
 _get_binning (self)
 
 _set_binning (self, binning)
 
 _get_roi (self)
 
 _set_roi (self, roi)
 
None _do_shutdown (self)
 
- Protected Member Functions inherited from microscope.abc.TriggerTargetMixin
- Protected Member Functions inherited from microscope.abc.Camera
 _process_data (self, data)
 
 _set_readout_transform (self, new_transform)
 
- Protected Member Functions inherited from microscope.abc.DataDevice
 _send_data (self, client, data, timestamp)
 
None _dispatch_loop (self)
 
None _fetch_loop (self)
 
 _client (self)
 
 _client (self, val)
 
None _put (self, data, timestamp)
 
- Protected Member Functions inherited from microscope.abc.Device

Protected Attributes

 _roi = microscope.ROI(0, 0, 512, 512)
 
 _binning = microscope.Binning(1, 1)
 
 _image_generator = _ImageGenerator()
 
int _a_setting = 0
 
int _error_percent = 0
 
 _set_error_percent
 
int _gain = 0
 
 _set_gain
 
bool _acquiring = False
 
float _exposure_time = 0.1
 
int _triggered = 0
 
int _sent = 0
 
- Protected Attributes inherited from microscope.abc.Camera
list _readout_modes = ["default"]
 
int _readout_mode = 0
 
tuple _readout_transform = (False, False, False)
 
tuple _client_transform = (False, False, False)
 
tuple _transform = (False, False, False)
 
- Protected Attributes inherited from microscope.abc.DataDevice
 _fetch_thread = None
 
bool _fetch_thread_run = False
 
bool _using_callback = False
 
list _clientStack = []
 
 _liveClients = set()
 
 _dispatch_thread = None
 
 _dispatch_buffer = queue.Queue(maxsize=buffer_length)
 
bool _acquiring = False
 
 _new_data_condition = threading.Condition()
 
 _client = None
 
tuple _new_data = (data, timestamp)
 
- Protected Attributes inherited from microscope.abc.Device
dict _settings = {}
 

Additional Inherited Members

- Static Public Attributes inherited from microscope.abc.Camera
list ALLOWED_TRANSFORMS = [p for p in itertools.product(*3 * [[False, True]])]
 
- Static Public Attributes inherited from microscope.abc.DataDevice
 set_setting = keep_acquiring(Device.set_setting)
 

Detailed Description

Definition at line 154 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

microscope.simulators.SimulatedCamera.__init__ ( self,
** buffer_length )
Derived.__init__ must call this at some point.

Reimplemented from microscope.abc.Camera.

Reimplemented in microscope.simulators.stage_aware_camera.StageAwareCamera, and microscope.testsuite.devices.TestCamera.

Definition at line 157 of file __init__.py.

157 def __init__(self, **kwargs):
158 super().__init__(**kwargs)
159 # Binning and ROI
160 self._roi = microscope.ROI(0, 0, 512, 512)
161 self._binning = microscope.Binning(1, 1)
162 # Function used to generate test image
163 self._image_generator = _ImageGenerator()
164 self.add_setting(
165 "image pattern",
166 "enum",
167 self._image_generator.method,
168 self._image_generator.set_method,
169 self._image_generator.get_methods,
170 )
171 self.add_setting(
172 "image data type",
173 "enum",
174 self._image_generator.data_type,
175 self._image_generator.set_data_type,
176 self._image_generator.get_data_types,
177 )
178 self.add_setting(
179 "display image number",
180 "bool",
181 lambda: self._image_generator.numbering,
182 self._image_generator.enable_numbering,
183 None,
184 )
185 # Software buffers and parameters for data conversion.
186 self._a_setting = 0
187 self.add_setting(
188 "a_setting",
189 "int",
190 lambda: self._a_setting,
191 lambda val: setattr(self, "_a_setting", val),
192 lambda: (1, 100),
193 )
194 self._error_percent = 0
195 self.add_setting(
196 "_error_percent",
197 "int",
198 lambda: self._error_percent,
199 self._set_error_percent,
200 lambda: (0, 100),
201 )
202 self._gain = 0
203 self.add_setting(
204 "gain",
205 "int",
206 lambda: self._gain,
207 self._set_gain,
208 lambda: (0, 8192),
209 )
210 self._acquiring = False
211 self._exposure_time = 0.1
212 self._triggered = 0
213 # Count number of images sent since last enable.
214 self._sent = 0
215

Member Function Documentation

◆ _create_buffers()

microscope.simulators.SimulatedCamera._create_buffers ( self)
protected
Create buffers and store values needed to remove padding later.

Definition at line 227 of file __init__.py.

227 def _create_buffers(self):
228 """Create buffers and store values needed to remove padding later."""
229 self._purge_buffers()
230 _logger.info("Creating buffers.")
231

◆ _do_disable()

microscope.simulators.SimulatedCamera._do_disable ( self)
protected
Do any device-specific work on disable.

Subclasses should override this method rather than modify
`disable`.

Reimplemented from microscope.abc.Device.

Definition at line 258 of file __init__.py.

258 def _do_disable(self):
259 self.abort()
260

◆ _do_enable()

microscope.simulators.SimulatedCamera._do_enable ( self)
protected
Do any device specific work on enable.

Subclasses should override this method, rather than modify
`enable`.

Reimplemented from microscope.abc.Device.

Definition at line 261 of file __init__.py.

261 def _do_enable(self):
262 _logger.info("Preparing for acquisition.")
263 if self._acquiring:
264 self.abort()
265 self._create_buffers()
266 self._acquiring = True
267 self._sent = 0
268 _logger.info("Acquisition enabled.")
269 return True
270

◆ _do_shutdown()

None microscope.simulators.SimulatedCamera._do_shutdown ( self)
protected
Private method - actual shutdown of the device.

Users should be calling :meth:`shutdown` and not this method.
Concrete implementations should implement this method instead
of `shutdown`.

Reimplemented from microscope.abc.Device.

Definition at line 308 of file __init__.py.

308 def _do_shutdown(self) -> None:
309 pass
310
311

◆ _do_trigger()

None microscope.simulators.SimulatedCamera._do_trigger ( self)
protected
Actual trigger of the device.

Classes implementing this interface should implement this
method instead of `trigger`.

Reimplemented from microscope.abc.TriggerTargetMixin.

Definition at line 287 of file __init__.py.

287 def _do_trigger(self) -> None:
288 _logger.info(
289 "Trigger received; self._acquiring is %s.", self._acquiring
290 )
291 if self._acquiring:
292 self._triggered += 1
293

◆ _fetch_data()

microscope.simulators.SimulatedCamera._fetch_data ( self)
protected
Poll for data and return it, with minimal processing.

If the device uses buffering in software, this function should
copy the data from the buffer, release or recycle the buffer,
then return a reference to the copy.  Otherwise, if the SDK
returns a data object that will not be written to again, this
function can just return a reference to the object.  If no
data is available, return `None`.

Reimplemented from microscope.abc.DataDevice.

Reimplemented in microscope.simulators.stage_aware_camera.StageAwareCamera.

Definition at line 232 of file __init__.py.

232 def _fetch_data(self):
233 if self._acquiring and self._triggered > 0:
234 if random.randint(0, 100) < self._error_percent:
235 _logger.info("Raising exception")
237 "Exception raised in SimulatedCamera._fetch_data"
238 )
239 _logger.info("Sending image")
240 time.sleep(self._exposure_time)
241 self._triggered -= 1
242 # Create an image
243 dark = int(32 * np.random.rand())
244 light = int(255 - 128 * np.random.rand())
245 width = self._roi.width // self._binning.h
246 height = self._roi.height // self._binning.v
247 image = self._image_generator.get_image(
248 width, height, dark, light, index=self._sent
249 )
250 self._sent += 1
251 return image
252

◆ _get_binning()

microscope.simulators.SimulatedCamera._get_binning ( self)
protected
Return the current binning.

Reimplemented from microscope.abc.Camera.

Definition at line 294 of file __init__.py.

294 def _get_binning(self):
295 return self._binning
296

◆ _get_roi()

microscope.simulators.SimulatedCamera._get_roi ( self)
protected
Return the ROI as it is on hardware.

Reimplemented from microscope.abc.Camera.

Definition at line 301 of file __init__.py.

301 def _get_roi(self):
302 return self._roi
303

◆ _get_sensor_shape()

microscope.simulators.SimulatedCamera._get_sensor_shape ( self)
protected
Return a tuple of `(width, height)` indicating shape in pixels.

Reimplemented from microscope.abc.Camera.

Definition at line 280 of file __init__.py.

280 def _get_sensor_shape(self):
281 return (512, 512)
282

◆ _purge_buffers()

microscope.simulators.SimulatedCamera._purge_buffers ( self)
protected
Purge buffers on both camera and PC.

Definition at line 223 of file __init__.py.

223 def _purge_buffers(self):
224 """Purge buffers on both camera and PC."""
225 _logger.info("Purging buffers.")
226

◆ _set_binning()

microscope.simulators.SimulatedCamera._set_binning ( self,
binning )
protected
Set binning along both axes.  Return `True` if successful.

Reimplemented from microscope.abc.Camera.

Definition at line 298 of file __init__.py.

298 def _set_binning(self, binning):
299 self._binning = binning
300

◆ _set_error_percent()

microscope.simulators.SimulatedCamera._set_error_percent ( self,
value )
protected

Definition at line 216 of file __init__.py.

216 def _set_error_percent(self, value):
217 self._error_percent = value
218 self._a_setting = value // 10
219

◆ _set_gain()

microscope.simulators.SimulatedCamera._set_gain ( self,
value )
protected

Definition at line 220 of file __init__.py.

220 def _set_gain(self, value):
221 self._gain = value
222

◆ _set_roi()

microscope.simulators.SimulatedCamera._set_roi ( self,
roi )
protected
Set the ROI on the hardware.  Return `True` if successful.

Reimplemented from microscope.abc.Camera.

Definition at line 305 of file __init__.py.

305 def _set_roi(self, roi):
306 self._roi = roi
307

◆ abort()

microscope.simulators.SimulatedCamera.abort ( self)
Stop acquisition as soon as possible.

Reimplemented from microscope.abc.DataDevice.

Definition at line 253 of file __init__.py.

253 def abort(self):
254 _logger.info("Disabling acquisition; %d images sent.", self._sent)
255 if self._acquiring:
256 self._acquiring = False
257

◆ get_cycle_time()

microscope.simulators.SimulatedCamera.get_cycle_time ( self)
Return the cycle time in seconds.

Reimplemented from microscope.abc.Camera.

Definition at line 277 of file __init__.py.

277 def get_cycle_time(self):
278 return self._exposure_time
279

◆ get_exposure_time()

microscope.simulators.SimulatedCamera.get_exposure_time ( self)
Return the current exposure time in seconds.

Reimplemented from microscope.abc.Camera.

Definition at line 274 of file __init__.py.

274 def get_exposure_time(self):
275 return self._exposure_time
276

◆ set_exposure_time()

microscope.simulators.SimulatedCamera.set_exposure_time ( self,
value )
Set the exposure time on the device in seconds.

Reimplemented from microscope.abc.Camera.

Definition at line 271 of file __init__.py.

271 def set_exposure_time(self, value):
272 self._exposure_time = value
273

◆ soft_trigger()

microscope.simulators.SimulatedCamera.soft_trigger ( self)

Definition at line 283 of file __init__.py.

283 def soft_trigger(self):
284 # deprecated, use self.trigger()
285 self.trigger()
286

Member Data Documentation

◆ _a_setting

int microscope.simulators.SimulatedCamera._a_setting = 0
protected

Definition at line 186 of file __init__.py.

◆ _acquiring [1/2]

bool microscope.simulators.SimulatedCamera._acquiring = False
protected

Definition at line 210 of file __init__.py.

◆ _acquiring [2/2]

int microscope.simulators.SimulatedCamera._acquiring = 1

Definition at line 291 of file __init__.py.

◆ _binning

microscope.simulators.SimulatedCamera._binning = microscope.Binning(1, 1)
protected

Definition at line 161 of file __init__.py.

◆ _error_percent

microscope.simulators.SimulatedCamera._error_percent = 0
protected

Definition at line 194 of file __init__.py.

◆ _exposure_time

microscope.simulators.SimulatedCamera._exposure_time = 0.1
protected

Definition at line 211 of file __init__.py.

◆ _gain

microscope.simulators.SimulatedCamera._gain = 0
protected

Definition at line 202 of file __init__.py.

◆ _image_generator

microscope.simulators.SimulatedCamera._image_generator = _ImageGenerator()
protected

Definition at line 163 of file __init__.py.

◆ _roi

microscope.simulators.SimulatedCamera._roi = microscope.ROI(0, 0, 512, 512)
protected

Definition at line 160 of file __init__.py.

◆ _sent

int microscope.simulators.SimulatedCamera._sent = 0
protected

Definition at line 214 of file __init__.py.

◆ _set_error_percent

microscope.simulators.SimulatedCamera._set_error_percent
protected

Definition at line 199 of file __init__.py.

◆ _set_gain

microscope.simulators.SimulatedCamera._set_gain
protected

Definition at line 207 of file __init__.py.

◆ _triggered

int microscope.simulators.SimulatedCamera._triggered = 0
protected

Definition at line 212 of file __init__.py.


The documentation for this class was generated from the following file: