napari-clusters-plotter icon indicating copy to clipboard operation
napari-clusters-plotter copied to clipboard

bug - Manual_Cluster_ID can go missing with feature as color and Surface Data

Open Cryaaa opened this issue 7 months ago • 3 comments

This probably is somewhat of an edgecase but I found that if you:

  1. use the cluster plotter and select a feature to color the plot,
  2. then delete the layers for which the plot was made
  3. load Surface data with new features

This causes the "Manual_Cluster_ID" column to go missing from the dropdown and you cannot manually annotate labels again until you close and reopen the plotter -> the Reset button does not fix this. I guess this has something to do with the fact that for surface data we have to hard code the features instead of loading them with the viewer.add_surface() function. I guess there is some kind of event that is being skipped because of this

Cryaaa avatar Apr 14 '25 13:04 Cryaaa

Hi @Cryaaa woah, good catch! Your hypothesis is probably on point - surface_layer.features is currently only tolerated but not really supported. In other words, viewer.add_surface(surface, features=...) won't complain if it receives features and will put them into the layer.features but it probably also doesn't hook up other functionality such as events.

Maybe we could add a little extra statement in the reset button that inserts the MANUAL_CLUSTER_ID if it's not present?

Edit: Just did a little digging and I think from the napari side it's fine as this is now fully supported. Will check!

Edit2: Maaayyybe the underlying problem here is that the clusters-plotter doesn't clean up behind itself properly in case every layer is removed from the viewer. I can reproduce the problem with any sequence like this:

  1. Use clusters-plotter on layer A
  2. close layer A (but not the plotter
  3. open new layer B --> coloring messed up

jo-mueller avatar Apr 14 '25 19:04 jo-mueller

Edit2: Maaayyybe the underlying problem here is that the clusters-plotter doesn't clean up behind itself properly in case every layer is removed from the viewer. I can reproduce the problem with any sequence like this:

  1. Use clusters-plotter on layer A
  2. close layer A (but not the plotter
  3. open new layer B --> coloring messed up

Actually for me it works fine if the new layer that is added is a points or labels layer. It just snaps back to what it was if reopening the layer or resets when adding a new layer type. For me it's just the surface layer which messes up.

Maybe we could add a little extra statement in the reset button that inserts the MANUAL_CLUSTER_ID if it's not present?

I think this would definitely be the best approach because it was also my first instinct to use it when realizing the bug so I guess other users might use it similarly

Cryaaa avatar Apr 15 '25 08:04 Cryaaa

I was able to identify a bunch of related issues. For instance, if you

  • add some layers
  • do some clustering
  • delete the layers
  • click reset
  • Segfault 😞

#379 should fix it a bit more globally 👍

jo-mueller avatar Apr 15 '25 08:04 jo-mueller