Using the Micro-Manager python library
From Micro-Manager
MMCorePy is a python library that wraps the Micro-Manager C++ core (on both Mac and Windows). The library allows you to control microscope hardware from python scripts or a python command line.
Here is how to get started with the Micro-Manager python library:
- Download and install Micro-Manager on your computer.
- Familiarize yourself with Micro-Manager and learn how to connect it to your hardware by using the existing Java-based GUI (graphical user interface).
- Install the latest versions of:
- python 2.6.x (required; python 3.x is not yet supported)
- numpy (required)
- scipy (optional, good for advanced image processing)
- matplotlib (optional, useful for displaying images)
- ipython (optional, a nice interactive python environment)
- PIL (Python Imaging Library) (optional, image processing and file saving)
- MMCorePy.py will be located in the main Micro-Manager directory; it requires many library files in that directory (with suffixes like .dll, .so, .pyd) to operate. You can make the Micro-Manager python wrapper library work from any directory by adding your micro-manager directory to the PYTHONPATH environment variable.
Images returned by calls to an instance of the pythonized Micro-Manager core class (CMMCore) are stored in numpy arrays for convenience, and can be easily displayed by pylab (matplotlib) commands. Here is a short example (using matplotlib) that demonstrates use of the python wrapper to acquire and display an image.
# Create a Micro-Manager core object:
import MMCorePy
mmc = MMCorePy.CMMCore()
# Load and initialize the demo camera device:
mmc.loadDevice("cam","DemoCamera","DCam")
mmc.initializeDevice("cam")
# Snap and retrieve an image:
mmc.snapImage()
im1 = mmc.getImage()
# Display the image:
from pylab import *
ion() # Activate interactive mode
figure()
imshow(im1,cmap = cm.gray)
A longer example script, MMCoreWrapDemo.py, is available in the Micro-Manager root directory.
