Skip to content

Commit

Permalink
Updated Pycromanager to 0.24.1. (#307)
Browse files Browse the repository at this point in the history
* Updated Pycromanager to 0.24.1.
Connects to MM and disconnects, but fails to reconnect.  That problem
seems to be related to ui code I do not understand.

* replace print statements with log and error msg

---------

Co-authored-by: Nico Stuurman <nstuurman@altoslabs.com>
Co-authored-by: Ziwen Liu <67518483+ziw-liu@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 9, 2023
1 parent a1451ee commit 5d56b29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
32 changes: 22 additions & 10 deletions recOrder/plugin/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from recOrder.calib.Calibration import QLIPP_Calibration, LC_DEVICE_NAME
from pycromanager import Bridge
from pycromanager import Core, Studio, zmq_bridge
from qtpy.QtCore import Slot, Signal, Qt
from qtpy.QtWidgets import QWidget, QFileDialog, QSizePolicy, QSlider
from qtpy.QtGui import QPixmap, QColor
Expand Down Expand Up @@ -884,21 +884,26 @@ def connect_to_mm(self):
RECOMMENDED_MM = "20220920"
ZMQ_TARGET_VERSION = "4.2.0"
try:
self.bridge = Bridge(convert_camel_case=False)
self.mmc = self.bridge.get_core()
self.mm = self.bridge.get_studio()
self.mmc = Core(convert_camel_case=False)
# Check it works
self.mmc.getAvailableConfigGroups()
self.mm = Studio(convert_camel_case=False)
# Order is important: If the bridge is created before Core, Core will not work
self.bridge = zmq_bridge._bridge._Bridge()
logging.debug("Established ZMQ Bridge and found Core and Studio")
except:
print(
raise EnvironmentError(
(
"Could not establish pycromanager bridge.\n"
"Is micromanager open?\n"
"Is Tools > Options > Run server on port 4827 checked?\n"
f"Are you using nightly build {RECOMMENDED_MM}?"
)
)
raise EnvironmentError

# Warn the user if there is a MicroManager/ZMQ version mismatch
# NS: Not quite sure what this is good for, we already know the Core works
# This code uses undocumented PycroManager features, so may well break in the future
self.bridge._main_socket.send({"command": "connect", "debug": False})
reply_json = self.bridge._main_socket.receive(timeout=500)
zmq_mm_version = reply_json["version"]
Expand All @@ -909,13 +914,15 @@ def connect_to_mm(self):
< version.parse(ZMQ_TARGET_VERSION)
else "downgrade"
)
print(
logging.warning(
(
"WARNING: This version of Micromanager has not been tested with recOrder.\n"
"This version of Micromanager has not been tested with recOrder.\n"
f"Please {upgrade_str} to MicroManager nightly build {RECOMMENDED_MM}."
)
)

logging.debug("Confirmed correct ZMQ bridge----")

# Find config group containing calibration channels
# calib_channels is typically ['State0', 'State1', 'State2', ...]
# config_list may be something line ['GFP', 'RFP', 'State0', 'State1', 'State2', ...]
Expand All @@ -926,6 +933,7 @@ def connect_to_mm(self):
# self.ui.cb_config_group.clear() # This triggers the enter config we will clear when switching off
groups = self.mmc.getAvailableConfigGroups()
config_group_found = False
logging.debug("Checking MM config group")
for i in range(groups.size()):
group = groups.get(i)
configs = self.mmc.getAvailableConfigs(group)
Expand Down Expand Up @@ -956,6 +964,7 @@ def connect_to_mm(self):
self.ui.cb_acq_channel.addItem(ch)
self.bf_channel_found = True

logging.debug("Checked configs.")
if not config_group_found:
msg = (
f"No config group contains channels {self.calib_channels}. "
Expand All @@ -975,6 +984,7 @@ def connect_to_mm(self):
self.ui.cb_acq_channel.setToolTip(self.no_bf_msg)

# set startup LC control mode
logging.debug("Setting startup LC control mode...")
_devices = self.mmc.getLoadedDevices()
loaded_devices = [_devices.get(i) for i in range(_devices.size())]
if LC_DEVICE_NAME in loaded_devices:
Expand All @@ -991,6 +1001,8 @@ def connect_to_mm(self):
self.calib_mode = "DAC"
self.ui.cb_calib_mode.setCurrentIndex(2)

logging.debug("Finished connecting to MM.")

@Slot(tuple)
def handle_progress_update(self, value):
self.ui.progress_bar.setValue(value[0])
Expand Down Expand Up @@ -1362,8 +1374,8 @@ def enter_config_group(self):
"""
# if/else takes care of the clearing of config
if self.ui.cb_config_group.count() != 0:
self.mmc = self.bridge.get_core()
self.mm = self.bridge.get_studio()
self.mmc = Core(convert_camel_case=False)
self.mm = Studio(convert_camel_case=False)

# Gather config groups and their children
self.config_group = self.ui.cb_config_group.currentText()
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ setup_requires = setuptools_scm
# add your package requirements here
install_requires =
waveorder==1.0.0rc0
pycromanager==0.19.2
pycromanager==0.24.1
click>=8.0.1
natsort>=7.1.1
colorspacious>=1.1.2
Expand All @@ -48,7 +48,6 @@ install_requires =
napari;'arm64' in platform_machine # without Qt and skimage
PyQt6;'arm64' in platform_machine
importlib-metadata
numpy==1.23.5 # TODO: remove after https://github.com/micro-manager/pycro-manager/pull/475

[options.extras_require]
dev =
Expand Down

0 comments on commit 5d56b29

Please sign in to comment.