Skip to content

Support visualizing multiple SpatialData objects #112

Closed

Description

@LucaMarconato

Works on the spatialdata branch, needs to be ported in main.

Activity

  1. kevinyamauchi commented on Jun 9, 2023

    @kevinyamauchi
    Collaborator

    @melonora , would you be able to take this one? @LucaMarconato has some demo code already on the spatialdata branch. @LucaMarconato , can please link the code?

  2. LucaMarconato commented on Jun 9, 2023

    @LucaMarconato
    MemberAuthor
  3. melonora commented on Jun 9, 2023

    @melonora
    Collaborator

    I have this also in follow up PRs which I did not open yet. I keep track of the spatialdata object in the layer metadata, similar to what Luca did on the spatialdata branch.

  4. melonora commented on Jun 9, 2023

    @melonora
    Collaborator

    I can open them, but they are branched from the layer_visibility branch so that was why I was waiting a bit.

  5. melonora commented on Jul 4, 2023

    @melonora
    Collaborator

    @kevinyamauchi @LucaMarconato After #120, I will add the possibility of having multiple spatialdata objects being visualized in one napari-spatialdata instance. This requires a few changes overall. This serves as an initial proposal.

    Proposal

    There are several ways by which a user could load multiple SpatialData objects.

    1. Interactive(sdatas: list[SpatialData])
    2. SpatialDataViewer.add_sdata(sdata: SpatialData)
    3. Drag and drop interaction.

    I believe the SpatialData objects ultimately can live as an EventedSet in SdataWidget. This allows us to create callbacks upon add, remove and discard
    events among others. Currently other emitted events wouldn't be important I think.

    Populating CoordinateSystemWidget and ElementWidget

    In the SdataWidget initialization, the CoordinateSystemWidget and ElementWidget are both created. The widgets do not hold a reference to the SdataWidget, but callbacks can be created in the respective widgets and connected to the event in the SdataWidget. The respective callbacks would take care of populating the items of the widgets also when later adding or removing new data.

    class SdataWidget(...):
        self._sdatas = EventedSet(sdatas)
        self.coordinate_system_widget = CoordinateSystemWidget(self._sdatas)
        self.elements_widget = ElementWidget(self._sdatas)
        
        self._sdatas.events.add.connect(self.coordinate_system_widget._add_items)
        ...
        
    class CoordinateSystemWidget(QListWidget):
        def __init__(self, sdatas: EventedSet(SpatialData)):
            super().__init__()
    
            self._sdatas = sdatas
            self._init_items(self._sdatas)
    
        def _init_items(sdatas: EventedSet):
            """initial populating of widget items"""
    
       def _add_items(event):
           ...
    
    class ElementWidget(QListWidget)
           ...

    Of note is that elements of multiple spatialdata objects can have the same name. We would have to choose to either disallow it, be ok with napari showing "copied" names (integer between parentheses) or come up with an appropriate suffix. Dependent on choice there would be additional functionality of the callbacks in this section. Personally, I think the latter would have preference.

    What do you think?

  6. LucaMarconato commented on Jul 4, 2023

    @LucaMarconato
    MemberAuthor

    Thanks Wouter, I prefer 1. since it was what we used so far, but we could also allow the user to use add_sdata() later (this is actually what happens in the spatialdata branch: there is an equivalent private function that allows for that).

    Drag and drops interactions would be also nice, but we can add it later.

    Re the multiple names I would prefer having napari automatically handle it so that we don't have to add extra suffix logic.

  7. melonora commented on Jul 5, 2023

    @melonora
    Collaborator

    I would say both option 1 and 2 are very doable, as initially the only thing that happens when adding a SpatialData object should be populating the CoordinateSystemWidget and the ElementWidget. This can be done by just adding items.

    Regarding the names I think it would be nice to modify the copy names of the layer in such a way that it at least indicates which layers share the SpatialData object, but I would have to find out first what would be the best way to achieve that.

  8. melonora commented on Sep 1, 2023

    @melonora
    Collaborator

    closed by #136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions