Example scripts of the things that can be done, typically when interacting with multiple devices.


Simple experiments can be ran with Python only. For a simple time series experiment:

import queue
import time

from microscope.lights.cobolt import CoboltLaser
from microscope.cameras.atmcd import AndorAtmcd

laser = CoboltLaser(com='/dev/ttyS0')
laser.power = 0.3

camera = AndorAtmcd(uid='9146')

buffer = queue.Queue()


for i in range(10):
    camera.trigger()  # images go to buffer


Remote devices

Microscope was designed around the idea that the multiple devices are distributed over the network. To accomplish this, the device objects can be replaced with Client and DataClient instances. For example, to run the previous experiment with remote devices:

import microscope.clients

camera_uri = 'PYRO:SomeCamera@'
laser_uri = 'PYRO:SomeLaser@'

camera = microscope.clients.DataClient(camera_uri)
laser =  microscope.clients.Client(laser_uri)

Device server

The device server requires a configuration file defining the different devices to be initialised. It can be started with:

python3 -m microscope.device_server PATH-TO-CONFIG-FILE

The device server configuration file is a Python script that defines a DEVICES list. Each element in the list corresponds to one device. For example:

"""Configuration file for deviceserver.
# The 'device' function creates device definitions.
from microscope.device_server import device

# Import required device classes
from microscope.lights.cobolt import CoboltLaser
from microscope.cameras.atmcd import AndorAtmcd

# host is the IP address (or hostname) from where the device will be
# accessible.  If everything is on the same computer, then host will
# be ''.  If devices are to be available on the network,
# then it will be the IP address on that network.
host = ""

# Each element in the DEVICES list identifies a device that will be
# served on the network.  Each device is defined like so:
# device(cls, host, port, conf)
#     cls: class of the device that will be served
#     host: ip or hostname where the device will be accessible.
#         This will be the same value for all devices.
#     port: port number where the device will be accessible.
#         Each device must have its own port.
#     conf: a dict with the arguments to construct the device
#         instance.  See the individual class documentation.
# This list, initialises two cobolt lasers and one Andor camera.
    device(CoboltLaser, host, 7701,
           {"com": "/dev/ttyS0"}),
    device(CoboltLaser, host, 7702,
           {"com": "/dev/ttyS1"}),
    device(AndorAtmcd, host, 7703,
           {"uid": "9146"}),

Test devices

Microscope includes multiple simulated devices. These are meant to support development by providing a fake device for testing purposes.

from microscope.device_server import device

from microscope.simulators import (

  device(SimulatedCamera, "", 8005,
         {"sensor_shape": (512, 512)}),
  device(SimulatedLightSource, "", 8006),
  device(SimulatedFilterWheel, "", 8007,
         {"positions": 6}),