Skip to content

[BUG] Deleting a track layer in the layer list prevents new projects from being loaded #217

Description

@IgorTatarnikov

Describe the bug
If a track layer is deleted using the layer list the plugin throws an error when opening a new project.

To Reproduce
Load a project in atlas space (with an existing track), delete the track in the layer list, try to load a new project.

Expected behaviour
The project should be loaded.

Computer used (please complete the following information):

  • OS: Linux
  • Version 24.04
Traceback
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/miniforge3/envs/brainglobe-test/lib/python3.12/site-packages/brainglobe_segmentation/segment.py:287, in SegmentationWidget.load_brainreg_directory_atlas_space(self=<brainglobe_segmentation.segment.SegmentationWidget object>)
    286 def load_brainreg_directory_atlas_space(self):
--> 287     self.get_brainreg_directory(atlas_space=True)
        self = <brainglobe_segmentation.segment.SegmentationWidget object at 0x15caabc80>
File ~/miniforge3/envs/brainglobe-test/lib/python3.12/site-packages/brainglobe_segmentation/segment.py:311, in SegmentationWidget.get_brainreg_directory(self=<brainglobe_segmentation.segment.SegmentationWidget object>, atlas_space=True)
    308     return
    310 if self.directory != brainreg_directory:
--> 311     status = self.remove_layers()
        self = <brainglobe_segmentation.segment.SegmentationWidget object at 0x15caabc80>    312     if not status:
    313         return  # Something prevented deletion

File ~/miniforge3/envs/brainglobe-test/lib/python3.12/site-packages/brainglobe_segmentation/segment.py:470, in SegmentationWidget.remove_layers(self=<brainglobe_segmentation.segment.SegmentationWidget object>)
    468 # Remove old layers
    469 for layer in all_layers:
--> 470     self.viewer.layers.remove(layer)
        layer = <Points layer 'track_0' at 0x15e7f92e0>
        self = <brainglobe_segmentation.segment.SegmentationWidget object at 0x15caabc80>
        self.viewer.layers = [<Image layer '2 (downsampled)' at 0x168f1a3f0>, <Image layer 'Registered image' at 0x168ca0770>, <Labels layer 'allen_mouse_10um' at 0x16e8a9430>, <Points layer 'track_1' at 0x15d811730>, <Points layer 'track_2' at 0x168ec6fc0>]
        self.viewer = Viewer(camera=Camera(center=(0.0, np.float64(399.5), np.float64(569.5)), zoom=np.float64(0.7683333333333333), angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True, orientation=(<DepthAxisOrientation.TOWARDS: 'towards'>, <VerticalAxisOrientation.DOWN: 'down'>, <HorizontalAxisOrientation.RIGHT: 'right'>)), cursor=Cursor(position=(np.float64(720.0), np.float64(201.6692101947378), np.float64(1162.992435200699)), scaled=True, style=<CursorStyle.STANDARD: 'standard'>, size=np.float64(10.0)), dims=Dims(ndim=3, ndisplay=2, order=(0, 1, 2), axis_labels=('0', '1', '2'), rollable=(True, True, True), range=(RangeTuple(start=np.float64(0.0), stop=np.float64(1319.0), step=np.float64(1.0)), RangeTuple(start=np.float64(0.0), stop=np.float64(799.0), step=np.float64(1.0)), RangeTuple(start=np.float64(0.0), stop=np.float64(1139.0), step=np.float64(1.0))), margin_left=(0.0, 0.0, 0.0), margin_right=(0.0, 0.0, 0.0), point=(np.float64(720.0), np.float64(399.0), np.float64(569.0)), last_used=0), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False, spacing=0.0), layers=[<Image layer '2 (downsampled)' at 0x168f1a3f0>, <Image layer 'Registered image' at 0x168ca0770>, <Labels layer 'allen_mouse_10um' at 0x16e8a9430>, <Points layer 'track_1' at 0x15d811730>, <Points layer 'track_2' at 0x168ec6fc0>], help='use <7> for transform, use <1> for activate the label eraser, use <2> for activate the paint brush, use <3> for activate the polygon tool, use <4> for activate the fill bucket, use <5> for pick mode', status='', tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=False, mouse_move_callbacks=[<function SegmentationWidget.__init__.<locals>.display_region_info at 0x142cd0720>], mouse_drag_callbacks=[], mouse_double_click_callbacks=[<function double_click_to_zoom at 0x126986200>], mouse_wheel_callbacks=[<function dims_scroll at 0x126986160>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, _keymap={})    471     self.track_layers = []
    472     self.label_layers = []

File <frozen _collections_abc>:1165, in remove(self=[<Image layer '2 (downsampled)' at 0x168f1a3f0>,...811730>, <Points layer 'track_2' at 0x168ec6fc0>], value=<Points layer 'track_0'>)

File ~/miniforge3/envs/brainglobe-test/lib/python3.12/site-packages/napari/utils/events/containers/_typed.py:232, in TypedMutableSequence.index(self=[<Image layer '2 (downsampled)' at 0x168f1a3f0>,...811730>, <Points layer 'track_2' at 0x168ec6fc0>], value=<Points layer 'track_0'>, start=0, stop=None)
    229     if v is value or v == value:
    230         return i
--> 232 raise ValueError(
        trans = <napari.utils.translations.TranslationBundle object at 0x1069f0c20>
        value = <Points layer 'track_0' at 0x15e7f92e0>    233     trans._(
    234         '{value!r} is not in list',
    235         deferred=True,
    236         value=value,
    237     )
    238 )

ValueError: <Points layer 'track_0' at 0x15e7f92e0> is not in list

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions