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.abc.DeformableMirror Class Reference
Inheritance diagram for microscope.abc.DeformableMirror:
microscope.abc.TriggerTargetMixin microscope.abc.Device microscope.mirror.alpao.AlpaoDeformableMirror microscope.mirror.bmc.BMCDeformableMirror microscope.mirror.mirao52e.Mirao52e microscope.simulators.SimulatedDeformableMirror

Public Member Functions

None __init__ (self, **kwargs)
 
int n_actuators (self)
 
None apply_pattern (self, numpy.ndarray pattern)
 
None queue_patterns (self, numpy.ndarray patterns)
 
None next_pattern (self)
 
None trigger (self)
 
- Public Member Functions inherited from microscope.abc.TriggerTargetMixin
microscope.TriggerMode trigger_mode (self)
 
microscope.TriggerType trigger_type (self)
 
None set_trigger (self, microscope.TriggerType ttype, microscope.TriggerMode tmode)
 
- Public Member Functions inherited from microscope.abc.Device
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)
 
 get_setting (self, str name)
 
 get_all_settings (self)
 
None set_setting (self, str name, value)
 
 describe_setting (self, str name)
 
 describe_settings (self)
 
 update_settings (self, incoming, bool init=False)
 

Public Attributes

 n_actuators
 
- Public Attributes inherited from microscope.abc.Device
bool enabled = False
 

Protected Member Functions

None _validate_patterns (self, numpy.ndarray patterns)
 
None _do_apply_pattern (self, numpy.ndarray pattern)
 
None _do_trigger (self)
 
- Protected Member Functions inherited from microscope.abc.TriggerTargetMixin
- Protected Member Functions inherited from microscope.abc.Device
 _do_disable (self)
 
 _do_enable (self)
 
None _do_shutdown (self)
 

Protected Attributes

typing.Optional[numpy.ndarray] _patterns = None
 
int _pattern_idx = -1
 
- Protected Attributes inherited from microscope.abc.Device
dict _settings = {}
 

Detailed Description

Base class for Deformable Mirrors.

There is no method to reset or clear a deformable mirror.  While
different vendors provide functions to do that, it is unclear
exactly what it does the actuators.  Does it set all actuators
back to something based on a calibration file?  Does it apply a
voltage of zero to each?  Does it set the values to zero and what
does that mean since different deformable mirrors expect values in
a different range?  For the sake of uniformity, it is better for
python-microscope users to pass the pattern they want, probably a
pattern that flattens the mirror.

It is also unclear what the use case for a reset.  If it just to
set the mirror to an initial state and not a specific shape, then
destroying and re-constructing the DeformableMirror object
provides the most obvious solution.

The private properties `_patterns` and `_pattern_idx` are
initialized to `None` to support the queueing of patterns and
software triggering.

Definition at line 1051 of file abc.py.

Constructor & Destructor Documentation

◆ __init__()

None microscope.abc.DeformableMirror.__init__ ( self,
** kwargs )

Reimplemented from microscope.abc.Device.

Definition at line 1076 of file abc.py.

1076 def __init__(self, **kwargs) -> None:
1077 super().__init__(**kwargs)
1078 self._patterns: typing.Optional[numpy.ndarray] = None
1079 self._pattern_idx: int = -1
1080

Member Function Documentation

◆ _do_apply_pattern()

None microscope.abc.DeformableMirror._do_apply_pattern ( self,
numpy.ndarray pattern )
protected

Definition at line 1110 of file abc.py.

1110 def _do_apply_pattern(self, pattern: numpy.ndarray) -> None:
1111 raise NotImplementedError()
1112

◆ _do_trigger()

None microscope.abc.DeformableMirror._do_trigger ( self)
protected
Convenience fallback.

This only provides a convenience fallback for devices that
don't support queuing multiple patterns and software trigger,
i.e., devices that take only one pattern at a time.  This is
not the case of most devices.

Devices that support queuing patterns, should override this
method.

.. todo::

    Instead of a convenience fallback, we should have a
    separate mixin for this.

Reimplemented from microscope.abc.TriggerTargetMixin.

Definition at line 1156 of file abc.py.

1156 def _do_trigger(self) -> None:
1157 """Convenience fallback.
1158
1159 This only provides a convenience fallback for devices that
1160 don't support queuing multiple patterns and software trigger,
1161 i.e., devices that take only one pattern at a time. This is
1162 not the case of most devices.
1163
1164 Devices that support queuing patterns, should override this
1165 method.
1166
1167 .. todo::
1168
1169 Instead of a convenience fallback, we should have a
1170 separate mixin for this.
1171
1172 """
1173 if self._patterns is None:
1174 raise microscope.DeviceError("no pattern queued to apply")
1175 self._pattern_idx += 1
1176 self.apply_pattern(self._patterns[self._pattern_idx, :])
1177

◆ _validate_patterns()

None microscope.abc.DeformableMirror._validate_patterns ( self,
numpy.ndarray patterns )
protected
Validate the shape of a series of patterns.

Only validates the shape of the patterns, not if the values
are actually in the [0 1] range.  If some hardware is unable
to handle values outside their defined range (most will simply
clip them), then it's the responsability of the subclass to do
the clipping before sending the values.

Definition at line 1086 of file abc.py.

1086 def _validate_patterns(self, patterns: numpy.ndarray) -> None:
1087 """Validate the shape of a series of patterns.
1088
1089 Only validates the shape of the patterns, not if the values
1090 are actually in the [0 1] range. If some hardware is unable
1091 to handle values outside their defined range (most will simply
1092 clip them), then it's the responsability of the subclass to do
1093 the clipping before sending the values.
1094
1095 """
1096 if patterns.ndim > 2:
1097 raise ValueError(
1098 "PATTERNS has %d dimensions (must be 1 or 2)" % patterns.ndim
1099 )
1100 elif patterns.shape[-1] != self.n_actuators:
1101 raise ValueError(
1102 (
1103 "PATTERNS length of second dimension '%d' differs"
1104 " from number of actuators '%d'"
1105 % (patterns.shape[-1], self.n_actuators)
1106 )
1107 )
1108

◆ apply_pattern()

None microscope.abc.DeformableMirror.apply_pattern ( self,
numpy.ndarray pattern )
Apply this pattern.

Raises:
    microscope.IncompatibleStateError: if device trigger type is
        not set to software.

Definition at line 1113 of file abc.py.

1113 def apply_pattern(self, pattern: numpy.ndarray) -> None:
1114 """Apply this pattern.
1115
1116 Raises:
1117 microscope.IncompatibleStateError: if device trigger type is
1118 not set to software.
1119
1120 """
1121 if self.trigger_type is not microscope.TriggerType.SOFTWARE:
1122 # An alternative to error is to change the trigger type,
1123 # apply the pattern, then restore the trigger type, but
1124 # that would clear the queue on the device. It's better
1125 # to have the user specifically do it. See issue #61.
1127 "apply_pattern requires software trigger type"
1128 )
1129 self._validate_patterns(pattern)
1130 self._do_apply_pattern(pattern)
1131

◆ n_actuators()

int microscope.abc.DeformableMirror.n_actuators ( self)

Definition at line 1083 of file abc.py.

1083 def n_actuators(self) -> int:
1084 raise NotImplementedError()
1085

◆ next_pattern()

None microscope.abc.DeformableMirror.next_pattern ( self)
Apply the next pattern in the queue.

DEPRECATED: this is the same as calling :meth:`trigger`.

Definition at line 1148 of file abc.py.

1148 def next_pattern(self) -> None:
1149 """Apply the next pattern in the queue.
1150
1151 DEPRECATED: this is the same as calling :meth:`trigger`.
1152
1153 """
1154 self.trigger()
1155

◆ queue_patterns()

None microscope.abc.DeformableMirror.queue_patterns ( self,
numpy.ndarray patterns )
Send values to the mirror.

Args:
    patterns: An `KxN` elements array of values in the range
        `[0 1]`, where `N` equals the number of actuators, and
        `K` is the number of patterns.

A convenience fallback is provided for software triggering is
provided.

Reimplemented in microscope.mirror.alpao.AlpaoDeformableMirror.

Definition at line 1132 of file abc.py.

1132 def queue_patterns(self, patterns: numpy.ndarray) -> None:
1133 """Send values to the mirror.
1134
1135 Args:
1136 patterns: An `KxN` elements array of values in the range
1137 `[0 1]`, where `N` equals the number of actuators, and
1138 `K` is the number of patterns.
1139
1140 A convenience fallback is provided for software triggering is
1141 provided.
1142
1143 """
1144 self._validate_patterns(patterns)
1145 self._patterns = patterns
1146 self._pattern_idx = -1 # none is applied yet
1147

◆ trigger()

None microscope.abc.DeformableMirror.trigger ( self)
Apply the next pattern in the queue.

Reimplemented from microscope.abc.TriggerTargetMixin.

Definition at line 1178 of file abc.py.

1178 def trigger(self) -> None:
1179 """Apply the next pattern in the queue."""
1180 # This is just a passthrough to the TriggerTargetMixin class
1181 # and only exists for the docstring.
1182 return super().trigger()
1183
1184

Member Data Documentation

◆ _pattern_idx

microscope.abc.DeformableMirror._pattern_idx = -1
protected

Definition at line 1079 of file abc.py.

◆ _patterns

typing.Optional[numpy.ndarray] microscope.abc.DeformableMirror._patterns = None
protected

Definition at line 1078 of file abc.py.

◆ n_actuators

microscope.abc.DeformableMirror.n_actuators

Definition at line 1105 of file abc.py.


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