napari / docs

Documentation for napari (other than API docs)
BSD 3-Clause "New" or "Revised" License
9 stars 37 forks source link

Rendering guide is broken (Key Error on viewer.close()) #436

Closed melissawm closed 4 days ago

melissawm commented 1 week ago

πŸ› Bug

The Rendering guide is currently broken, with the following output when running the last cell:

In [15]: viewer.close()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[15], line 1
----> 1 viewer.close()

File ~/micromamba/envs/napari-dev/lib/python3.11/site-packages/napari/viewer.py:144, in Viewer.close(self)
    142 self._layer_slicer.shutdown()
    143 # Remove all the layers from the viewer
--> 144 self.layers.clear()
    145 # Close the main window
    146 self.window.close()

File <frozen _collections_abc>:1084, in clear(self)

File <frozen _collections_abc>:1106, in pop(self, index)

File ~/micromamba/envs/napari-dev/lib/python3.11/site-packages/napari/utils/events/containers/_evented_list.py:193, in EventedList.__delitem__(self, key)
    191 item = parent._list.pop(index)
    192 self._process_delete_item(item)
--> 193 parent.events.removed(index=index, value=item)

File ~/micromamba/envs/napari-dev/lib/python3.11/site-packages/napari/utils/events/event.py:764, in EventEmitter.__call__(self, *args, **kwargs)
    761     self._block_counter.update([cb])
    762     continue
--> 764 self._invoke_callback(cb, event if pass_event else None)
    765 if event.blocked:
    766     break

File ~/micromamba/envs/napari-dev/lib/python3.11/site-packages/napari/utils/events/event.py:802, in EventEmitter._invoke_callback(self, cb, event)
    800     self.disconnect(cb)
    801     return
--> 802 _handle_exception(
    803     self.ignore_callback_errors,
    804     self.print_callback_errors,
    805     self,
    806     cb_event=(cb, event),
    807 )

File ~/micromamba/envs/napari-dev/lib/python3.11/site-packages/napari/utils/events/event.py:789, in EventEmitter._invoke_callback(self, cb, event)
    787 try:
    788     if event is not None:
--> 789         cb(event)
    790     else:
    791         cb()

File ~/micromamba/envs/napari-dev/lib/python3.11/site-packages/napari/_vispy/canvas.py:599, in VispyCanvas._remove_layer(self, event)
    597 del vispy_layer
    598 del self.layer_to_visual[layer]
--> 599 self._reorder_layers()

File ~/micromamba/envs/napari-dev/lib/python3.11/site-packages/napari/_vispy/canvas.py:606, in VispyCanvas._reorder_layers(self)
    603 first_visible_found = False
    605 for i, layer in enumerate(self.viewer.layers):
--> 606     vispy_layer = self.layer_to_visual[layer]
    607     vispy_layer.order = i
    609     # the bottommost visible layer needs special treatment for blending

KeyError: <Image layer 'mean_data' at 0x7f532730e9d0>

Environment

This is napari and napari/docs from main, and I tried executing the steps in the guide separately (not while building the docs) and got the same result.

melissawm commented 1 week ago

Also - should all links pointing to the deleted rendering-explanation document now link to rendering?

psobolewskiPhD commented 1 week ago

Odd that the CircleCI previews built. and napari.org/dev seems ok?

melissawm commented 1 week ago

Let's see what happens here: https://github.com/napari/docs/actions/runs/9718326742/job/26825951263?pr=437

EDIT: Oh no, it looks like something local? Maybe some dependency, and the CI is using the constraints??

There it is: https://github.com/napari/docs/actions/runs/9718326742/job/26825951263?pr=437#step:9:884

melissawm commented 1 week ago

napari.org/dev seems ok?

That's because the error is in the notebook's last cell, and this cell is not shown in the notebook so the output looks ok. But if you run the commands on that page you should be able to reproduce

andy-sweet commented 4 days ago

I'm taking a look at the error.

andy-sweet commented 4 days ago

Error is caused by the following line

viewer.layers[0] = Image(mean_data, colormap=viewer.layers[0].colormap)

That doesn't error itself, but directly replacing a layer means that the corresponding vispy layer is never created (among other things). Not sure if napari is supposed to support this in-place mutation, but it's easy to change the doc example to work by adding the mean image layer instead.

andy-sweet commented 4 days ago

Fix in #441