BioImager  3.9.1
A .NET microscopy imaging library. Supports various microscopes by using imported libraries & GUI automation. Supported libraries include PriorĀ® & ZeissĀ® & all devices supported by Micromanager 2.0 and python-microscope.
Loading...
Searching...
No Matches
microscope.abc.Device Class Reference
Inheritance diagram for microscope.abc.Device:
microscope.abc.Controller microscope.abc.DataDevice microscope.abc.DeformableMirror microscope.abc.FilterWheel microscope.abc.LightSource microscope.abc.Stage microscope.stages.linkam._LinkamBase microscope.testsuite.devices.DummyDSP microscope.testsuite.devices.DummySLM microscope.testsuite.devices.TestFloatingDevice microscope.testsuite.test_device_server.DeviceWithPort microscope.testsuite.test_device_server.ExposePIDDevice

Public Member Functions

None __init__ (self)
 
None __del__ (self)
 
bool get_is_enabled (self)
 
None disable (self)
 
None enable (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)
 
def get_setting (self, str name)
 
def get_all_settings (self)
 
None set_setting (self, str name, value)
 
def describe_setting (self, str name)
 
def describe_settings (self)
 
def update_settings (self, incoming, bool init=False)
 

Public Attributes

 enabled
 

Detailed Description

A base device class. All devices should subclass this class.

Definition at line 285 of file abc.py.

Constructor & Destructor Documentation

◆ __init__()

◆ __del__()

None microscope.abc.Device.__del__ (   self)

Reimplemented in microscope.stages.linkam._LinkamBase.

Definition at line 292 of file abc.py.

292 def __del__(self) -> None:
293 self.shutdown()
294

Member Function Documentation

◆ add_setting()

None microscope.abc.Device.add_setting (   self,
  name,
  dtype,
  get_func,
  set_func,
  values,
typing.Optional[typing.Callable[[], bool]]   readonly = None 
)
Add a setting definition.

Args:
    name: the setting's name.
    dtype: a data type from `"int"`, `"float"`, `"bool"`,
        `"enum"`, or `"str"` (see `DTYPES`).
    get_func: a function to get the current value.
    set_func: a function to set the value.
    values: a description of allowed values dependent on
        dtype, or function that returns a description.
    readonly: an optional function to indicate if the setting
        is readonly.  A setting may be readonly temporarily,
        so this function will return `True` or `False` to
        indicate its current state.  If set to no `None`
        (default), then its value will be dependent on the
        value of `set_func`.

A client needs some way of knowing a setting name and data
type, retrieving the current value and, if settable, a way to
retrieve allowable values, and set the value.  We store this
info in a dictionary.  I considered having a `Setting1 class
with getter, setter, etc., and adding `Setting` instances as
device attributes, but Pyro does not support dot notation to
access the functions we need (e.g. `Device.some_setting.set`),
so I'd have to write access functions, anyway.

Definition at line 399 of file abc.py.

407 ) -> None:
408 """Add a setting definition.
409
410 Args:
411 name: the setting's name.
412 dtype: a data type from `"int"`, `"float"`, `"bool"`,
413 `"enum"`, or `"str"` (see `DTYPES`).
414 get_func: a function to get the current value.
415 set_func: a function to set the value.
416 values: a description of allowed values dependent on
417 dtype, or function that returns a description.
418 readonly: an optional function to indicate if the setting
419 is readonly. A setting may be readonly temporarily,
420 so this function will return `True` or `False` to
421 indicate its current state. If set to no `None`
422 (default), then its value will be dependent on the
423 value of `set_func`.
424
425 A client needs some way of knowing a setting name and data
426 type, retrieving the current value and, if settable, a way to
427 retrieve allowable values, and set the value. We store this
428 info in a dictionary. I considered having a `Setting1 class
429 with getter, setter, etc., and adding `Setting` instances as
430 device attributes, but Pyro does not support dot notation to
431 access the functions we need (e.g. `Device.some_setting.set`),
432 so I'd have to write access functions, anyway.
433
434 """
435 if dtype not in DTYPES:
436 raise ValueError("Unsupported dtype.")
437 elif not (isinstance(values, DTYPES[dtype]) or callable(values)):
438 raise TypeError(
439 "Invalid values type for %s '%s': expected function or %s"
440 % (dtype, name, DTYPES[dtype])
441 )
442 else:
443 self._settings[name] = _Setting(
444 name, dtype, get_func, set_func, values, readonly
445 )
446

References microscope.simulators.stage_aware_camera.StageAwareCamera._settings.

Referenced by microscope.abc.Camera.__init__(), microscope.simulators.SimulatedCamera.__init__(), microscope.testsuite.devices.TestCamera.__init__(), microscope.cameras.picam.PiCamera.__init__(), microscope.simulators.stage_aware_camera.StageAwareCamera.__init__(), microscope.cameras.ximea.XimeaCamera.__init__(), microscope.stages.linkam.LinkamCMS.__init__(), microscope.cameras.andorsdk3.AndorSDK3.initialize(), microscope.cameras.atmcd.AndorAtmcd.initialize(), microscope.cameras.pvcam.PVCamera.initialize(), and microscope.cameras.ximea.XimeaCamera.initialize().

◆ describe_setting()

def microscope.abc.Device.describe_setting (   self,
str  name 
)
Return ordered setting descriptions as a list of dicts.

Definition at line 476 of file abc.py.

476 def describe_setting(self, name: str):
477 """Return ordered setting descriptions as a list of dicts."""
478 return self._settings[name].describe()
479

References microscope.simulators.stage_aware_camera.StageAwareCamera._settings.

◆ describe_settings()

def microscope.abc.Device.describe_settings (   self)
Return ordered setting descriptions as a list of dicts.

Definition at line 480 of file abc.py.

480 def describe_settings(self):
481 """Return ordered setting descriptions as a list of dicts."""
482 return [(k, v.describe()) for (k, v) in self._settings.items()]
483

References microscope.simulators.stage_aware_camera.StageAwareCamera._settings.

◆ disable()

None microscope.abc.Device.disable (   self)
Disable the device for a short period for inactivity.

Reimplemented in microscope.abc.DataDevice, microscope.controllers.coolled._CoolLEDChannel, microscope.controllers.lumencor._SpectraIIILightChannel, microscope.lights.cobolt.CoboltLaser, microscope.lights.sapphire.SapphireLaser, and microscope.lights.toptica.TopticaiBeam.

Definition at line 307 of file abc.py.

307 def disable(self) -> None:
308 """Disable the device for a short period for inactivity."""
309 self._do_disable()
310 self.enabled = False
311

References microscope.abc.Device._do_disable(), microscope.cameras.andorsdk3.AndorSDK3._do_disable(), microscope.cameras.atmcd.AndorAtmcd._do_disable(), microscope.cameras.picam.PiCamera._do_disable(), microscope.cameras.pvcam.PVCamera._do_disable(), microscope.cameras.ximea.XimeaCamera._do_disable(), microscope.controllers.toptica._iChromeLaser._do_disable(), microscope.controllers.zaber._ZaberLED._do_disable(), microscope.filterwheels.aurox.Clarity._do_disable(), microscope.lights.deepstar.DeepstarLaser._do_disable(), microscope.lights.obis.ObisLaser._do_disable(), microscope.simulators.SimulatedCamera._do_disable(), microscope.simulators.SimulatedLightSource._do_disable(), microscope.abc.Device.enabled, microscope.abc.DataDevice.enabled, and microscope.testsuite.devices.DummySLM.enabled.

Referenced by microscope.abc.DataDevice.__init__(), microscope.lights.cobolt.CoboltLaser.get_status(), microscope.lights.deepstar.DeepstarLaser.get_status(), microscope.lights.obis.ObisLaser.get_status(), and microscope.abc.Device.shutdown().

◆ enable()

◆ get_all_settings()

def microscope.abc.Device.get_all_settings (   self)
Return ordered settings as a list of dicts.

Definition at line 455 of file abc.py.

455 def get_all_settings(self):
456 """Return ordered settings as a list of dicts."""
457 # Fetching some settings may fail depending on device state.
458 # Report these values as 'None' and continue fetching other settings.
459 def catch(f):
460 try:
461 return f()
462 except Exception as err:
463 _logger.error("getting %s: %s", f.__self__.name, err)
464 return None
465
466 return {k: catch(v.get) for k, v in self._settings.items()}
467

References microscope.simulators.stage_aware_camera.StageAwareCamera._settings.

◆ get_is_enabled()

bool microscope.abc.Device.get_is_enabled (   self)

Definition at line 295 of file abc.py.

295 def get_is_enabled(self) -> bool:
296 return self.enabled
297

◆ get_setting()

def microscope.abc.Device.get_setting (   self,
str  name 
)
Return the current value of a setting.

Definition at line 447 of file abc.py.

447 def get_setting(self, name: str):
448 """Return the current value of a setting."""
449 try:
450 return self._settings[name].get()
451 except Exception as err:
452 _logger.error("in get_setting(%s):", name, exc_info=err)
453 raise
454

References microscope.simulators.stage_aware_camera.StageAwareCamera._settings.

Referenced by microscope.cameras.atmcd.AndorAtmcd.get_id(), microscope.cameras.atmcd.AndorAtmcd.soft_trigger(), and microscope.abc.Device.update_settings().

◆ initialize()

None microscope.abc.Device.initialize (   self)
Initialize the device.

If devices have this method (not required, and many don't),
then they should call it as part of the initialisation, i.e.,
they should call it on their `__init__` method.

Reimplemented in microscope.cameras.andorsdk3.AndorSDK3, microscope.cameras.atmcd.AndorAtmcd, microscope.cameras.picam.PiCamera, microscope.cameras.pvcam.PVCamera, microscope.cameras.ximea.XimeaCamera, microscope.lights.cobolt.CoboltLaser, microscope.lights.obis.ObisLaser, microscope.lights.sapphire.SapphireLaser, and microscope.testsuite.devices.TestFloatingDevice.

Definition at line 339 of file abc.py.

339 def initialize(self) -> None:
340 """Initialize the device.
341
342 If devices have this method (not required, and many don't),
343 then they should call it as part of the initialisation, i.e.,
344 they should call it on their `__init__` method.
345
346 """
347 pass
348

Referenced by microscope.cameras.picam.PiCamera.__init__(), microscope.cameras.ximea.XimeaCamera.__init__(), and microscope.cameras.picam.PiCamera.initialize().

◆ set_setting()

None microscope.abc.Device.set_setting (   self,
str  name,
  value 
)
Set a setting.

Definition at line 468 of file abc.py.

468 def set_setting(self, name: str, value) -> None:
469 """Set a setting."""
470 try:
471 self._settings[name].set(value)
472 except Exception as err:
473 _logger.error("in set_setting(%s):", name, exc_info=err)
474 raise
475

References microscope.simulators.stage_aware_camera.StageAwareCamera._settings.

Referenced by microscope.cameras.atmcd.AndorAtmcd.initialize(), and microscope.cameras.atmcd.AndorAtmcd.set_trigger().

◆ shutdown()

None microscope.abc.Device.shutdown (   self)
Shutdown the device.

Disable and disconnect the device.  This method should be
called before destructing the device object, to ensure that
the device is actually shutdown.

After `shutdown`, the device object is no longer usable and
calling any other method is undefined behaviour.  The only
exception `shutdown` itself which can be called consecutively,
and after the first time will have no effect.

A device object that has been shutdown can't be reinitialised.
Instead of reusing the object, a new one should be created
instead.  This means that `shutdown` will leave the device in
a state that it can be reconnected.

.. code-block:: python

    device = SomeDevice()
    device.shutdown()

    # Multiple calls to shutdown are OK
    device.shutdown()
    device.shutdown()

    # After shutdown, everything else is undefined behaviour.
    device.enable()  # undefined behaviour
    device.get_setting("speed")  # undefined behaviour

    # To reinitialise the device, construct a new instance.
    device = SomeDevice()


.. note::

    While `__del__` calls `shutdown`, one should not rely on
    it.  Python does not guarante that `__del__` will be
    called when the interpreter exits so if `shutdown` is not
    called explicitely, the devices might not be shutdown.

Definition at line 349 of file abc.py.

349 def shutdown(self) -> None:
350 """Shutdown the device.
351
352 Disable and disconnect the device. This method should be
353 called before destructing the device object, to ensure that
354 the device is actually shutdown.
355
356 After `shutdown`, the device object is no longer usable and
357 calling any other method is undefined behaviour. The only
358 exception `shutdown` itself which can be called consecutively,
359 and after the first time will have no effect.
360
361 A device object that has been shutdown can't be reinitialised.
362 Instead of reusing the object, a new one should be created
363 instead. This means that `shutdown` will leave the device in
364 a state that it can be reconnected.
365
366 .. code-block:: python
367
368 device = SomeDevice()
369 device.shutdown()
370
371 # Multiple calls to shutdown are OK
372 device.shutdown()
373 device.shutdown()
374
375 # After shutdown, everything else is undefined behaviour.
376 device.enable() # undefined behaviour
377 device.get_setting("speed") # undefined behaviour
378
379 # To reinitialise the device, construct a new instance.
380 device = SomeDevice()
381
382
383 .. note::
384
385 While `__del__` calls `shutdown`, one should not rely on
386 it. Python does not guarante that `__del__` will be
387 called when the interpreter exits so if `shutdown` is not
388 called explicitely, the devices might not be shutdown.
389
390 """
391 try:
392 self.disable()
393 except Exception as e:
394 _logger.warning("Exception in disable() during shutdown: %s", e)
395 _logger.info("Shutting down ... ... ...")
396 self._do_shutdown()
397 _logger.info("... ... ... ... shut down completed.")
398

References microscope.abc.Device._do_shutdown(), microscope.abc.Controller._do_shutdown(), microscope.cameras.andorsdk3.AndorSDK3._do_shutdown(), microscope.cameras.atmcd.AndorAtmcd._do_shutdown(), microscope.cameras.picam.PiCamera._do_shutdown(), microscope.cameras.pvcam.PVCamera._do_shutdown(), microscope.cameras.ximea.XimeaCamera._do_shutdown(), microscope.controllers.coolled._CoolLEDChannel._do_shutdown(), microscope.controllers.lumencor._SpectraIIILightChannel._do_shutdown(), microscope.controllers.prior._ProScanIIIFilterWheel._do_shutdown(), microscope.controllers.toptica._iChromeLaser._do_shutdown(), microscope.controllers.zaber._ZaberStage._do_shutdown(), microscope.controllers.zaber._ZaberFilterWheel._do_shutdown(), microscope.controllers.zaber._ZaberLED._do_shutdown(), microscope.filterwheels.aurox.Clarity._do_shutdown(), microscope.filterwheels.thorlabs.ThorlabsFilterWheel._do_shutdown(), microscope.lights.cobolt.CoboltLaser._do_shutdown(), microscope.lights.deepstar.DeepstarLaser._do_shutdown(), microscope.lights.obis.ObisLaser._do_shutdown(), microscope.lights.sapphire.SapphireLaser._do_shutdown(), microscope.lights.toptica.TopticaiBeam._do_shutdown(), microscope.mirror.alpao.AlpaoDeformableMirror._do_shutdown(), microscope.mirror.bmc.BMCDeformableMirror._do_shutdown(), microscope.mirror.mirao52e.Mirao52e._do_shutdown(), microscope.simulators.SimulatedCamera._do_shutdown(), microscope.simulators.SimulatedFilterWheel._do_shutdown(), microscope.simulators.SimulatedLightSource._do_shutdown(), microscope.simulators.SimulatedDeformableMirror._do_shutdown(), microscope.simulators.SimulatedStage._do_shutdown(), microscope.stages.linkam._LinkamBase._do_shutdown(), microscope.stages.ludl._LudlStage._do_shutdown(), microscope.testsuite.devices.DummySLM._do_shutdown(), microscope.testsuite.devices.DummyDSP._do_shutdown(), microscope.testsuite.devices.TestFloatingDevice._do_shutdown(), microscope.testsuite.test_device_server.ExposePIDDevice._do_shutdown(), microscope.testsuite.test_device_server.DeviceWithPort._do_shutdown(), microscope.abc.Device.disable(), microscope.abc.DataDevice.disable(), microscope.controllers.coolled._CoolLEDChannel.disable(), microscope.controllers.lumencor._SpectraIIILightChannel.disable(), microscope.lights.cobolt.CoboltLaser.disable(), microscope.lights.sapphire.SapphireLaser.disable(), and microscope.lights.toptica.TopticaiBeam.disable().

◆ update_settings()

def microscope.abc.Device.update_settings (   self,
  incoming,
bool   init = False 
)
Update settings based on dict of settings and values.

Reimplemented in microscope.abc.DataDevice.

Definition at line 484 of file abc.py.

484 def update_settings(self, incoming, init: bool = False):
485 """Update settings based on dict of settings and values."""
486 if init:
487 # Assume nothing about state: set everything.
488 my_keys = set(self._settings.keys())
489 their_keys = set(incoming.keys())
490 update_keys = my_keys & their_keys
491 if update_keys != my_keys:
492 missing = ", ".join([k for k in my_keys - their_keys])
493 msg = (
494 "update_settings init=True but missing keys: %s." % missing
495 )
496 _logger.debug(msg)
497 raise Exception(msg)
498 else:
499 # Only update changed values.
500 my_keys = set(self._settings.keys())
501 their_keys = set(incoming.keys())
502 update_keys = set(
503 key
504 for key in my_keys & their_keys
505 if self.get_setting(key) != incoming[key]
506 )
507 results = {}
508 # Update values.
509 for key in update_keys:
510 if key not in my_keys or not self._settings[key].set:
511 # Setting not recognised or no set function implemented
512 results[key] = NotImplemented
513 update_keys.remove(key)
514 continue
515 if self._settings[key].readonly():
516 continue
517 self._settings[key].set(incoming[key])
518 # Read back values in second loop.
519 for key in update_keys:
520 results[key] = self._settings[key].get()
521 return results
522
523

References microscope.abc.DataDevice._acquiring, microscope.cameras.andorsdk3.AndorSDK3._acquiring(), microscope.cameras.atmcd.AndorAtmcd._acquiring(), microscope.cameras.picam.PiCamera._acquiring, microscope.cameras.pvcam.PVCamera._acquiring, microscope.cameras.ximea.XimeaCamera._acquiring, microscope.simulators.SimulatedCamera._acquiring, microscope.abc.Device._do_enable(), microscope.cameras.andorsdk3.AndorSDK3._do_enable(), microscope.cameras.atmcd.AndorAtmcd._do_enable(), microscope.cameras.picam.PiCamera._do_enable(), microscope.cameras.pvcam.PVCamera._do_enable(), microscope.cameras.ximea.XimeaCamera._do_enable(), microscope.controllers.toptica._iChromeLaser._do_enable(), microscope.controllers.zaber._ZaberStage._do_enable(), microscope.controllers.zaber._ZaberLED._do_enable(), microscope.filterwheels.aurox.Clarity._do_enable(), microscope.lights.cobolt.CoboltLaser._do_enable(), microscope.lights.deepstar.DeepstarLaser._do_enable(), microscope.lights.obis.ObisLaser._do_enable(), microscope.lights.sapphire.SapphireLaser._do_enable(), microscope.simulators.SimulatedCamera._do_enable(), microscope.simulators.SimulatedLightSource._do_enable(), microscope.stages.ludl._LudlStage._do_enable(), microscope.simulators.stage_aware_camera.StageAwareCamera._settings, microscope.abc.DataDevice.abort(), microscope.cameras.andorsdk3.AndorSDK3.abort(), microscope.cameras.atmcd.AndorAtmcd.abort(), microscope.cameras.picam.PiCamera.abort(), microscope.cameras.pvcam.PVCamera.abort(), microscope.cameras.ximea.XimeaCamera.abort(), microscope.simulators.SimulatedCamera.abort(), and microscope.abc.Device.get_setting().

Member Data Documentation

◆ enabled


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