Skip to content

MDAWidget

MDAWidget widget

This image generated from example code below.

MDAWidget #

Bases: MDASequenceWidget

Main MDA Widget connected to a pymmcore_plus.CMMCorePlus instance.

It provides a GUI to construct and run a useq.MDASequence. Unlike useq_widgets.MDASequenceWidget, this widget is connected to a pymmcore_plus.CMMCorePlus instance, enabling awareness and control of the current state of the microscope.

Parameters:

Name Type Description Default
parent QWidget | None

Optional parent widget, by default None.

None
mmcore CMMCorePlus | None

Optional CMMCorePlus micromanager core. By default, None. If not specified, the widget will use the active (or create a new) CMMCorePlus.instance.

None

_enable_af(state: bool) -> None #

Override the autofocus enablement to account for the autofocus device.

_get_autofocus_device() -> str | None #

Return the autofocus device if available.

If there is also a z plan selected, the Autofocus device is only available if the z plan is not in absolute mode.

_get_current_stage_position() -> Position #

Return the current stage position.

_get_tooltip(wdg: QWidget) -> str #

Return the tooltip for the autofocus widgets.

_update_autofocus_enablement() -> None #

Enable or disable the autofocus widgets.

Enable af_axis and af_per_position only if there is an autofocus device and no absolute z plan is selected.

_update_save_path_from_metadata(sequence: MDASequence, update_widget: bool = True, update_metadata: bool = False) -> Path | None #

Get the next available save path from sequence metadata and update widget.

Parameters:

Name Type Description Default
sequence MDASequence

The MDA sequence to get the save path from. (must be in the 'pymmcore_widgets' key of the metadata)

required
update_widget bool

Whether to update the save widget with the new path, by default True.

True
update_metadata bool

Whether to update the Sequence metadata with the new path, by default False.

False

execute_mda(output: Path | str | SupportsFrameReady | Sequence[Path | str | SupportsFrameReady] | None) -> None #

Execute the MDA experiment corresponding to the current value.

get_next_available_path(requested_path: Path) -> Path #

Get the next available path.

This method is called immediately before running an MDA to ensure that the file being saved does not overwrite an existing file. It is also called at the end of the experiment to update the save widget with the next available path.

It may be overridden to provide custom behavior, but it should always return a Path object to a non-existing file or folder.

The default behavior adds/increments a 3-digit counter at the end of the path (before the extension) if the path already exists.

Parameters:

Name Type Description Default
requested_path Path

The path we are requesting for use.

required

prepare_mda() -> bool | str | Path | None #

Prepare the MDA sequence experiment.

Returns:

Type Description
bool

False if MDA to be cancelled due to autofocus issue.

str | Path

Preparation successful, save path to be used for saving and saving active

None

Preparation successful, saving deactivated

setValue(value: MDASequence) -> None #

Get the current state of the widget as a useq.MDASequence.

value() -> MDASequence #

Set the current state of the widget from a useq.MDASequence.

Example#

mda_widget.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""MDAWidget is a widget for creating and running a useq.MDASequence.

It is fully connected to the CMMCorePlus object, and has a "run" button.
"""

from contextlib import suppress

import useq
from pymmcore_plus import CMMCorePlus
from qtpy.QtWidgets import QApplication

from pymmcore_widgets import MDAWidget

with suppress(ImportError):
    from rich import print

app = QApplication([])

CMMCorePlus.instance().loadSystemConfiguration()

wdg = MDAWidget()
wdg.channels.setChannelGroups({"Channel": ["DAPI", "FITC"]})
wdg.time_plan.setValue(useq.TIntervalLoops(interval=0.5, loops=11))
wdg.valueChanged.connect(lambda: print(wdg.value()))
wdg.show()
app.exec()