Connecting Napari to current Omero Server (5.4.9)

I’ve been playing around with Napari and was wondering if it is possible to write a python 3 client that can connect to our currently implemented server (5.4.9). I saw the example code posted recently, but it wasn’t clear to me whether this was only compatible with a development version of Omero server running python 3, or if it was just a dev version of the python 3 Omero API. On my own I haven’t been able to get the dependencies to line up.

1 Like

Maybe @will-moore can help with this one. Here is the post I think you are referring too - Napari loading images from OMERO I havn’t got experience with the omero server, but if there are things we can do on the #napari side of things to make this easier let us know

Hi, I think you’re going to have to use the up-coming OMERO 5.6.0 which will support python 3. See OMERO / Python 3 Rollout Plan. This is getting stable enough for developer testing now.

I’ve put my current omero-napari code at https://gitlab.com/openmicroscopy/incubator/omero-napari. So far, this is very untested code (no-one apart from me has looked at it yet) and the OME team has not discussed it yet.
In fact, I’m aware of some issues with it, which I need to look into a bit more…

Let us know if you want any help trying the pre-releases of OMERO 5.6.0 and if you can help with omero-napari, that would be great!

Regards,
Will.

1 Like

Hi @dstabley. There are not too many API changes between OMERO 5.4 and the upcoming OMERO 5.6 which is the target for the Python 3 migration. There’s some chance that we can help you to get it working. But to quote from OMERO / Python 3 Rollout Plan :

As a result, all future security patches will only be available for OMERO 5.6 and greater. For your own safety, it will be imperative that you be ready to upgrade your OMERO installation early in 2020.

I’d strongly encourage you to drive an upgrade of your OMERO to 5.6. We will definitely help with that. :slightly_smiling_face:

All the best,
~Josh

for what it’s worth, I tried @will-moore’s code last night with our 5.4.10.56 OMERO instance and it worked great! (as usual, the only difficult part was getting the zeroc-ice dependency installed which required some finagling of my command line tools to compile correctly).
A couple images did throw IndexErrors, but I haven’t had time to see whether that was an API mismatch error or something else.

1 Like

@talley @will-moore @joshmoore I can get this far into it but the final pip install -e . errors out.

(naparitest) C:\Users\dstabley\omero-py>pip install -e .
Obtaining file:///C:/Users/dstabley/omero-py
    ERROR: Command errored out with exit status 1:
     command: 'C:\ProgramData\Anaconda3\envs\naparitest\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\dstabley\\omero-py\\setup.py'"'"'; __file__='"'"'C:\\Users\\dstabley\\omero-py\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info
         cwd: C:\Users\dstabley\omero-py\
    Complete output (42 lines):
    running egg_info
    creating target\omero_py.egg-info
    writing target/omero_py.egg-info\PKG-INFO
    writing dependency_links to target/omero_py.egg-info\dependency_links.txt
    writing requirements to target/omero_py.egg-info\requires.txt
    writing top-level names to target/omero_py.egg-info\top_level.txt
    writing manifest file 'target/omero_py.egg-info\SOURCES.txt'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\dstabley\omero-py\setup.py", line 219, in <module>
        'devtarget': DevTargetCommand,
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\site-packages\setuptools\__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\distutils\dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\site-packages\setuptools\command\egg_info.py", line 296, in run
        self.find_sources()
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\site-packages\setuptools\command\egg_info.py", line 303, in find_sources
        mm.run()
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\site-packages\setuptools\command\egg_info.py", line 534, in run
        self.add_defaults()
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\site-packages\setuptools\command\egg_info.py", line 570, in add_defaults
        sdist.add_defaults(self)
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\site-packages\setuptools\command\py36compat.py", line 34, in add_defaults
        self._add_defaults_python()
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\site-packages\setuptools\command\sdist.py", line 127, in _add_defaults_python
        build_py = self.get_finalized_command('build_py')
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\distutils\cmd.py", line 299, in get_finalized_command
        cmd_obj.ensure_finalized()
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\distutils\cmd.py", line 107, in ensure_finalized
        self.finalize_options()
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\site-packages\setuptools\command\build_py.py", line 34, in finalize_options
        orig.build_py.finalize_options(self)
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\distutils\command\build_py.py", line 55, in finalize_options
        self.package_dir[name] = convert_path(path)
      File "C:\ProgramData\Anaconda3\envs\naparitest\lib\distutils\util.py", line 127, in convert_path
        raise ValueError("path '%s' cannot end with '/'" % pathname)
    ValueError: path 'target/' cannot end with '/'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Ah, Windows. Looks like a setup.py/build issue has slipped in in the migration. We’ll look into getting a test environment set up. In the meantime, you might try removing the / on line 202 ("target/"):

git diff setup.py
diff --git a/setup.py b/setup.py
index e4241b68..3bcc80b0 100644
--- a/setup.py
+++ b/setup.py
@@ -199,7 +199,7 @@ setup(
     author="The Open Microscopy Team",
     author_email="ome-devel@lists.openmicroscopy.org.uk",
     url=url,
-    package_dir={"": "target/"},
+    package_dir={"": "target"},

~J

@joshmoore That did it, thanks!

1 Like

Thanks for letting us know. https://github.com/ome/omero-py/pull/132 ~J

@joshmoore I think this is completely unrelated, but I am now getting the following when actually trying to connect:

Traceback (most recent call last):
  File "c:/Users/dstabley/Downloads/1.0/1.0/SampleScript.py", line 10, in <module>
    image = conn.getObject("Image", IMAGE_ID)
  File "c:\users\dstabley\omero-py\target\omero\gateway\__init__.py", line 3269, in getObject
    result = self.getQueryService().findByQuery(
  File "c:\users\dstabley\omero-py\target\omero\gateway\__init__.py", line 2564, in getQueryService
    return self._proxies['query']
  File "c:\users\dstabley\omero-py\target\omero\gateway\__init__.py", line 1502, in __getitem__
    raise Ice.ConnectionLostException
Ice.ConnectionLostException: Ice.ConnectionLostException:
recv() returned zero

Hey @dstabley,

I wouldn’t think this is related to the migration to Python 3, but it may stem from using an older version of OMERO. Is there any related standard out/err?

~Josh

We watched the server activity through SSH as it was trying to connect and didn’t see anything, it looks like it isn’t contacting the server at all, we didn’t see anything from the omero side. If I remove all of the code and try a simple connect and close through BlitzGateway I get the following:

C:\Users\dstabley>C:/ProgramData/Anaconda3/envs/naparitest/python.exe c:/Users/dstabley/Downloads/1.0/1.0/SampleScript.py
closing conn…
WARNING:omero.client:…Ignoring error in client.del:<class ‘Ice.SecurityException’>

SecurityException looks to be new for this thread. Can you possibly share your SampleScript.py? ~J.

It is identical to the script Will posted, just using our info and an image that is in our Omero instance:

import napari
from vispy.color import Colormap
import numpy
from omero.gateway import BlitzGateway
conn = BlitzGateway(“username”, “password”, port=4064, host=“omero.stjude.org”)
conn.connect()

IMAGE_ID = 8803
image = conn.getObject(“Image”, IMAGE_ID)

def get_z_stack(img, c=0, t=0):
zct_list = [(z, c, t) for z in range(img.getSizeZ())]
pixels = image.getPrimaryPixels()
return numpy.array(list(pixels.getPlanes(zct_list)))

with napari.gui_qt():
viewer = napari.Viewer()

for c, channel in enumerate(image.getChannels()):
    print('loading channel %s' % c)
    data = get_z_stack(image, c=c)
    # use current rendering settings from OMERO
    color = channel.getColor().getRGB()
    color = [r/256 for r in color]
    cmap = Colormap([[0, 0, 0], color])
    # Z-scale for 3D viewing
    size_x = image.getPixelSizeX()
    size_z = image.getPixelSizeZ()
    z_scale = size_z / size_x
    viewer.add_image(data, blending='additive',
                     colormap=('from_omero', cmap),
                     scale=[1, z_scale, 1, 1],
                     name=channel.getLabel())

print(‘closing conn…’)

conn.close()

I’ve tried connecting to an OMERO 5.4 server from my omero-py 5.6 virtualenv and I can’t reproduce any SecurityException. We can only guess it might be some issue with Windows or SSL related (I can’t easily test on Windows).

Hopefully upgrading to OMERO 5.6 will help (we will have our first release candidate out soon) and we will certainly test Windows connection to OMERO 5.6.
Regards,

Will.