Skip to content

Instantly share code, notes, and snippets.

@oeway
Last active September 6, 2020 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oeway/f2564258a5a72fa8819e30fda34f030d to your computer and use it in GitHub Desktop.
Save oeway/f2564258a5a72fa8819e30fda34f030d to your computer and use it in GitHub Desktop.
<config lang="json">
{
"name": "PycroManagerControl",
"type": "native-python",
"version": "0.1.0",
"description": "Microscope control with PycroManager",
"tags": [],
"ui": "",
"cover": "",
"inputs": null,
"outputs": null,
"flags": [],
"icon": "extension",
"api_version": "0.1.8",
"env": "",
"permissions": [],
"requirements": ["pycromanager", "numpy"],
"dependencies": []
}
</config>
<script lang="python">
import time
from imjoy import api
import numpy as np
from pycromanager import Bridge
class MyMicroscope():
async def setup(self):
bridge = Bridge()
self._core = bridge.get_core()
exposure = self._core.get_exposure()
api.showMessage('MMcore loaded, exposure: ' + str(exposure))
def snap_image(self):
if self._core.is_sequence_running():
self._core.stop_sequence_acquisition()
self._core.snap_image()
tagged_image = self._core.get_tagged_image()
image_array = np.reshape(tagged_image.pix, newshape=[-1, tagged_image.tags['Height'], tagged_image.tags['Width']])
image_array = (image_array/image_array.max()*255).astype('uint8')
return image_array
def get_image(self):
# we can also check remaining with getRemainingImageCount()
tagged_image = self._core.get_tagged_image()
image_array = np.reshape(tagged_image.pix, newshape=[-1, tagged_image.tags['Height'], tagged_image.tags['Width']])
image_array = (image_array/image_array.max()*255).astype('uint8')
return image_array
def get_device_properties(self):
core = self._core
devices = core.get_loaded_devices()
devices = [devices.get(i) for i in range(devices.size())]
device_items = []
for device in devices:
names = core.get_device_property_names(device)
props = [names.get(i) for i in range(names.size())]
property_items = []
for prop in props:
value = core.get_property(device, prop)
is_read_only = core.is_property_read_only(device, prop)
if core.has_property_limits(device, prop):
lower = core.get_property_lower_limit(device, prop)
upper = core.get_property_upper_limit(device, prop)
allowed = {"type": "range", "min": lower, "max": upper, "readOnly": is_read_only}
else:
allowed = core.get_allowed_property_values(device, prop)
allowed = {"type": "enum", "options": [allowed.get(i) for i in range(allowed.size())], "readOnly": is_read_only}
property_items.append({"device": device, "name": prop, "value": value, "allowed": allowed})
# print('===>', device, prop, value, allowed)
if len(property_items) > 0:
device_items.append({"name": device, "value": "{} properties".format(len(props)), "items": property_items})
return device_items
async def run(self, ctx):
mmcore_api = {
"_rintf": True,
"snapImage": self.snap_image,
"getImage": self.get_image,
"getDeviceProperties": self.get_device_properties,
"getCameraDevice": self._core.get_camera_device,
"setCameraDevice": self._core.set_camera_device,
"startContinuousSequenceAcquisition": self._core.start_continuous_sequence_acquisition,
"stopSequenceAcquisition": self._core.stop_sequence_acquisition,
"setExposure": self._core.set_exposure,
"getExposure": self._core.get_exposure,
"setProperty": self._core.set_property,
"getProperty": self._core.get_property
}
viewer = await api.createWindow(src='https://gist.github.com/oeway/f59c1d1c49c94a831e5e21ba4c6111dd', data={'mmcore': mmcore_api})
api.export(MyMicroscope())
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment