pymmcore_plus.experimental.unicore
¶
Pure-Python device adapters, used alongside C++ devices with UniMMCore.
Classes
| Name | Description |
|---|---|
CameraDevice |
|
Device |
ABC for all Devices. |
GenericDevice |
Generic device API, e.g. for devices that don't fit into other categories. |
HubDevice |
ABC for Hub devices that can have peripheral devices attached. |
PropertyInfo |
State of a property of a device. |
SLMDevice |
ABC for Spatial Light Modulator (SLM) devices. |
ShutterDevice |
Shutter device API, e.g. for physical shutters or electronic shutter control. |
SimpleCameraDevice |
A convenience subclass of CameraDevice for simple/simulated cameras. |
StageDevice |
ABC for Stage devices. |
StateDevice |
State device API, e.g. filter wheel, objective turret, etc. |
UniMMCore |
Unified Core object that first checks for python, then C++ devices. |
XYStageDevice |
ABC for XYStage devices. |
XYStepperStageDevice |
ABC for XYStage devices that support stepper motors. |
Functions
| Name | Description |
|---|---|
pymm_property |
Decorates a (getter) method to create a device property. |
Classes¶
UniMMCore
¶
Bases: CMMCorePlus
Unified Core object that first checks for python, then C++ devices.
- User Guide Advanced Topics UniMMCore A unified controller of C++ and pure-Python devices
loadSystemConfiguration
¶
Load a system config file conforming to the MM .cfg format.
This is a Python implementation that supports both C++ and Python devices.
Lines prefixed with #py are processed as Python device commands but
are ignored by upstream C++/pymmcore implementations.
Format example:
# C++ devices
Device,Camera,DemoCamera,DCam
Property,Core,Initialize,1
# Python devices (hidden from upstream via comment prefix)
#py pyDevice,PyCamera,mypackage.cameras,MyCameraClass
#py Property,PyCamera,Exposure,50.0
See https://micro-manager.org/Micro-Manager_Configuration_Guide#configuration-file-syntax
For relative paths, the current working directory is first checked, then the device adapter path is checked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fileName
|
str | Path
|
Path to the configuration file. Defaults to "MMConfig_demo.cfg". |
'MMConfig_demo.cfg'
|
saveSystemConfiguration
¶
Save the current system configuration to a text file.
This saves both C++ and Python devices. Python device lines are prefixed
with #py by default so they are ignored by upstream C++/pymmcore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
Path to save the configuration file. |
required |
prefix_py_devices
|
bool
|
If True (default), Python device lines are prefixed with |
True
|
loadDevice
¶
Loads a device from the plugin library, or python module.
In the standard MM case, this will load a device from the plugin library:
For python devices, this will load a device from a python module:
loadPyDevice
¶
Load a unicore.Device as a python device.
This API allows you to create python-side Device objects that can be used in tandem with the C++ devices. Whenever a method is called that would normally interact with a C++ device, this class will first check if a python device with the same label exists, and if so, use that instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label to assign to the device. |
required |
device
|
Device
|
The device object to load. Use the appropriate subclass of |
required |
isPyDevice
¶
Returns True if the specified device label corresponds to a Python device.
getDeviceInitializationState
¶
getDeviceInitializationState(label: str) -> DeviceInitializationState
setParentLabel
¶
getLoadedPeripheralDevices
¶
getInstalledDeviceDescription
¶
getInstalledDeviceDescription(
hubLabel: DeviceLabel | str, peripheralLabel: DeviceName | str
) -> str
getDevicePropertyNames
¶
getPropertyFromCache
¶
hasPropertyLimits
¶
getPropertyLowerLimit
¶
getPropertyUpperLimit
¶
getAllowedPropertyValues
¶
getAllowedPropertyValues(
label: DeviceLabel | str, propName: PropertyName | str
) -> tuple[str, ...]
isPropertyPreInit
¶
isPropertyReadOnly
¶
isPropertySequenceable
¶
getPropertySequenceMaxLength
¶
loadPropertySequence
¶
loadPropertySequence(
label: DeviceLabel | str,
propName: PropertyName | str,
eventSequence: Sequence[Any],
) -> None
startPropertySequence
¶
stopPropertySequence
¶
getXYStageDevice
¶
getXYStageDevice() -> DeviceLabel | Literal['']
Returns the label of the currently selected XYStage device.
Returns empty string if no XYStage device is selected.
getXPosition
¶
Obtains the current position of the X axis of the XY stage in microns.
getYPosition
¶
Obtains the current position of the Y axis of the XY stage in microns.
getXYStageSequenceMaxLength
¶
Gets the maximum length of an XY stage's position sequence.
isXYStageSequenceable
¶
Queries XY stage if it can be used in a sequence.
loadXYStageSequence
¶
loadXYStageSequence(
xyStageLabel: DeviceLabel | str,
xSequence: Sequence[float],
ySequence: Sequence[float],
) -> None
Transfer a sequence of stage positions to the xy stage.
xSequence and ySequence must have the same length. This should only be called for XY stages that are sequenceable
setOriginX
¶
setOriginX(xyStageLabel: DeviceLabel | str) -> None
setOriginX(xyStageLabel: DeviceLabel | str = '') -> None
Zero the given XY stage's X coordinate at the current position.
setOriginY
¶
setOriginY(xyStageLabel: DeviceLabel | str) -> None
setOriginY(xyStageLabel: DeviceLabel | str = '') -> None
Zero the given XY stage's Y coordinate at the current position.
setOriginXY
¶
setOriginXY(xyStageLabel: DeviceLabel | str) -> None
setOriginXY(xyStageLabel: DeviceLabel | str = '') -> None
Zero the given XY stage's coordinates at the current position.
setAdapterOriginXY
¶
setAdapterOriginXY(*args: Any) -> None
Enable software translation of coordinates for the current XY stage.
The current position of the stage becomes (newXUm, newYUm). It is recommended that setOriginXY() be used instead where available.
setRelativeXYPosition
¶
setRelativeXYPosition(*args: Any) -> None
Sets the relative position of the XY stage in microns.
startXYStageSequence
¶
startXYStageSequence(xyStageLabel: DeviceLabel | str) -> None
Starts an ongoing sequence of triggered events in an XY stage.
This should only be called for stages that are sequenceable
stopXYStageSequence
¶
stopXYStageSequence(xyStageLabel: DeviceLabel | str) -> None
Stops an ongoing sequence of triggered events in an XY stage.
This should only be called for stages that are sequenceable
getPosition
¶
getFocusDirection
¶
getFocusDirection(stageLabel: DeviceLabel | str) -> FocusDirection
Get the current focus direction of the Z stage.
setOrigin
¶
setOrigin(stageLabel: DeviceLabel | str) -> None
setOrigin(stageLabel: DeviceLabel | str | None = None) -> None
Zero the current focus/Z stage's coordinates at the current position.
setRelativePosition
¶
setRelativePosition(d: float) -> None
setRelativePosition(*args: Any) -> None
Sets the relative position of the stage in microns.
setAdapterOrigin
¶
setAdapterOrigin(newZUm: float) -> None
setAdapterOrigin(*args: Any) -> None
Enable software translation of coordinates for the current focus/Z stage.
The current position of the stage becomes Z = newZUm. Only some stages support this functionality; it is recommended that setOrigin() be used instead where available.
isStageSequenceable
¶
Queries stage if it can be used in a sequence.
isStageLinearSequenceable
¶
Queries if the stage can be used in a linear sequence.
A linear sequence is defined by a step size and number of slices.
getStageSequenceMaxLength
¶
Gets the maximum length of a stage's position sequence.
loadStageSequence
¶
Transfer a sequence of stage positions to the stage.
This should only be called for stages that are sequenceable.
startStageSequence
¶
startStageSequence(stageLabel: DeviceLabel | str) -> None
Starts an ongoing sequence of triggered events in a stage.
This should only be called for stages that are sequenceable.
stopStageSequence
¶
stopStageSequence(stageLabel: DeviceLabel | str) -> None
Stops an ongoing sequence of triggered events in a stage.
This should only be called for stages that are sequenceable.
setStageLinearSequence
¶
Loads a linear sequence (defined by step size and nr. of steps).
isContinuousFocusDrive
¶
Check if a stage has continuous focusing capability.
Returns True if positions can be set while continuous focus runs.
home
¶
home(xyOrZStageLabel: DeviceLabel | str) -> None
Perform a hardware homing operation for an XY or focus/Z stage.
getCameraDevice
¶
getCameraDevice() -> DeviceLabel | Literal['']
Returns the label of the currently selected camera device.
Returns empty string if no camera device is selected.
getImage
¶
isSequenceRunning
¶
getLastImageMD
¶
getNBeforeLastImageMD
¶
setCircularBufferMemoryFootprint
¶
setCircularBufferMemoryFootprint(sizeMB: int) -> None
Set the circular buffer memory footprint in MB.
getBufferFreeCapacity
¶
getBufferFreeCapacity() -> int
Get the number of free slots in the circular buffer.
getBufferTotalCapacity
¶
getBufferTotalCapacity() -> int
Get the total capacity of the circular buffer.
getCircularBufferMemoryFootprint
¶
getCircularBufferMemoryFootprint() -> int
Get the circular buffer memory footprint in MB.
getCameraChannelName
¶
Get the name of the camera channel.
getExposure
¶
Get the exposure time in milliseconds.
getROI
¶
Get the current region of interest (ROI) for the camera.
isExposureSequenceable
¶
Check if the camera supports exposure sequences.
loadExposureSequence
¶
loadExposureSequence(
cameraLabel: DeviceLabel | str, exposureSequence_ms: Sequence[float]
) -> None
Transfer a sequence of exposure times to the camera.
getExposureSequenceMaxLength
¶
Get the maximum length of the exposure sequence.
startExposureSequence
¶
startExposureSequence(cameraLabel: DeviceLabel | str) -> None
Start a sequence of exposures.
stopExposureSequence
¶
stopExposureSequence(cameraLabel: DeviceLabel | str) -> None
Stop a sequence of exposures.
prepareSequenceAcquisition
¶
prepareSequenceAcquisition(cameraLabel: DeviceLabel | str) -> None
Prepare the camera for sequence acquisition.
getPixelSizeAffine
¶
getPixelSizeAffine(cached: bool) -> AffineTuple
getPixelSizeAffine(cached: bool = False) -> AffineTuple
Get the pixel size affine transformation matrix.
getPixelSizeUm
¶
Get the pixel size in micrometers.
getSLMDevice
¶
getSLMDevice() -> DeviceLabel | Literal['']
Returns the label of the currently selected SLM device.
Returns empty string if no SLM device is selected.
setSLMImage
¶
setSLMImage(pixels: ndarray) -> None
setSLMImage(*args: Any) -> None
Load the image into the SLM device adapter.
getSLMImage
¶
Get the current image from the SLM device.
setSLMPixelsTo
¶
setSLMPixelsTo(intensity: int) -> None
setSLMPixelsTo(*args: Any) -> None
Set all pixels of the SLM to a uniform intensity or RGB values.
displaySLMImage
¶
displaySLMImage(slmLabel: DeviceLabel | str) -> None
displaySLMImage(slmLabel: DeviceLabel | str | None = None) -> None
Command the SLM to display the loaded image.
setSLMExposure
¶
setSLMExposure(interval_ms: float) -> None
setSLMExposure(*args: Any) -> None
Command the SLM to turn off after a specified interval.
getSLMExposure
¶
Find out the exposure interval of an SLM.
getSLMWidth
¶
Returns the width of the SLM in pixels.
getSLMHeight
¶
Returns the height of the SLM in pixels.
getSLMNumberOfComponents
¶
Returns the number of color components (channels) in the SLM.
getSLMBytesPerPixel
¶
Returns the number of bytes per pixel for the SLM.
getSLMSequenceMaxLength
¶
Get the maximum length of an image sequence that can be uploaded.
loadSLMSequence
¶
Load a sequence of images to the SLM.
startSLMSequence
¶
startSLMSequence(slmLabel: DeviceLabel | str) -> None
Start a sequence of images on the SLM.
stopSLMSequence
¶
stopSLMSequence(slmLabel: DeviceLabel | str) -> None
Stop a sequence of images on the SLM.
setState
¶
Set state (position) on the specific device.
getState
¶
Return the current state (position) on the specific device.
getNumberOfStates
¶
Return the total number of available positions (states).
setStateLabel
¶
Set device state using the previously assigned label (string).
getStateLabel
¶
getStateLabel(stateDeviceLabel: DeviceLabel | str) -> StateLabel
Return the current state as the label (string).
defineStateLabel
¶
Define a label for the specific state.
getStateLabels
¶
Return labels for all states.
getStateFromLabel
¶
Obtain the state for a given label.
getShutterDevice
¶
getShutterDevice() -> DeviceLabel | Literal['']
Returns the label of the currently selected Shutter device.
Returns empty string if no Shutter device is selected.
getShutterOpen
¶
defineConfig
¶
defineConfig(
groupName: str,
configName: str,
deviceLabel: str | None = None,
propName: str | None = None,
value: Any | None = None,
) -> None
deleteConfig
¶
deleteConfig(
groupName: str,
configName: str,
deviceLabel: str | None = None,
propName: str | None = None,
) -> None
getConfigData
¶
getConfigData(
configGroup: str, configName: str, *, native: Literal[False] = False
) -> Configuration
getConfigData(
configGroup: str, configName: str, *, native: bool = False
) -> Configuration | Configuration
getCurrentConfigFromCache
¶
getConfigState
¶
getConfigState(
group: str, config: str, *, native: bool = False
) -> Configuration | Configuration
getConfigGroupState
¶
getConfigGroupState(
group: str, *, native: Literal[False] = False
) -> Configuration
getConfigGroupState(
group: str, *, native: bool = False
) -> Configuration | Configuration
getConfigGroupStateFromCache
¶
getConfigGroupStateFromCache(
group: str, *, native: Literal[False] = False
) -> Configuration
getConfigGroupStateFromCache(
group: str, *, native: bool = False
) -> Configuration | Configuration
getSystemState
¶
getSystemState(*, native: bool = False) -> Configuration | Configuration
Return the entire system state including Python device properties.
This method iterates through all devices (C++ and Python) and returns all property values. Following the C++ implementation pattern.
getSystemStateCache
¶
getSystemStateCache(*, native: Literal[True]) -> Configuration
getSystemStateCache(*, native: Literal[False] = False) -> Configuration
getSystemStateCache(*, native: bool = False) -> Configuration | Configuration
updateSystemStateCache
¶
Update the system state cache for all devices including Python devices.
This populates our Python-side cache with current values from all Python devices, then calls the C++ updateSystemStateCache.
CameraDevice
¶
Bases: Device
STANDARD_PROPERTIES
¶
STANDARD_PROPERTIES: ClassVar = MappingProxyType(
{
Keyword.ActualInterval_ms: ("actual_interval_ms", float),
Keyword.Binning: ("binning", int),
Keyword.CameraID: ("camera_id", str),
Keyword.CameraName: ("camera_name", str),
Keyword.CCDTemperature: ("ccd_temperature", float),
Keyword.CCDTemperatureSetPoint: ("ccd_temperature_set_point", float),
Keyword.EMGain: ("em_gain", float),
Keyword.Exposure: ("exposure", float),
Keyword.Gain: ("gain", float),
Keyword.Interval_ms: ("interval_ms", float),
Keyword.Offset: ("offset", float),
"PixelFormat": ("pixel_format", PixelFormat),
Keyword.ReadoutMode: ("readout_mode", str),
Keyword.ReadoutTime: ("readout_time", float),
Keyword.Metadata_ROI_X: ("roi_x", int),
Keyword.Metadata_ROI_Y: ("roi_y", int),
}
)
get_exposure
abstractmethod
¶
get_exposure() -> float
Get the current exposure time in milliseconds.
set_exposure
abstractmethod
¶
set_exposure(exposure: float) -> None
Set the exposure time in milliseconds.
shape
abstractmethod
¶
Return the shape of the current image buffer.
This is used when querying Height, Width and number of components. If the camera is grayscale, it should return (height, width). If the camera is color, it should return (height, width, n_channels).
If the camera supports ROI, this should return the ROI dimensions.
start_sequence
abstractmethod
¶
start_sequence(
n: int | None, get_buffer: Callable[[Sequence[int], DTypeLike], ndarray]
) -> Iterator[Mapping]
Start a sequence acquisition.
This method should be implemented by the camera device adapter and should yield metadata for each acquired image. The implementation should call get_buffer() to get a buffer, fill it with image data, then yield the metadata for that image.
The core will handle threading and synchronization. This function may block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int | None
|
If an integer, this is the number of images to acquire. If None, the camera should acquire images indefinitely until stopped. |
required |
get_buffer
|
Callable[[Sequence[int], DTypeLike], ndarray]
|
A callable that returns a buffer for the camera to fill with image data. You should call this with the shape of the image and the dtype of the image data. The core will produce a buffer of the requested shape and dtype, and you should fill it (in place) with the image data. |
required |
Yields:
| Type | Description |
|---|---|
Mapping
|
Metadata for each acquired image. This should be yielded after the corresponding buffer has been filled with image data. |
register_standard_properties
¶
Inspect the class for standard properties and register them.
get_roi
¶
Return the current ROI as (x, y, width, height).
The default implementation returns the full frame from
shape(). Override in subclasses to support hardware ROI.
set_roi
¶
Set the ROI.
The default implementation raises NotImplementedError.
Override in subclasses to support hardware ROI.
clear_roi
¶
Reset the ROI to the full sensor frame.
No-op by default (nothing was set, nothing to clear).
SimpleCameraDevice
¶
Bases: CameraDevice
A convenience subclass of CameraDevice for simple/simulated cameras.
Instead of implementing start_sequence() and shape()
directly, subclasses only need to implement:
sensor_shape(): the full (height, width) of the sensorsnap(buffer): fill the provided full-frame buffer with image data and return metadata. The buffer is always sized tosensor_shape(). If a ROI is active, cropping is handled automatically by this base class.
Software ROI (set_roi / clear_roi) works out of the box.
.. warning::
This class is not recommended for real hardware cameras that need
efficient ring-buffer or hardware-triggered acquisition. For those,
use subclass CameraDevice directly and implement start_sequence().
Device
¶
Bases: ABC
ABC for all Devices.
- User Guide Advanced Topics UniMMCore Supported device types Common methods
core
property
¶
The device may use this to access a restricted subset of the Core API.
register_property
¶
register_property(
name: str,
*,
default_value: TProp | None = None,
getter: Callable[[TDev], TProp] | None = None,
setter: Callable[[TDev, TProp], None] | None = None,
limits: tuple[int | float, int | float] | None = None,
sequence_max_length: int = 0,
allowed_values: Sequence[TProp] | None = None,
is_read_only: bool = False,
is_pre_init: bool = False,
property_type: PropArg = None,
sequence_loader: Callable[[TDev, Sequence[TProp]], None] | None = None,
sequence_starter: Callable[[TDev], None] | None = None,
sequence_stopper: Callable[[TDev], None] | None = None,
) -> None
Manually register a property.
This is an alternative to using the @pymm_property decorator. It can be used
to register properties that are not defined in the class body. This is useful
for pure "user-side" properties that are not used by the adapter, but which the
adapter may want to access (such as a preference or a configuration setting
that doesn't affect the device's behavior, but which the adapter may want to
read).
Properties defined this way are not accessible as class attributes.
- User Guide Advanced Topics UniMMCore Device properties
has_property
¶
Return True if the device has a property with the given name.
get_property_info
¶
get_property_info(prop_name: str) -> PropertyInfo
Return the property controller for a property.
set_property_value
¶
Set the value of a property.
set_property_allowed_values
¶
Set the allowed values of a property.
set_property_limits
¶
Set the limits of a property.
set_property_sequence_max_length
¶
Set the sequence max length of a property.
load_property_sequence
¶
Load a sequence into a property.
start_property_sequence
¶
start_property_sequence(prop_name: str) -> None
Start a sequence of a property.
stop_property_sequence
¶
stop_property_sequence(prop_name: str) -> None
Stop a sequence of a property.
is_property_sequenceable
¶
Return True if the property is sequenceable.
is_property_read_only
¶
Return True if the property is read-only.
GenericDevice
¶
Bases: Device
Generic device API, e.g. for devices that don't fit into other categories.
Generic Devices generally only use the device property interface.
HubDevice
¶
Bases: Device
ABC for Hub devices that can have peripheral devices attached.
Hub devices represent a central device (e.g., a controller) that can have multiple peripheral devices attached to it. Examples include multi-channel controllers, or devices that manage multiple sub-devices.
To implement a Hub device, simply override get_installed_peripherals():
class MyHub(HubDevice):
def get_installed_peripherals(self) -> Sequence[tuple[str, str]]:
return [
("Motor1", "First motor controller"),
("Motor2", "Second motor controller"),
]
If your hub needs to perform expensive detection (e.g., scanning a bus),
implement caching inside your get_installed_peripherals() method.
get_installed_peripherals
¶
Return information about installed peripheral devices.
Override this method to return a sequence of tuple[str, str] objects
describing all devices that can be loaded as peripherals of this hub.
Returns:
| Type | Description |
|---|---|
Sequence[tuple[str, str]]
|
A sequence of (name, description) tuples for each available peripheral. The name MUST be the name of a class, importable from the same module as this hub. |
PropertyInfo
dataclass
¶
PropertyInfo(
*,
name: str,
default_value: TProp | None = None,
last_value: TProp | None = None,
limits: tuple[int | float, int | float] | None = None,
sequence_max_length: int = 0,
description: str | None = None,
type: PropertyType = Undef,
allowed_values: Sequence[TProp] | None = None,
is_read_only: bool | None = None,
is_pre_init: bool = False,
)
Bases: Generic[TProp]
State of a property of a device.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the property. |
default_value |
TProp | None
|
The default value of the property, by default None. |
last_value |
TProp | None
|
The last value seen from the device, by default None. |
limits |
tuple[int | float, int | float] | None
|
The minimum and maximum values of the property, by default None. |
sequence_max_length |
int
|
The maximum length of a sequence of property values. |
description |
str | None
|
A description of the property, by default None. |
type |
PropertyType
|
The type of the property. |
allowed_values |
Sequence[TProp] | None
|
The allowed values of the property, by default None. |
is_read_only |
bool | None
|
Whether the property is read-only. |
is_pre_init |
bool
|
Whether the property must be set before initialization. |
ShutterDevice
¶
Bases: Device
Shutter device API, e.g. for physical shutters or electronic shutter control.
Or any 2-state device that can be either open or closed.
SLMDevice
¶
Bases: SequenceableDevice[ndarray]
ABC for Spatial Light Modulator (SLM) devices.
SLM devices are capable of displaying images. They are expected to represent a rectangular grid of pixels that can be either 8-bit or 32-bit. Illumination (light source on or off) is logically independent of displaying the image.
shape
abstractmethod
¶
Return the shape of the SLM image buffer.
This is used when querying Width, Height, and number of components. If the SLM is grayscale, it should return (height, width). If the SLM is color, it should return (height, width, n_channels).
set_image
abstractmethod
¶
set_image(pixels: ndarray) -> None
Load the image into the SLM device adapter.
get_image
¶
get_image() -> ndarray
Get the current image from the SLM device adapter.
This is useful for verifying that the image was set correctly.
set_exposure
abstractmethod
¶
set_exposure(interval_ms: float) -> None
Command the SLM to turn off after a specified interval.
get_sequence_max_length
¶
get_sequence_max_length() -> int
Return the maximum length of an image sequence that can be uploaded.
send_sequence
¶
Load a sequence of images to the SLM.
StageDevice
¶
ABC for Stage devices.
set_position_um
abstractmethod
¶
set_position_um(val: float) -> None
Set the position of the stage in microns.
get_position_um
abstractmethod
¶
get_position_um() -> float
Returns the current position of the stage in microns.
get_focus_direction
¶
get_focus_direction() -> FocusDirection
Returns the focus direction of the stage.
set_relative_position_um
¶
set_relative_position_um(d: float) -> None
Move the stage by a relative amount.
Can be overridden for more efficient implementations.
set_adapter_origin_um
¶
set_adapter_origin_um(newZUm: float) -> None
Enable software translation of coordinates.
The current position of the stage becomes Z = newZUm. Only some stages support this functionality; it is recommended that set_origin() be used instead where available.
is_linear_sequenceable
¶
is_linear_sequenceable() -> bool
Return True if the stage supports linear sequences.
A linear sequence is defined by a step size and number of slices.
set_linear_sequence
¶
Load a linear sequence defined by step size and number of slices.
XYStageDevice
¶
ABC for XYStage devices.
set_position_um
abstractmethod
¶
Set the position of the XY stage in microns.
get_position_um
abstractmethod
¶
Returns the current position of the XY stage in microns.
set_origin_x
abstractmethod
¶
Zero the stage's X coordinates at the current position.
set_origin_y
abstractmethod
¶
Zero the stage's Y coordinates at the current position.
set_relative_position_um
¶
Move the stage by a relative amount.
Can be overridden for more efficient implementations.
set_adapter_origin_um
¶
Alter the software coordinate translation between micrometers and steps.
... such that the current position becomes the given coordinates.
set_origin
¶
Zero the stage's coordinates at the current position.
This is a convenience method that calls set_origin_x and set_origin_y.
Can be overridden for more efficient implementations.
XYStepperStageDevice
¶
Bases: XYStageDevice
ABC for XYStage devices that support stepper motors.
In this variant, rather than providing set_position_um and get_position_um,
you provide set_position_steps, get_position_steps, get_step_size_x_um,
and get_step_size_y_um. A default implementation of set_position_um and
get_position_um is then provided that uses these methods, taking into account
the XY-mirroring properties of the device.
set_position_steps
abstractmethod
¶
Set the position of the XY stage in steps.
get_position_steps
abstractmethod
¶
Returns the current position of the XY stage in steps.
get_step_size_x_um
abstractmethod
¶
get_step_size_x_um() -> float
Returns the step size of the X axis in microns.
get_step_size_y_um
abstractmethod
¶
get_step_size_y_um() -> float
Returns the step size of the Y axis in microns.
set_position_um
¶
Set the position of the XY stage in microns.
get_position_um
¶
Get the position of the XY stage in microns.
set_relative_position_steps
¶
Move the stage by a relative amount.
Can be overridden for more efficient implementations.
set_relative_position_um
¶
Default implementation for relative motion.
Can be overridden for more efficient implementations.
set_adapter_origin_um
¶
Alter the software coordinate translation between micrometers and steps.
... such that the current position becomes the given coordinates.
StateDevice
¶
Bases: Device
State device API, e.g. filter wheel, objective turret, etc.
A state device is a device that at any point in time is in a single state out of a list of possible states, like a filter wheel, an objective turret, etc. The interface contains functions to get and set the state, to give states human readable labels, and functions to make it possible to treat the state device as a shutter.
In terms of implementation, this base class provides the basic functionality by presenting state and label as properties, which it keeps in sync with the underlying device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_labels
|
Mapping[int, str] | Iterable[tuple[int, str]]
|
A mapping (or iterable of 2-tuples) of integer state indices to string labels. |
required |
set_state
abstractmethod
¶
set_state(position: int) -> None
Set the state of the device (integer index).
from_count
classmethod
¶
Simplified constructor with just a number of states.
register_standard_properties
¶
Inspect the class for standard properties and register them.
set_position_or_label
¶
Set the position of the device by index or label.
assign_label_to_position
¶
Assign a User-defined label to a position.
Functions¶
pymm_property
¶
pymm_property(fget: Callable[[TDev], TProp]) -> PropertyController[TDev, TProp]
pymm_property(
*,
allowed_values: Sequence[TProp] | None,
sequence_max_length: int = ...,
is_read_only: bool | None = ...,
is_pre_init: bool = ...,
name: str | None = ...,
property_type: PropArg = ...,
) -> Callable[[Callable[[TDev], TProp]], PropertyController[TDev, TProp]]
pymm_property(
fget: Callable[[TDev], TProp] | None = None,
*,
limits: tuple[TLim, TLim] | None = None,
sequence_max_length: int = 0,
allowed_values: Sequence[TProp] | None = None,
is_read_only: bool | None = None,
is_pre_init: bool = False,
name: str | None = None,
property_type: PropArg = None,
) -> (
PropertyController[TDev, TProp]
| Callable[[Callable[[TDev], TProp]], PropertyController[TDev, TProp]]
)
Decorates a (getter) method to create a device property.
The returned PropertyController instance can be additionally used (similar to
@property) to decorate setter, sequence_loader, sequence_starter, and/or
sequence_stopper methods.
Properties can have limits, allowed values, but may not have both.
Properties will only be considered "sequenceable" (i.e. they support hardware
triggering) if they have a non-zero sequence_max_length AND have decorated
sequence_loader and sequence_starter methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fget
|
Callable[[TDev], TProp]
|
The getter method for the property, by default None. |
None
|
limits
|
tuple[float, float]
|
The minimum and maximum values of the property, by default None. Cannot be
combined with |
None
|
sequence_max_length
|
int
|
The maximum length of a sequence of property values, by default 0. |
0
|
allowed_values
|
Sequence[TProp]
|
The allowed values of the property, by default None. Cannot be combined with
|
None
|
is_read_only
|
bool
|
Whether the property is read-only, by default False. |
None
|
is_pre_init
|
bool
|
Whether the property must be set before initialization, by default False. |
False
|
name
|
str
|
The name of the property, by default, the name of the getter method is used. |
None
|
property_type
|
PropArg
|
The type of the property, by default the return annotation of the getter method
is used (but must be one of |
None
|
Examples:
class MyDevice(Device):
@pymm_property(limits=(0, 100), sequence_max_length=10)
def position(self) -> float:
# get position from device
return 42.0
@position.setter
def position(self, value: float) -> None:
print(f"Setting position to {value}")
@position.sequence_loader
def load_position_sequence(self, sequence: Sequence[float]) -> None:
print(f"Loading position sequence: {sequence}")
@position.sequence_starter
def start_position_sequence(self) -> None:
print("Starting position sequence")
@pymm_property(is_read_only=True)
def pressure(self) -> float:
return 1.0
@pymm_property(allowed_values=["low", "medium", "high"])
def speed(self) -> str:
# get speed from device
return "medium"
@speed.setter
def speed(self, value: str) -> None:
print(f"Setting speed to {value}")
- User Guide Advanced Topics UniMMCore Device properties