Skip to content

pymmcore_plus.model

An in-memory model of a Micro-Manager configuration.

This can be used to read, edit and write .cfg files without loading any devices.

Classes

Name Description
AvailableDevice Model of an available device, with a possible hub parent.
ConfigGroup ConfigGroup model.
ConfigPreset ConfigPreset model.
CoreDevice
Device Model of a device.
Microscope Full model of a microscope.
PixelSizeGroup Model of the pixel size group.
PixelSizePreset PixelSizePreset model.
Property Model of a device property.
Setting Model of a device setting.

Classes

ConfigGroup dataclass

ConfigGroup(name: str, presets: MutableMapping[str, ConfigPreset] = dict())

ConfigGroup model.

Attributes:

Name Type Description
name str
presets MutableMapping[str, ConfigPreset]

name

name: str

presets

presets: MutableMapping[str, ConfigPreset] = field(default_factory=dict)

from_metadata classmethod

from_metadata(meta: ConfigGroup) -> Self

create_from_core classmethod

create_from_core(core: CMMCorePlus, name: str) -> Self

update_from_core

update_from_core(core: CMMCorePlus) -> None

Update this object's values from the core.

all_config_groups staticmethod

all_config_groups(core: CMMCorePlus) -> dict[str, ConfigGroup]

Get all config presets from the given core.

apply_to_core

apply_to_core(
    core: CMMCorePlus,
    *,
    exclude: Container[str] = (),
    on_err: ErrCallback | None = None,
    apply_properties: bool = False,
    then_update: bool = True,
) -> None

ConfigPreset dataclass

ConfigPreset(name: str, settings: list[Setting] = list())

ConfigPreset model.

Attributes:

Name Type Description
name str
settings list[Setting]

name

name: str

settings

settings: list[Setting] = field(default_factory=list)

from_metadata classmethod

from_metadata(meta: ConfigPreset) -> Self

Setting

Bases: NamedTuple

Model of a device setting.

Attributes:

Name Type Description
device_name str
property_name str
property_value str

device_name

device_name: str = UNDEFINED

property_name

property_name: str = UNDEFINED

property_value

property_value: str = UNDEFINED

CoreDevice dataclass

CoreDevice(
    name: str = CORE,
    library: str = "",
    adapter_name: str = CORE,
    description: str = "Core device",
    device_type: DeviceType = Core,
    properties: list[Property] = _core_props(),
    delay_ms: float = 0.0,
    uses_delay: bool = False,
    parent_label: str = "",
    initialized: bool = False,
    labels: tuple[str, ...] = tuple(),
    focus_direction: FocusDirection = Unknown,
    children: tuple[str, ...] = tuple(),
)

Bases: Device

Attributes:

Name Type Description
name str
library str
adapter_name str
description str
device_type DeviceType
properties list[Property]
delay_ms float
uses_delay bool
parent_label str
initialized bool
labels tuple[str, ...]
focus_direction FocusDirection
children tuple[str, ...]

name

name: str = CORE

adapter_name

adapter_name: str = CORE

device_type

device_type: DeviceType = DeviceType.Core

description

description: str = 'Core device'

properties

properties: list[Property] = field(default_factory=_core_props)

apply_to_core

apply_to_core(
    core: CMMCorePlus,
    *,
    exclude: Container[str] = (value,),
    on_err: ErrCallback | None = None,
    apply_properties: bool = True,
    then_update: bool = True,
) -> None

AvailableDevice dataclass

AvailableDevice(
    name: str = UNDEFINED,
    library: str = "",
    adapter_name: str = "",
    description: str = "",
    device_type: DeviceType = Any,
    properties: list[Property] = list(),
    delay_ms: float = 0.0,
    uses_delay: bool = False,
    parent_label: str = "",
    initialized: bool = False,
    labels: tuple[str, ...] = tuple(),
    focus_direction: FocusDirection = Unknown,
    children: tuple[str, ...] = tuple(),
    library_hub: AvailableDevice | None = None,
)

Device dataclass

Device(
    name: str = UNDEFINED,
    library: str = "",
    adapter_name: str = "",
    description: str = "",
    device_type: DeviceType = Any,
    properties: list[Property] = list(),
    delay_ms: float = 0.0,
    uses_delay: bool = False,
    parent_label: str = "",
    initialized: bool = False,
    labels: tuple[str, ...] = tuple(),
    focus_direction: FocusDirection = Unknown,
    children: tuple[str, ...] = tuple(),
)

Bases: CoreObject

Model of a device.

Attributes:

Name Type Description
name str
library str
adapter_name str
description str
device_type DeviceType
properties list[Property]
delay_ms float
uses_delay bool
parent_label str
initialized bool
labels tuple[str, ...]
focus_direction FocusDirection
children tuple[str, ...]

name

name: str = UNDEFINED

library

library: str = ''

adapter_name

adapter_name: str = ''

description

description: str = ''

device_type

device_type: DeviceType = DeviceType.Any

properties

properties: list[Property] = field(default_factory=list)

delay_ms

delay_ms: float = 0.0

uses_delay

uses_delay: bool = False

parent_label

parent_label: str = ''

initialized

initialized: bool = False

labels

labels: tuple[str, ...] = field(default_factory=tuple)

focus_direction

children

children: tuple[str, ...] = field(default_factory=tuple)

port property writable

port: str | None

Returns the value of the first property named "Port".

Returns None if the device has no port property.

from_metadata classmethod

from_metadata(metadata: DeviceInfo) -> Self

get_property

get_property(name: str) -> Property

Get a device by name.

set_property

set_property(prop_name: str, value: Any) -> None

set_prop_default

set_prop_default(prop_name: str, value: str = '', **kwargs: Any) -> Property

Works similar to dict.set_default. Add property if it doesn't exist.

replace

replace(**kwargs: Any) -> Device

create_from_core classmethod

create_from_core(core: CMMCorePlus, *args: Any, **kwargs: Any) -> Device

update_from_core

update_from_core(
    core: CMMCorePlus,
    *,
    exclude: Container[str] = (),
    on_err: ErrCallback | None = None,
) -> None

Update device properties from the core.

load

load(core: CMMCorePlus, *, reload: bool = False) -> None

Load device properties from the core.

unload

unload(core: CMMCorePlus) -> None

Unload device from the core.

initialize

initialize(
    core: CMMCorePlus,
    *,
    apply_pre_init: bool = False,
    reload: bool = False,
    then_update: bool = True,
) -> None

Initialize the device in core.

apply_to_core

apply_to_core(
    core: CMMCorePlus,
    *,
    exclude: Container[str] = ("delay_ms",),
    on_err: ErrCallback | None = None,
    apply_properties: bool = True,
    then_update: bool = True,
) -> None

child_descriptions

child_descriptions(core: CMMCorePlus) -> tuple[str, ...]

loaded_peripherals

loaded_peripherals(core: CMMCorePlus) -> tuple[str, ...]

Return device labels of all loaded devices that belong to this hub.

NOTE: unlike "available_peripherals", this returns device labels currently loaded into core. It does not check whether the devices are in the model.

available_peripherals

available_peripherals(model: Microscope) -> Iterable[AvailableDevice]

Return all available devices that belong to this hub that aren't in model.

set_label

set_label(state: int | str, label: str) -> None

Set the label for a state device.

Microscope dataclass

Microscope(
    core_device: CoreDevice = CoreDevice(),
    devices: list[Device] = list(),
    config_groups: dict[str, ConfigGroup] = dict(),
    pixel_size_group: PixelSizeGroup = PixelSizeGroup(),
    config_file: str = "",
    initialized: bool = False,
)

Full model of a microscope.

Attributes:

Name Type Description
core_device CoreDevice

CoreDevice(name: 'str' = 'Core', library: 'str' = '', adapter_name: 'str' = 'Core', description: 'str' = 'Core device', device_type: 'DeviceType' = , properties: 'list[Property]' = , delay_ms: 'float' = 0.0, uses_delay: 'bool' = False, parent_label: 'str' = '', initialized: 'bool' = False, labels: 'tuple[str, ...]' = , focus_direction: 'FocusDirection' = , children: 'tuple[str, ...]' = )

devices list[Device]
config_groups dict[str, ConfigGroup]
pixel_size_group PixelSizeGroup

Model of the pixel size group.

config_file str
initialized bool

core_device

core_device: CoreDevice = field(default_factory=CoreDevice)

devices

devices: list[Device] = field(default_factory=list)

config_groups

config_groups: dict[str, ConfigGroup] = field(default_factory=dict)

pixel_size_group

pixel_size_group: PixelSizeGroup = field(default_factory=PixelSizeGroup)

config_file

config_file: str = ''

initialized

initialized: bool = False

available_devices property

available_devices: tuple[AvailableDevice, ...]

assigned_com_ports property

assigned_com_ports: dict[Device, Device]

Return map of SerialDevice -> DeviceUsingIt.

A com port is "claimed" if it is assigned to a device.

available_serial_devices property

available_serial_devices: Iterable[Device]

Return the available com ports.

reset

reset() -> None

Reset the Microscope to an empty state.

is_dirty

is_dirty() -> bool

Return True if the model has changed since last save.

mark_clean

mark_clean() -> None

Mark the model as clean.

get_device

get_device(name: str) -> Device

Get a device by name.

filter_devices

filter_devices(
    name: str | None = None,
    library: str | None = None,
    adapter_name: str | None = None,
    description: str | None = None,
    device_type: DeviceType | str | None = None,
    parent_label: str | None = None,
) -> Iterable[Device]

Filter devices by name .

create_from_config classmethod

create_from_config(config_file: str | Path) -> Microscope

load_config

load_config(path_or_text: str | Path) -> None

Load model from a micro-manager config file or string.

save

save(path: str | Path) -> None

Save model as a micro-manager config file.

from_summary_metadata classmethod

from_summary_metadata(summary_meta: SummaryMetaV1) -> Microscope

Create a Microscope model from summary metadata.

This may be used to load a model from summary metadata, such as as written during the course of a Multi-Dimensional Acquisition. This is useful for restoring the state of a microscope from a specific experiment, or writing out a cfg file that can be used to restore the state of the microscope.

create_from_core classmethod

create_from_core(core: CMMCorePlus, *args: Any, **kwargs: Any) -> Microscope

update_from_core

update_from_core(
    core: CMMCorePlus,
    *,
    exclude: Container[str] = (),
    on_err: ErrCallback | None = None,
) -> None

Update this object's values from the core.

apply_to_core

apply_to_core(
    core: CMMCorePlus,
    *,
    exclude: Container[str] = (),
    on_err: ErrCallback | None = None,
    apply_properties: bool = True,
    then_update: bool = True,
) -> None

initialize

initialize(
    core: CMMCorePlus,
    on_fail: Callable[[Device | Property, BaseException], bool | None] = _noop,
) -> None

Attempt to initialize all devices in the model.

Simulates what MMCore does upon loading config file.

load_available_devices

load_available_devices(core: CMMCorePlus) -> None

Load the available device list.

update_config_groups_from_core

update_config_groups_from_core(core: CMMCorePlus) -> None

Load config groups from the core.

update_pixel_sizes_from_core

update_pixel_sizes_from_core(core: CMMCorePlus) -> None

Load pixel size groups from the core.

PixelSizeGroup dataclass

PixelSizeGroup(
    name: str = PIXEL_SIZE_GROUP,
    presets: MutableMapping[str, PixelSizePreset] = dict(),
)

Bases: ConfigGroup

Model of the pixel size group.

Attributes:

Name Type Description
name str
presets MutableMapping[str, PixelSizePreset]

name

name: str = PIXEL_SIZE_GROUP

presets

presets: MutableMapping[str, PixelSizePreset] = field(default_factory=dict)

from_metadata classmethod

from_metadata(meta: tuple[PixelSizeConfigPreset, ...]) -> Self

Create a PixelSizeGroup from metadata.

create_from_core classmethod

create_from_core(
    core: CMMCorePlus, name: str = PIXEL_SIZE_GROUP
) -> PixelSizeGroup

Create pixel size presets from the given core.

apply_to_core

apply_to_core(
    core: CMMCorePlus,
    *,
    exclude: Container[str] = (),
    on_err: ErrCallback | None = None,
    apply_properties: bool = False,
    then_update: bool = True,
) -> None

PixelSizePreset dataclass

PixelSizePreset(
    name: str,
    settings: list[Setting] = list(),
    pixel_size_um: float = 0.0,
    affine: AffineTuple = DEFAULT_AFFINE,
    angle_dxdz: float = 0.0,
    angle_dydz: float = 0.0,
    optimalz_um: float = 0.0,
)

Bases: ConfigPreset

PixelSizePreset model.

Attributes:

Name Type Description
name str
settings list[Setting]
pixel_size_um float
affine AffineTuple
angle_dxdz float
angle_dydz float
optimalz_um float

pixel_size_um

pixel_size_um: float = 0.0

affine

affine: AffineTuple = DEFAULT_AFFINE

angle_dxdz

angle_dxdz: float = 0.0

angle_dydz

angle_dydz: float = 0.0

optimalz_um

optimalz_um: float = 0.0

from_metadata classmethod

from_metadata(meta: PixelSizeConfigPreset) -> Self

Property dataclass

Property(
    device_name: str,
    name: str,
    value: str = "",
    is_read_only: bool = False,
    is_pre_init: bool = False,
    allowed_values: tuple[str, ...] = tuple(),
    has_limits: bool = False,
    lower_limit: float = 0.0,
    upper_limit: float = 0.0,
    property_type: PropertyType = Undef,
)

Bases: CoreObject

Model of a device property.

Attributes:

Name Type Description
device_name str
name str
value str
is_read_only bool
is_pre_init bool
allowed_values tuple[str, ...]
has_limits bool
lower_limit float
upper_limit float
property_type PropertyType

device_name

device_name: str

name

name: str

value

value: str = ''

is_read_only

is_read_only: bool = False

is_pre_init

is_pre_init: bool = False

allowed_values

allowed_values: tuple[str, ...] = field(default_factory=tuple)

has_limits

has_limits: bool = False

lower_limit

lower_limit: float = 0.0

upper_limit

upper_limit: float = 0.0

property_type

property_type: PropertyType = PropertyType.Undef

apply_to_core

apply_to_core(
    core: CMMCorePlus,
    *,
    exclude: Container[str] = (),
    on_err: ErrCallback | None = None,
    then_update: bool = True,
) -> None

Apply the property to the given Core instance.