Skip to main content

Control pymmcore (micro-manager) in another process

Project description

pymmcore-plus

Documentation Status License PyPI Python Version CI codecov

🧪🧪 pre-alpha software: work in progress! 🧪🧪

pymmcore-plus aims to extend pymmcore (python bindings for the C++ micro-manager core) with a number of features designed to facilitate working with Micro-manager in pure python/C environments.

  • pymmcore_plus.CMMCorePlus is a subclass of pymmcore.CMMCore that provides additional convenience functions beyond the standard CMMCore API.

    from pymmcore_plus import CMMCorePlus
    core = CMMCorePlus.instance()
    core.loadSystemConfiguration() # loads demo config
    print(core.getLoadedDevices())
    
  • CMMCorePlus includes a run_mda method (name may change) "acquisition engine" that drives micro-manager for conventional multi-dimensional experiments. It accepts an MDASequence from useq-schema for experiment design/declaration.

  • Adds a callback system that adapts the CMMCore callback object to an existing python event loop (such as Qt, or perhaps asyncio/etc...)

  • Includes an experimental Pyro5-based client/server that allows one to create and control and CMMCorePlus instance running in another process, or (conceivably) another computer. To use this feature, install with pip install pymmcore-plus[remote]. (Do try using the single-process CMMCorePlus first, as the interprocess variant is still buggy and does not support MDAs).

    from pymmcore_plus import RemoteMMCore
    
    with RemoteMMCore() as mmcore:
        mmcore.loadSystemConfiguration()
        print(mmcore.getLoadedDevices())
    

Why does this exist?

pymmcore is (and should probably remain) a pure SWIG wrapper for the C++ code at the core of the Micro-Manager project. It is sufficient to control micromanager via python, but lacks some "niceties" that python users are accustomed to. This library can extend the core object, add additional methods, docstrings, type hints, etc... and generally feel more pythonic (note however, camelCase method names from the CMMCore API are not converted to snake_case.)

pycro-manager is an excellent library designed to make it easier to work with and control Micro-manager using python. It's core acquisition engine, however, is written in Java, requiring java to be installed and running in the background (either via the micro-manager GUI application directly, or via a headless process). The python half communicates with the Java half using ZeroMQ messaging.

Among other things, this package aims to provide a pure python / C++ implementation of a MMCore acquisition engine, with no Java dependency (see CMMCorePlus.run_mda... it's minimal at the moment and lacks acquisition hooks). This library also provides an experimental pymmcore_plus.RemoteMMCore proxy object (via Pyro5) that provides a server/client interface for inter-process communication (this serves the same role as the ZMQ server in pycro-manager... but in this case it's communicating with another python process instead of a Java process).

side-note: the useq.MDASequence object that this library uses to define experiments can also generate events consumable by pycro-manager. So if you prefer the pycro-manager approach, but also like the MDASequence schema, you can use both.

Finally, the CMMCorePlus class here adds a callback mechanism that makes it easier to adapt the native MMCore callback system to multiple listeners, across multiple process, which makes it easier to incorporate pymmcore-plus into existing event loops (like a Qt event loop). See napari-micromanager for a nascent project that adds Qt-based GUI interface for micro-manager.

Quickstart

install

# from pip
pip install pymmcore-plus

# if you also want the inter-process RemoteCMMCore feature
pip install pymmcore-plus[remote]

# or from source tree
pip install git+https://github.com/tlambert03/pymmcore-plus.git

device adapters

In most cases you will want the Micro-manager device adapter libraries. These can be downloaded and installed the usual way from the Micro-manager website (use version 2.0-gamma), or, you can use the included installation script to install to the pymmcore-plus install folder:

python -m pymmcore_plus.install

By default, pymmcore-plus will look first for the Micro-Manager device adapters installed using the above command (i.e. in the current or pymmcore_plus folders), and will then look in your Applications or Program Files directory. To override these default device adapter search path, set the MICROMANAGER_PATH environment variable.

Important: The device interface version must match between pymmcore and the Micro-Manager device adapters.

The device interface version of a given pymmcore version is the fourth part in the version number, and can also be with the following command:

python -c "print(__import__('pymmcore').CMMCore().getAPIVersionInfo())"

The device interface version of a given Micro-Manager installation can be viewed in Help > About Micro-Manager. Or you can look at the MMDevice.h file for the corresponding date, roughly here

Examples

You can find for some basic examples in the examples directory.

run a basic MDASequence from useq-schema

create MMCore in the main thread.

python examples/run_mda.py
from pymmcore_plus import CMMCorePlus
from useq import MDASequence

# see
sequence = MDASequence(
    channels=["DAPI", {"config": "FITC", "exposure": 50}],
    time_plan={"interval": 2, "loops": 5},
    z_plan={"range": 4, "step": 0.5},
    axis_order="tpcz",
)

mmc = CMMCorePlus()
# this will load the `MMConfig_demo.cfg` in your micromanager path
mmc.loadSystemConfiguration()
mmc.run_mda(sequence)

attach to or start a remote CMMCorePlus server

python examples/basic_client.py
from pymmcore_plus import RemoteMMCore

with RemoteMMCore() as mmcore:
    mmcore.loadSystemConfiguration()
    print("loaded:", mmcore.getLoadedDevices())
    ...

use with an event loop

see qt_integration for a slightly more 'realistic' example that drives an experiment using threads.

Contributing

Contributions welcome. Please fork this library, then clone locally, then install with extras

pip install -e .[remote,testing]

Run pre-commit install to add pre-commit hooks (black, flake8, mypy, etc...) Run tests with pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymmcore_plus-0.4.0.tar.gz (57.4 kB view details)

Uploaded Source

Built Distribution

pymmcore_plus-0.4.0-py3-none-any.whl (45.4 kB view details)

Uploaded Python 3

File details

Details for the file pymmcore_plus-0.4.0.tar.gz.

File metadata

  • Download URL: pymmcore_plus-0.4.0.tar.gz
  • Upload date:
  • Size: 57.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for pymmcore_plus-0.4.0.tar.gz
Algorithm Hash digest
SHA256 031cc8594f2bea529457402f5f23da75d87bb7e6aba95d5d8eeea32ae317f5e0
MD5 d92365dd78dcb5f4d86f3996b0f17382
BLAKE2b-256 a613fe460a7e4f5619eb267455616a1f08dcdcc1b765bb9786df2d4e0f414ad7

See more details on using hashes here.

Provenance

File details

Details for the file pymmcore_plus-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pymmcore_plus-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 45.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for pymmcore_plus-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8302e2b8b643c987258e3ec7f4b76e54dec48a35ba698d052ebfc7a90ba40a5f
MD5 83ef4ced16d27fe8375d522bd0e2241f
BLAKE2b-256 89c2a0915b1cf5fff4ab5a045ad36fa8d8f18fae24a6ff70c9072468c01f9b2b

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page