Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open labels in https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr #11

Open
will-moore opened this issue Sep 17, 2021 · 3 comments
Open

Comments

@will-moore
Copy link
Member

will-moore commented Sep 17, 2021

We only have a single public example of labels at https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr

e.g. wanted to provide this as a response to https://twitter.com/jm_mightypirate/status/1447486365252399108

But can't get it working...

Starting with recent releases:

napari-0.4.11
napari-ome-zarr==0.2.0
ome-zarr==0.1.0
zarr==2.9.5

$ napari https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr -vvv

Opens the image (2 channels) but No labels channel.

Labels seen in verbose logging...

10:53:09 DEBUG open(ZarrLocation(https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/labels))
10:53:09 DEBUG https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/labels
10:53:09 DEBUG Created legacy flat FSStore(https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/labels, r)
10:53:09 DEBUG https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/labels/.zarray
10:53:09 DEBUG https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/labels/.zgroup
10:53:10 WARNING version mismatch: detected:FormatV03, requested:FormatV01
10:53:10 DEBUG https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/labels
10:53:10 DEBUG Created nested FSStore(https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/labels, r, {'dimension_separator': '/', 'normalize_keys': True})
10:53:10 DEBUG https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/labels/.zarray
10:53:10 DEBUG https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/labels/.zgroup

but nothing after that...

TODO: try more versions...

@will-moore
Copy link
Member Author

With ome/ome-zarr-py#111 in ome-zarr-0.1.1 now I'm seeing...

napari==0.4.11
napari-ome-zarr==0.2.0
zarr==2.10.1
ome-zarr-0.1.1

$ napari https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr -vvv
12:00:23 DEBUG https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr/2/0.1.0.0.0
Traceback (most recent call last):
  File "/opt/anaconda3/envs/ome_ngff/bin/napari", line 8, in <module>
    sys.exit(main())
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/__main__.py", line 424, in main
    _run()
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/__main__.py", line 308, in _run
    viewer = view_path(  # noqa: F841
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/view_layers.py", line 169, in view_path
    return _make_viewer_then('open', args, kwargs)
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/view_layers.py", line 119, in _make_viewer_then
    method(*args, **kwargs)
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/components/viewer_model.py", line 914, in open
    self._add_layers_with_plugins(
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/components/viewer_model.py", line 987, in _add_layers_with_plugins
    added.extend(self._add_layer_from_data(*_data))
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/components/viewer_model.py", line 1064, in _add_layer_from_data
    raise exc
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/components/viewer_model.py", line 1061, in _add_layer_from_data
    layer = add_method(data, **(meta or {}))
  File "<string>", line 4, in add_labels
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/layers/labels/labels.py", line 243, in __init__
    data = self._ensure_int_labels(data)
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/layers/labels/labels.py", line 534, in _ensure_int_labels
    raise TypeError(
TypeError: Only integer types are supported for Labels layers, but data contains float64.

@will-moore will-moore changed the title Labels v0.3 investigation Open labels in https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr Oct 11, 2021
@will-moore
Copy link
Member Author

will-moore commented Oct 11, 2021

Tried to convert 'float' data with this diff:

$ git diff
diff --git a/napari_ome_zarr/_reader.py b/napari_ome_zarr/_reader.py
index c7fdc48..09d306c 100644
--- a/napari_ome_zarr/_reader.py
+++ b/napari_ome_zarr/_reader.py
@@ -9,6 +9,7 @@ import warnings
 from typing import Any, Callable, Dict, Iterator, List, Optional
 
 from vispy.color import Colormap
+import numpy as np
 
 from ome_zarr.data import CHANNEL_DIMENSION
 from ome_zarr.io import parse_url
@@ -101,6 +102,12 @@ def transform(nodes: Iterator[Node]) -> Optional[ReaderFunction]:
                     for x in METADATA_KEYS:
                         if x in node.metadata:
                             metadata[x] = node.metadata[x]
+                    # need to ensure dtype is integer not float
+                    print("DTYPE", data[0].dtype.str, data[0].itemsize)
+                    if data[0].itemsize == 8 or 'f' in data[0].dtype.str:
+                        # convert to something napari can handle
+                        data = [data[0].astype(np.dtype('i4'))]
+                        print('data', data[0])
                 else:
                     channel_axis = None
                     if "axes" in node.metadata:

But that crashes (and even causes Python to crash):

$ napari https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr
/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/napari/_qt/__init__.py:54: UserWarning: 

napari was tested with QT library `>=5.12.3`.
The version installed is 5.9.7. Please report any issues with
this specific QT version at https://github.com/Napari/napari/issues.
  warn(message=warn_message)
12:36:45 WARNING version mismatch: detected:FormatV01, requested:FormatV03
12:36:46 WARNING version mismatch: detected:FormatV03, requested:FormatV01
12:36:47 WARNING version mismatch: detected:FormatV01, requested:FormatV03
12:36:48 WARNING version mismatch: detected:FormatV03, requested:FormatV01
DTYPE <i8 8
data dask.array<astype, shape=(1, 1, 257, 210, 253), dtype=int32, chunksize=(1, 1, 33, 53, 64), chunktype=numpy.ndarray>
WARNING: Traceback (most recent call last):
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/vispy/app/backends/_qt.py", line 897, in paintGL
    self._vispy_canvas.events.draw(region=None)
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/vispy/util/event.py", line 451, in __call__
    raise RuntimeError('EventEmitter loop detected!')
RuntimeError: EventEmitter loop detected!
12:36:50 WARNING Traceback (most recent call last):
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/vispy/app/backends/_qt.py", line 897, in paintGL
    self._vispy_canvas.events.draw(region=None)
  File "/opt/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/vispy/util/event.py", line 451, in __call__
    raise RuntimeError('EventEmitter loop detected!')
RuntimeError: EventEmitter loop detected!
Abort trap: 6
(ome_ngff) LS30778:napari-ome-zarr wmoore$ /opt/anaconda3/envs/ome_ngff/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

@psobolewskiPhD
Copy link
Contributor

This is still not working:
napari https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr
ome-zarr: 0.9.0
napari: 0.5.0
napari-ome-zarr: 0.6.1

╰─ napari https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr(napari-050) ─╯
Traceback (most recent call last):
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/_qt/qt_viewer.py", line 986, in _qt_open
    self.viewer.open(
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/components/viewer_model.py", line 1215, in open
    layers = self._open_or_raise_error(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/components/viewer_model.py", line 1335, in _open_or_raise_error
    raise MultipleReaderError(
napari.errors.reader_errors.MultipleReaderError: Multiple plugins found capable of reading https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr. Select plugin from {'napari': 'napari builtins', 'napari-ome-zarr': 'napari-ome-zarr'} and pass to reading function e.g. `viewer.open(..., plugin=...)`.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/bin/napari", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/__main__.py", line 584, in main
    _run()
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/__main__.py", line 348, in _run
    viewer._window._qt_viewer._qt_open(
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/_qt/qt_viewer.py", line 1004, in _qt_open
    handle_gui_reading(filenames, self, stack, **kwargs)
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/_qt/dialogs/qt_reader_dialog.py", line 201, in handle_gui_reading
    open_with_dialog_choices(
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/_qt/dialogs/qt_reader_dialog.py", line 294, in open_with_dialog_choices
    qt_viewer.viewer.open(paths, stack=stack, plugin=plugin_name, **kwargs)
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/components/viewer_model.py", line 1205, in open
    self._add_layers_with_plugins(
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/components/viewer_model.py", line 1405, in _add_layers_with_plugins
    layer_data, hookimpl = read_data_with_plugins(
                           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/plugins/io.py", line 78, in read_data_with_plugins
    res = _npe2.read(paths, plugin, stack=stack)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/napari/plugins/_npe2.py", line 57, in read
    layer_data, reader = io_utils.read_get_reader(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/npe2/io_utils.py", line 66, in read_get_reader
    return _read(
           ^^^^^^
  File "/Users/piotrsobolewski/Dev/miniforge3/envs/napari-050/lib/python3.12/site-packages/npe2/io_utils.py", line 176, in _read
    raise ValueError(
ValueError: Reader 'napari-ome-zarr' was selected to open ['https://s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001247.zarr'], but returned no data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants