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

Labels layers don't load with napari 0.5.0 (dev) #109

Closed
psobolewskiPhD opened this issue Jun 6, 2024 · 10 comments · Fixed by napari/napari#7061
Closed

Labels layers don't load with napari 0.5.0 (dev) #109

psobolewskiPhD opened this issue Jun 6, 2024 · 10 comments · Fixed by napari/napari#7061

Comments

@psobolewskiPhD
Copy link
Contributor

psobolewskiPhD commented Jun 6, 2024

In 0.4.19 there were a number of deprecations to labels kwargs:
napari/napari#6542
In 0.5.0 they are removed:
napari/napari#6641

This results in a traceback when trying to load ome zarr with labels, e.g.
NAPARI_ASYNC=1 napari https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0001A/2551.zarr/A/1/0
validator: https://ome.github.io/ome-ngff-validator/?source=https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0001A/2551.zarr/A/1/0/

Traceback (most recent call last):
  File "/Users/sobolp/Documents/dev/napari/napari/components/viewer_model.py", line 1474, in _add_layer_from_data
    layer = add_method(data, **(meta or {}))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: add_labels() got an unexpected keyword argument 'color'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/sobolp/Documents/dev/napari/napari/components/viewer_model.py", line 1283, in _open_or_raise_error
    added = self._add_layers_with_plugins(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolp/Documents/dev/napari/napari/components/viewer_model.py", line 1401, in _add_layers_with_plugins
    added.extend(self._add_layer_from_data(*_data))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolp/Documents/dev/napari/napari/components/viewer_model.py", line 1479, in _add_layer_from_data
    raise TypeError(
TypeError: _add_layer_from_data received an unexpected keyword argument ('color') for layer type labels

Env details:
napari 0.5.0 from main 5c1e7281bbc11878a748add1006f7211473be16b
0.5.2 of this plugin
0.8.3 of ome-zarr
python 3.11.7
macOS arm64

@psobolewskiPhD
Copy link
Contributor Author

CC @jni

@jni
Copy link
Contributor

jni commented Jun 7, 2024

Well, shit. I forgot and broke my rule that kwargs to our API should never need to be exotic objects. 🤦 This means that plugins have to import from napari if they want to give us this information, which imho is a big no-no.

My suggested fix is:

  • on the napari-ome-zarr end, we return colormap=<dict of label:color>
  • on the napari end, we add a convenience validator so that if the input is a dictionary, we internally wrap it in a DirectColormap, and if the input is a list, we internally wrap it in a CyclicLabelColormap.

Additionally, we should probably (a) make a new release of napari-ome-zarr that pins napari<=0.4.19, and then when we update as above we make another release that requires napari>=0.4.19.

What do you think @psobolewskiPhD?

@psobolewskiPhD
Copy link
Contributor Author

@jni I think a convenience in napari is the way to go for 0.5.0. I happened to find it here, but how many other plugins could return a labels layer? Do we want all of them to make pins?

@jni
Copy link
Contributor

jni commented Jun 7, 2024

Note that plugins will break — it's just that the fix will be less painful.

@jni
Copy link
Contributor

jni commented Jun 24, 2024

Another note: the only plugins that will break are those that specify colors for the labels — I expect those are in the minority. But, the fix will be pretty easy — colors -> colormap in the LayerDataTuple, and this will work with both 0.4.19 and 0.5.0+.

@jni
Copy link
Contributor

jni commented Jun 24, 2024

See napari/napari#7025 for the proposed fix.

jni added a commit to jni/napari that referenced this issue Jul 4, 2024
While trying to fix ome/napari-ome-zarr#109 on the ome side after napari#7025,
I found that I was still getting errors — now by the color_dict
validator, which requires a None key or a defaultdict. Ultimately,
I think this is a quirky interface that I don't want to impose on
ome-zarr or their readers. Therefore, I've changed the ValueError to a
warning. I'd consider removing the warning altogether but I think
@Czaki was opposed?
@jni
Copy link
Contributor

jni commented Jul 6, 2024

@psobolewskiPhD probably you didn't mean for this to auto-close with my commit? 😅

@psobolewskiPhD
Copy link
Contributor Author

Um, no idea how I could close this sorry.

@psobolewskiPhD psobolewskiPhD reopened this Jul 6, 2024
@jni
Copy link
Contributor

jni commented Jul 6, 2024

Based on the message above, it looks like my commit message had the phrase "while trying to fix [this issue]", and when you pushed to your own fork, GitHub fixated on "fix [this issue]" in your commit and was like, great, he fixed it! 😂

@psobolewskiPhD
Copy link
Contributor Author

This was fixed by #112

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