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.DataDevice Class Reference
Inheritance diagram for microscope.abc.DataDevice:
microscope.abc.Device microscope.abc.Camera microscope.cameras.andorsdk3.AndorSDK3 microscope.cameras.atmcd.AndorAtmcd microscope.cameras.picam.PiCamera microscope.cameras.pvcam.PVCamera microscope.cameras.ximea.XimeaCamera microscope.simulators.SimulatedCamera microscope.simulators.stage_aware_camera.StageAwareCamera microscope.testsuite.devices.TestCamera

Public Member Functions

None __init__ (self, int buffer_length=0, **kwargs)
 
def __del__ (self)
 
None abort (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)
 
def grab_next_data (self, bool soft_trigger=True)
 
None receiveData (self, data, timestamp)
 
- Public Member Functions inherited from microscope.abc.Device
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
 
- Public Attributes inherited from microscope.abc.Device
 enabled
 

Static Public Attributes

 set_setting = keep_acquiring(Device.set_setting)
 

Detailed Description

A data capture device.

This class handles a thread to fetch data from a device and dispatch
it to a client.  The client is set using set_client(uri) or (legacy)
receiveClient(uri).

Derived classed should implement::

* :meth:`abort` (required)
* :meth:`_fetch_data` (required)
* :meth:`_process_data` (optional)

Derived classes may override `__init__`, `enable` and `disable`,
but must ensure to call this class's implementations as indicated
in the docstrings.

Definition at line 539 of file abc.py.

Constructor & Destructor Documentation

◆ __init__()

None microscope.abc.DataDevice.__init__ (   self,
int   buffer_length = 0,
**  kwargs 
)
Derived.__init__ must call this at some point.

Reimplemented from microscope.abc.Device.

Reimplemented in microscope.abc.Camera, microscope.simulators.SimulatedCamera, microscope.testsuite.devices.TestCamera, microscope.cameras.picam.PiCamera, microscope.simulators.stage_aware_camera.StageAwareCamera, and microscope.cameras.ximea.XimeaCamera.

Definition at line 558 of file abc.py.

558 def __init__(self, buffer_length: int = 0, **kwargs) -> None:
559 """Derived.__init__ must call this at some point."""
560 super().__init__(**kwargs)
561 # A thread to fetch and dispatch data.
562 self._fetch_thread = None
563 # A flag to control the _fetch_thread.
564 self._fetch_thread_run = False
565 # A flag to indicate that this class uses a fetch callback.
566 self._using_callback = False
567 # Clients to which we send data.
568 self._clientStack = []
569 # A set of live clients to avoid repeated dispatch to disconnected client.
570 self._liveClients = set()
571 # A thread to dispatch data.
572 self._dispatch_thread = None
573 # A buffer for data dispatch.
574 self._dispatch_buffer = queue.Queue(maxsize=buffer_length)
575 # A flag to indicate if device is ready to acquire.
576 self._acquiring = False
577 # A condition to signal arrival of a new data and unblock grab_next_data
578 self._new_data_condition = threading.Condition()
579

References microscope.abc.DataDevice.__init__(), 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.DataDevice._clientStack, microscope.abc.DataDevice._dispatch_buffer, microscope.abc.DataDevice._dispatch_thread, microscope.abc.DataDevice._fetch_thread, microscope.abc.DataDevice._fetch_thread_run, microscope.abc.DataDevice._liveClients, microscope.abc.DataDevice._new_data_condition, microscope.abc.DataDevice._using_callback, microscope.cameras.andorsdk3.AndorSDK3._using_callback, microscope.cameras.pvcam.PVCamera._using_callback, 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().

Referenced by microscope.abc.DataDevice.__init__().

◆ __del__()

def microscope.abc.DataDevice.__del__ (   self)

Reimplemented from microscope.abc.Device.

Definition at line 580 of file abc.py.

580 def __del__(self):
581 self.disable()
582 super().__del__()
583

Member Function Documentation

◆ abort()

◆ disable()

None microscope.abc.DataDevice.disable (   self)
Disable the data capture device.

Implement device-specific code in `_do_disable`.

Reimplemented from microscope.abc.Device.

Definition at line 629 of file abc.py.

629 def disable(self) -> None:
630 """Disable the data capture device.
631
632 Implement device-specific code in `_do_disable`.
633
634 """
635 self.enabled = False
636 if self._fetch_thread:
637 if self._fetch_thread.is_alive():
638 self._fetch_thread_run = False
639 self._fetch_thread.join()
640 super().disable()
641

References microscope.abc.DataDevice._client, microscope.testsuite.devices.DummyDSP._client, microscope.abc.DataDevice._clientStack, microscope.abc.DataDevice._dispatch_buffer, microscope.abc.DataDevice._fetch_data(), microscope.cameras.atmcd.AndorAtmcd._fetch_data(), microscope.cameras.picam.PiCamera._fetch_data(), microscope.cameras.pvcam.PVCamera._fetch_data(), microscope.cameras.ximea.XimeaCamera._fetch_data(), microscope.simulators.SimulatedCamera._fetch_data(), microscope.simulators.stage_aware_camera.StageAwareCamera._fetch_data(), microscope.cameras.andorsdk3.AndorSDK3._fetch_data(), microscope.abc.DataDevice._fetch_thread, microscope.abc.DataDevice._fetch_thread_run, microscope.abc.DataDevice._liveClients, microscope.abc.DataDevice._process_data(), microscope.abc.Camera._process_data(), microscope.abc.DataDevice._put(), microscope.abc.DataDevice._send_data(), microscope.abc.DataDevice.disable(), microscope.abc.Device.enabled, microscope.abc.DataDevice.enabled, and microscope.testsuite.devices.DummySLM.enabled.

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

◆ enable()

None microscope.abc.DataDevice.enable (   self)
Enable the data capture device.

Ensures that a data handling threads are running.  Implement
device specific code in `_do_enable`.

Reimplemented from microscope.abc.Device.

Definition at line 592 of file abc.py.

592 def enable(self) -> None:
593 """Enable the data capture device.
594
595 Ensures that a data handling threads are running. Implement
596 device specific code in `_do_enable`.
597
598 """
599 _logger.debug("Enabling ...")
600 # Call device-specific code.
601 try:
602 result = self._do_enable()
603 except Exception as err:
604 _logger.debug("Error in _do_enable:", exc_info=err)
605 self.enabled = False
606 raise err
607 if not result:
608 self.enabled = False
609 else:
610 self.enabled = True
611 # Set up data fetching
612 if self._using_callback:
613 if self._fetch_thread:
614 self._fetch_thread_run = False
615 else:
616 if not self._fetch_thread or not self._fetch_thread.is_alive():
617 self._fetch_thread = Thread(target=self._fetch_loop)
618 self._fetch_thread.daemon = True
619 self._fetch_thread.start()
620 if (
621 not self._dispatch_thread
622 or not self._dispatch_thread.is_alive()
623 ):
624 self._dispatch_thread = Thread(target=self._dispatch_loop)
625 self._dispatch_thread.daemon = True
626 self._dispatch_thread.start()
627 _logger.debug("... enabled.")
628

References microscope.abc.DataDevice._dispatch_loop(), microscope.abc.DataDevice._dispatch_thread, 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.abc.DataDevice._fetch_loop(), microscope.abc.DataDevice._fetch_thread, microscope.abc.DataDevice._fetch_thread_run, microscope.abc.DataDevice._using_callback, microscope.cameras.andorsdk3.AndorSDK3._using_callback, microscope.cameras.pvcam.PVCamera._using_callback, microscope.abc.Device.enabled, microscope.abc.DataDevice.enabled, and microscope.testsuite.devices.DummySLM.enabled.

◆ grab_next_data()

def microscope.abc.DataDevice.grab_next_data (   self,
bool   soft_trigger = True 
)
Returns results from next trigger via a direct call.

Args:
    soft_trigger: calls :meth:`trigger` if `True`, waits for
        hardware trigger if `False`.

Definition at line 789 of file abc.py.

789 def grab_next_data(self, soft_trigger: bool = True):
790 """Returns results from next trigger via a direct call.
791
792 Args:
793 soft_trigger: calls :meth:`trigger` if `True`, waits for
794 hardware trigger if `False`.
795
796 """
797 if not self.enabled:
798 raise microscope.DisabledDeviceError("Camera not enabled.")
799 self._new_data_condition.acquire()
800 # Push self onto client stack.
801 self.set_client(self)
802 # Wait for data from next trigger.
803 if soft_trigger:
804 self.trigger()
805 self._new_data_condition.wait()
806 # Pop self from client stack
807 self.set_client(None)
808 # Return the data.
809 return self._new_data
810

References microscope.abc.DataDevice._new_data, microscope.abc.DataDevice._new_data_condition, microscope.abc.Device.enabled, microscope.abc.DataDevice.enabled, microscope.testsuite.devices.DummySLM.enabled, microscope.testsuite.devices.DummyDSP.set_client(), microscope.abc.DataDevice.set_client(), microscope.abc.TriggerTargetMixin.trigger(), and microscope.abc.DeformableMirror.trigger().

◆ receiveClient()

None microscope.abc.DataDevice.receiveClient (   self,
str  client_uri 
)
A passthrough for compatibility.

Definition at line 785 of file abc.py.

785 def receiveClient(self, client_uri: str) -> None:
786 """A passthrough for compatibility."""
787 self.set_client(client_uri)
788

References microscope.testsuite.devices.DummyDSP.set_client(), and microscope.abc.DataDevice.set_client().

◆ receiveData()

None microscope.abc.DataDevice.receiveData (   self,
  data,
  timestamp 
)
Unblocks grab_next_frame so it can return.

Definition at line 812 of file abc.py.

812 def receiveData(self, data, timestamp) -> None:
813 """Unblocks grab_next_frame so it can return."""
814 with self._new_data_condition:
815 self._new_data = (data, timestamp)
816 self._new_data_condition.notify()
817
818

References microscope.abc.DataDevice._new_data, and microscope.abc.DataDevice._new_data_condition.

◆ set_client()

None microscope.abc.DataDevice.set_client (   self,
  new_client 
)
Set up a connection to our client.

Clients now sit in a stack so that a single device may send
different data to multiple clients in a single experiment.
The usage is currently::

    device.set_client(client) # Add client to top of stack
    # do stuff, send triggers, receive data
    device.set_client(None)   # Pop top client off stack.

There is a risk that some other client calls ``None`` before
the current client is finished.  Avoiding this will require
rework here to identify the caller and remove only that caller
from the client stack.

Definition at line 749 of file abc.py.

749 def set_client(self, new_client) -> None:
750 """Set up a connection to our client.
751
752 Clients now sit in a stack so that a single device may send
753 different data to multiple clients in a single experiment.
754 The usage is currently::
755
756 device.set_client(client) # Add client to top of stack
757 # do stuff, send triggers, receive data
758 device.set_client(None) # Pop top client off stack.
759
760 There is a risk that some other client calls ``None`` before
761 the current client is finished. Avoiding this will require
762 rework here to identify the caller and remove only that caller
763 from the client stack.
764
765 """
766 if new_client is not None:
767 if isinstance(new_client, (str, Pyro4.core.URI)):
768 self._client = Pyro4.Proxy(new_client)
769 else:
770 self._client = new_client
771 else:
772 self._client = None
773 # _client uses a setter. Log the result of assignment.
774 if self._client is None:
775 _logger.info("Current client is None.")
776 else:
777 _logger.info("Current client is %s.", str(self._client))
778

References microscope.abc.DataDevice._client, and microscope.testsuite.devices.DummyDSP._client.

Referenced by microscope.clients.DataClient.enable(), microscope.abc.DataDevice.grab_next_data(), and microscope.abc.DataDevice.receiveClient().

◆ update_settings()

None microscope.abc.DataDevice.update_settings (   self,
  settings,
bool   init = False 
)
Update settings, toggling acquisition if necessary.

Reimplemented from microscope.abc.Device.

Definition at line 780 of file abc.py.

780 def update_settings(self, settings, init: bool = False) -> None:
781 """Update settings, toggling acquisition if necessary."""
782 super().update_settings(settings, init)
783

References microscope.abc.DataDevice.update_settings().

Referenced by microscope.abc.DataDevice.update_settings().

Member Data Documentation

◆ enabled

◆ set_setting

microscope.abc.DataDevice.set_setting = keep_acquiring(Device.set_setting)
static

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