napari-spatialdata icon indicating copy to clipboard operation
napari-spatialdata copied to clipboard

Barebone annotate

Open melonora opened this issue 1 year ago • 4 comments

This PR serves to provide a barebone annotation widget. At the moment only shape annotations are supported but I am to extend this to points and perhaps labels as well. Furthermore, at a later stage also a table widget will be provided.

Currently, the user can annotate using and also reload shape annotations. The description column at the moment serves no purpose but this will come with the table widget.

@LucaMarconato maybe before putting this in we need to discuss a little bit about UI experience.

melonora avatar Apr 09 '24 11:04 melonora

Some comments from the call:

  • [x] I would add the shortcut "CMD+L" in the hover tooltip of "Link layer to sdata"
  • [x] There seem to be some bugs on macOS that can't be reproduced on Ubuntu (I can't debug with PyCharm due to this bug https://github.com/napari/napari/issues/6789; I'll try to get past this). I will report the bugs once I fix this. But these seems to be bugs:
    • [x] radio button of the annotation groups hidden
    • [x] the color of the shapes being drawn don't change when the radio buttons are selected (probably due to an index error when a new annotation group is being added)
  • [x] Bug with "Table annotating layer" not showing options in the combobox in the view widget
  • [x] (related) bug with points layers now showing correctly in the view widget
  • [x] In an annotation table empty strings are converted to NaN.
  • [x] Use case to cover: the user should be able to save an annotation to an spatial element correctly (correct matching) even when some classes are added or removed, or some elements are added or removed.
  • [x] In particular, these two edge cases should be considered:
    • [x] a class is added but the class is not annotating any element. In this case, I suggest to just ignore the class when saving to disk
    • [x] an element is not belonging to any class; saving should still work.

Still to do:

  • [ ] EDIT: not part of this PR, but please open an issue. When saving the annotation the user should be able to choose between saving the element, the annotations, or both. The default should be both, unless no layer is selected, then only the annotations.

LucaMarconato avatar Apr 30 '24 14:04 LucaMarconato

a class is added but the class is not annotating any element. In this case, I suggest to just ignore the class when saving to disk, this is already there. I checked again with the table widget btw, single molecule didn't show anything because it is the cell element that the table is annotating. Checked with cell and it properly shows.

melonora avatar May 01 '24 16:05 melonora

Regarding an element is not belonging to any class; saving should still work.

This works by setting the class to undefined.

melonora avatar May 02 '24 06:05 melonora

so the problem with the view widget is that when reopening the widget it doesn't properly load the information.

melonora avatar May 02 '24 07:05 melonora

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Open points from the test together (these are all mac specific):

  • [x] bug with lasso (to replicate: open the annotation widgret, create a shapes layer, rename it, then use the lasso). If the layer is linked, the lasso works again.
  • [x] (tiny) after modifying the class text it feels natural to use to clear focus
  • [x] general bug with radio selection and colors
  • [x] color selection (with the color widget) doesn't update the colors in the "layer controls" widget
  • [x] works on Wouter's Mac but not on Luca's one: switching between layers doesn't update the list of classes.

Non mac specific

  • [x] luca: ~merge~checkout incremental io and test the saving

LucaMarconato avatar May 28 '24 14:05 LucaMarconato

Small comment:

  • [x] please document the code inside on_mouse_move() in _view.py.

LucaMarconato avatar May 30 '24 12:05 LucaMarconato

Bug:

  • [x] _on_inserted() is not called when a shapes layer is created before opening the annotation widget. A consequence of this is that, after setting the annotation on shape and after deselecting the shape, hovering the mouse on the shape will not show the text that has been saved. This because the callback for on_mouse_move() is set in _on_insterted(), which is never called.

LucaMarconato avatar May 30 '24 13:05 LucaMarconato

I tested the saving (on the incremental io branch). I found some bugs:

  • [x] when saving an element, the View widget is not updated. Workaround: from the element widget add the element, and delete it; now the View widget is updated an it works.
  • [x] The colors of the annotation widget do not correspond to the colors used for plotting, easy fix.
  • [ ] The "Annotation table" dropdown combobox does not update the color classes.

Saving and overwriting work!

LucaMarconato avatar May 30 '24 13:05 LucaMarconato

Bug that I probably introduced here (I was working on performance in order to avoid copies) https://github.com/scverse/napari-spatialdata/pull/239/files in _model.py:

  • [x] when trying to plot instance_key an error is raised. The user playing around with the annotation widget may encounter this bug because the table created has only a few columns, so it's likely to try to plot instance_id.

LucaMarconato avatar May 30 '24 13:05 LucaMarconato

I tested the saving (on the incremental io branch). I found some bugs:

  • [x] when saving an element, the View widget is not updated. Workaround: from the element widget add the element, and delete it; now the View widget is updated an it works.
  • [x] The colors of the annotation widget do not correspond to the colors used for plotting, easy fix.
  • [ ] The "Annotation table" dropdown combobox does not update the color classes.

Saving and overwriting work!

not certain what you mean with the last point

melonora avatar Jun 06 '24 20:06 melonora

tests pass locally, but here it would require a release of spatialdata with the incremental IO. For hackathon purposes merging now already.

melonora avatar Jun 10 '24 15:06 melonora

The "Annotation table" dropdown combobox does not update the color classes.

I will explain this in a new issue (done here: https://github.com/scverse/napari-spatialdata/issues/260), I have just verified and it is still open.

LucaMarconato avatar Jun 24 '24 14:06 LucaMarconato