What would cause a StopIteration on napari

Was trying to show napari to a coworker in addition to napari-aicsimageio and certain image formats load just fine while others result in a StopIteration error.

(napari-test) maxfield@maxfield-ubuntu:~/active/cell$ napari aicsimageio/aicsimageio/tests/resources/s_1_t_4_c_2_z_1.lif 
Reader will load image in-memory: False
Traceback (most recent call last):
  File "/home/maxfield/miniconda3/envs/napari-test/bin/napari", line 8, in <module>
    sys.exit(main())
  File "/home/maxfield/miniconda3/envs/napari-test/lib/python3.8/site-packages/napari/__main__.py", line 166, in main
    view_path(
  File "/home/maxfield/miniconda3/envs/napari-test/lib/python3.8/site-packages/napari/view_layers.py", line 207, in view_path
    viewer.open(
  File "/home/maxfield/miniconda3/envs/napari-test/lib/python3.8/site-packages/napari/components/add_layers_mixin.py", line 858, in open
    self._add_layers_with_plugins(
  File "/home/maxfield/miniconda3/envs/napari-test/lib/python3.8/site-packages/napari/components/add_layers_mixin.py", line 925, in _add_layers_with_plugins
    new = self._add_layer_from_data(*_data)
  File "/home/maxfield/miniconda3/envs/napari-test/lib/python3.8/site-packages/napari/components/add_layers_mixin.py", line 997, in _add_layer_from_data
    layer = add_method(data, **(meta or {}))
  File "/home/maxfield/miniconda3/envs/napari-test/lib/python3.8/site-packages/napari/components/add_layers_mixin.py", line 268, in add_image
    i_kwargs = {k: next(v) for k, v in kwargs.items()}
  File "/home/maxfield/miniconda3/envs/napari-test/lib/python3.8/site-packages/napari/components/add_layers_mixin.py", line 268, in <dictcomp>
    i_kwargs = {k: next(v) for k, v in kwargs.items()}
StopIteration

From the log I know that napari-aicsimageio is indeed being used for image reading (“Reader will load image in-memory: False”), and so I find it odd that different image formats result in success or failure considering the path that napari-aicsimageio takes is the same regardless of format. Any ideas? @sofroniewn @talley @jni

hey @JacksonMaxfield,
looks like that StopIteration error will be thrown if the channel_axis argument is used, but one of the other keyword arguments is unsuccessfully “iterated” (that’s definitely an error that should be caught and presented to you in a more interpretable form!).

From your code, it looks like it must be either the visible, or the name key in the meta dict that you return here … but it’s hard to say exactly why at the moment. Can you either send me the file? or put some print/logging statements in your plugin to show the contents of that meta dict when you get the error?

2 Likes

Hey! Interesting… Here is a link to the exact file that failed above: https://open.quiltdata.com/b/aics-modeling-packages-test-resources/tree/aicsimageio/test_resources/resources/s_1_t_4_c_2_z_1.lif

I will try to debug this later this week too. Thanks for the insight.

ok, looks like the channel_axis argument was off-by-one for some reason for that file. channel_axis was set to “3” … but the data shape was (1, 4, 2, 614, 614) … so it was trying to load 614 different channels. But when it got to the name argument, there were only 2 names, so you get the StopIteration error when it tries to get the name for the (non-existent) 3rd channel.

1 Like

I opened napari/napari/#1381 which would provide a more interpretable error message in this case

2 Likes

Ahhhh thanks for finding that. I think I have an idea as to what could be happening so will test some stuff out and hopefully patch it soon. Thanks for the help and that PR would make debugging this stuff much easier so thanks for doing that as well.

2 Likes