From b05cd655c74042ff73d409b1b18cc111d98d1f2a Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Fri, 27 Oct 2023 16:26:15 +0100 Subject: [PATCH 1/3] Migrate to npe2 --- brainreg_segment/napari.yaml | 11 +++++++++++ brainreg_segment/plugins.py | 10 ---------- pyproject.toml | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 brainreg_segment/napari.yaml delete mode 100644 brainreg_segment/plugins.py diff --git a/brainreg_segment/napari.yaml b/brainreg_segment/napari.yaml new file mode 100644 index 0000000..39881e6 --- /dev/null +++ b/brainreg_segment/napari.yaml @@ -0,0 +1,11 @@ +name: brainreg-segment +schema_version: 0.1.0 +contributions: + commands: + - id: brainreg-segment.SegmentationWidget + title: Open segmentation widget + python_name: brainreg_segment.segment:SegmentationWidget + + widgets: + - command: brainreg-segment.SegmentationWidget + display_name: Region/track segmentation \ No newline at end of file diff --git a/brainreg_segment/plugins.py b/brainreg_segment/plugins.py deleted file mode 100644 index 6458b49..0000000 --- a/brainreg_segment/plugins.py +++ /dev/null @@ -1,10 +0,0 @@ -from napari_plugin_engine import napari_hook_implementation - -from brainreg_segment.segment import SegmentationWidget - - -@napari_hook_implementation -def napari_experimental_provide_dock_widget(): - return [ - (SegmentationWidget, {"name": "Region/track segmentation"}), - ] diff --git a/pyproject.toml b/pyproject.toml index 9733353..d39322e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,8 @@ dev = [ "napari-time-slicer" # to test non ndarray-types ] +[project.entry-points."napari.manifest"] +cellfinder-napari = "brainreg_segment:napari.yaml" [project.scripts] brainreg-segment = "brainreg_segment.segment:main" From 116cfac0d86a77c80caf0ee42041d716b0c5e384 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Fri, 27 Oct 2023 16:46:44 +0100 Subject: [PATCH 2/3] Update brainglobe-napari-io dependency --- pyproject.toml | 2 +- .../regions/summary.csv | 0 .../regions/test_region.csv | 0 .../regions/test_region.obj | 0 .../regions/test_region.tiff | Bin .../tracks/test_track.csv | 0 .../tracks/test_track.npy | Bin .../tracks/test_track.points | Bin 8 files changed, 1 insertion(+), 1 deletion(-) rename tests/data/brainreg_output/manual_segmentation/{standard_space => atlas_space}/regions/summary.csv (100%) rename tests/data/brainreg_output/manual_segmentation/{standard_space => atlas_space}/regions/test_region.csv (100%) rename tests/data/brainreg_output/manual_segmentation/{standard_space => atlas_space}/regions/test_region.obj (100%) rename tests/data/brainreg_output/manual_segmentation/{standard_space => atlas_space}/regions/test_region.tiff (100%) rename tests/data/brainreg_output/manual_segmentation/{standard_space => atlas_space}/tracks/test_track.csv (100%) rename tests/data/brainreg_output/manual_segmentation/{standard_space => atlas_space}/tracks/test_track.npy (100%) rename tests/data/brainreg_output/manual_segmentation/{standard_space => atlas_space}/tracks/test_track.points (100%) diff --git a/pyproject.toml b/pyproject.toml index d39322e..6778525 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ ] requires-python = ">=3.7" dependencies = [ - "brainglobe-napari-io", + "brainglobe-napari-io >= 0.3.0", "dask >= 2.15.0", "imio", "brainglobe-utils", diff --git a/tests/data/brainreg_output/manual_segmentation/standard_space/regions/summary.csv b/tests/data/brainreg_output/manual_segmentation/atlas_space/regions/summary.csv similarity index 100% rename from tests/data/brainreg_output/manual_segmentation/standard_space/regions/summary.csv rename to tests/data/brainreg_output/manual_segmentation/atlas_space/regions/summary.csv diff --git a/tests/data/brainreg_output/manual_segmentation/standard_space/regions/test_region.csv b/tests/data/brainreg_output/manual_segmentation/atlas_space/regions/test_region.csv similarity index 100% rename from tests/data/brainreg_output/manual_segmentation/standard_space/regions/test_region.csv rename to tests/data/brainreg_output/manual_segmentation/atlas_space/regions/test_region.csv diff --git a/tests/data/brainreg_output/manual_segmentation/standard_space/regions/test_region.obj b/tests/data/brainreg_output/manual_segmentation/atlas_space/regions/test_region.obj similarity index 100% rename from tests/data/brainreg_output/manual_segmentation/standard_space/regions/test_region.obj rename to tests/data/brainreg_output/manual_segmentation/atlas_space/regions/test_region.obj diff --git a/tests/data/brainreg_output/manual_segmentation/standard_space/regions/test_region.tiff b/tests/data/brainreg_output/manual_segmentation/atlas_space/regions/test_region.tiff similarity index 100% rename from tests/data/brainreg_output/manual_segmentation/standard_space/regions/test_region.tiff rename to tests/data/brainreg_output/manual_segmentation/atlas_space/regions/test_region.tiff diff --git a/tests/data/brainreg_output/manual_segmentation/standard_space/tracks/test_track.csv b/tests/data/brainreg_output/manual_segmentation/atlas_space/tracks/test_track.csv similarity index 100% rename from tests/data/brainreg_output/manual_segmentation/standard_space/tracks/test_track.csv rename to tests/data/brainreg_output/manual_segmentation/atlas_space/tracks/test_track.csv diff --git a/tests/data/brainreg_output/manual_segmentation/standard_space/tracks/test_track.npy b/tests/data/brainreg_output/manual_segmentation/atlas_space/tracks/test_track.npy similarity index 100% rename from tests/data/brainreg_output/manual_segmentation/standard_space/tracks/test_track.npy rename to tests/data/brainreg_output/manual_segmentation/atlas_space/tracks/test_track.npy diff --git a/tests/data/brainreg_output/manual_segmentation/standard_space/tracks/test_track.points b/tests/data/brainreg_output/manual_segmentation/atlas_space/tracks/test_track.points similarity index 100% rename from tests/data/brainreg_output/manual_segmentation/standard_space/tracks/test_track.points rename to tests/data/brainreg_output/manual_segmentation/atlas_space/tracks/test_track.points From b6854815b4614c708e780ed1ed3c9bf24cf6d5a7 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Fri, 27 Oct 2023 16:48:18 +0100 Subject: [PATCH 3/3] Standardise use of atlas space --- brainreg_segment/napari.yaml | 2 +- brainreg_segment/paths.py | 13 ++----- brainreg_segment/segment.py | 36 +++++++++---------- tests/conftest.py | 4 +-- .../test_integration/test_gui/test_gui.py | 30 ++++++++-------- .../test_gui/test_region_ui_functionality.py | 4 +-- .../test_gui/test_track_ui_functionality.py | 4 +-- 7 files changed, 41 insertions(+), 52 deletions(-) diff --git a/brainreg_segment/napari.yaml b/brainreg_segment/napari.yaml index 39881e6..82d20ff 100644 --- a/brainreg_segment/napari.yaml +++ b/brainreg_segment/napari.yaml @@ -8,4 +8,4 @@ contributions: widgets: - command: brainreg-segment.SegmentationWidget - display_name: Region/track segmentation \ No newline at end of file + display_name: Region/track segmentation diff --git a/brainreg_segment/paths.py b/brainreg_segment/paths.py index fff5021..f73ead0 100644 --- a/brainreg_segment/paths.py +++ b/brainreg_segment/paths.py @@ -3,23 +3,14 @@ class Paths: A single class to hold all file paths that may be used. """ - def __init__( - self, brainreg_directory, standard_space=True, atlas_space=False - ): + def __init__(self, brainreg_directory, atlas_space=False): self.brainreg_directory = brainreg_directory self.main_directory = self.brainreg_directory / "manual_segmentation" if atlas_space: self.segmentation_directory = self.main_directory / "atlas_space" else: - if standard_space: - self.segmentation_directory = ( - self.main_directory / "standard_space" - ) - else: - self.segmentation_directory = ( - self.main_directory / "sample_space" - ) + self.segmentation_directory = self.main_directory / "sample_space" self.regions_directory = self.join_seg_files("regions") self.region_summary_csv = self.regions_directory / "summary.csv" diff --git a/brainreg_segment/segment.py b/brainreg_segment/segment.py index 49fc95b..a7ca00c 100644 --- a/brainreg_segment/segment.py +++ b/brainreg_segment/segment.py @@ -193,7 +193,7 @@ def add_loading_panel(self, row, column=0): self.load_button = add_button( "Load project (sample space)", self.load_data_layout, - self.load_brainreg_directory_sample, + self.load_brainreg_directory_sample_space, row=0, column=0, visibility=False, @@ -205,10 +205,10 @@ def add_loading_panel(self, row, column=0): "the orientation of your chosen atlas.", ) - self.load_button_standard = add_button( + self.load_button_atlas_space = add_button( "Load project (atlas space)", self.load_data_layout, - self.load_brainreg_directory_standard, + self.load_brainreg_directory_atlas_space, row=1, column=0, visibility=False, @@ -229,7 +229,7 @@ def add_loading_panel(self, row, column=0): # buttons made visible after adding to main widget, preventing them # from briefly appearing in a separate window self.load_button.setVisible(True) - self.load_button_standard.setVisible(True) + self.load_button_atlas_space.setVisible(True) def add_saving_panel(self, row): """ @@ -349,7 +349,7 @@ def load_atlas(self): opacity=0.3, visible=False, ) - self.standard_space = True + self.atlas_space = True self.prevent_layer_edit() def reset_atlas_menu(self): @@ -360,25 +360,23 @@ def reset_atlas_menu(self): # BRAINREG INTERACTION ################################################# - def load_brainreg_directory_sample(self): - self.get_brainreg_directory(standard_space=False) + def load_brainreg_directory_sample_space(self): + self.get_brainreg_directory(atlas_space=False) - def load_brainreg_directory_standard(self): - self.get_brainreg_directory(standard_space=True) + def load_brainreg_directory_atlas_space(self): + self.get_brainreg_directory(atlas_space=True) - def get_brainreg_directory(self, standard_space): + def get_brainreg_directory(self, atlas_space): """ Shows file dialog to choose output directory and sets global directory info """ - if standard_space: - self.plugin = ( - "brainglobe-napari-io.brainreg_read_dir_standard_space" - ) - self.standard_space = True + if atlas_space: + self.plugin = "brainglobe-napari-io.brainreg_read_dir_atlas_space" + self.atlas_space = True else: self.plugin = "brainglobe-napari-io.brainreg_read_dir" - self.standard_space = False + self.atlas_space = False self.status_label.setText("Loading...") options = QFileDialog.Options() @@ -415,7 +413,7 @@ def load_brainreg_directory(self): self.viewer.open(str(self.directory), plugin=self.plugin) self.paths = Paths( self.directory, - standard_space=self.standard_space, + atlas_space=self.atlas_space, ) self.initialise_loaded_data() except ValueError: @@ -443,7 +441,7 @@ def initialise_loaded_data(self): self.metadata = self.base_layer.metadata self.atlas = self.metadata["atlas_class"] self.annotations_layer = self.viewer.layers[self.metadata["atlas"]] - if self.standard_space: + if self.atlas_space: self.hemispheres_data = self.atlas.hemispheres else: self.hemispheres_layer = self.viewer.layers[ @@ -497,7 +495,7 @@ def initialise_segmentation_interface(self): self.initialise_image_view() self.save_data_panel.setVisible(True) self.save_button.setVisible(True) - self.export_button.setVisible(self.standard_space) + self.export_button.setVisible(self.atlas_space) self.show_regionseg_button.setEnabled(True) self.show_trackseg_button.setEnabled(True) self.status_label.setText("Ready") diff --git a/tests/conftest.py b/tests/conftest.py index be98ad2..b2c870a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -38,9 +38,9 @@ def segmentation_widget_with_data_atlas_space(tmp_path, segmentation_widget): """ tmp_input_dir = tmp_path / "brainreg_output" shutil.copytree(brainreg_dir, tmp_input_dir) - segmentation_widget.standard_space = True + segmentation_widget.atlas_space = True segmentation_widget.plugin = ( - "brainglobe-napari-io.brainreg_read_dir_standard_space" + "brainglobe-napari-io.brainreg_read_dir_atlas_space" ) segmentation_widget.directory = Path(tmp_input_dir) segmentation_widget.load_brainreg_directory() diff --git a/tests/tests/test_integration/test_gui/test_gui.py b/tests/tests/test_integration/test_gui/test_gui.py index a1c9bd1..e9f278a 100644 --- a/tests/tests/test_integration/test_gui/test_gui.py +++ b/tests/tests/test_integration/test_gui/test_gui.py @@ -8,23 +8,23 @@ def test_load_sample_space(segmentation_widget): - segmentation_widget.standard_space = False + segmentation_widget.atlas_space = False segmentation_widget.plugin = "brainglobe-napari-io.brainreg_read_dir" segmentation_widget.directory = brainreg_dir segmentation_widget.load_brainreg_directory() check_loaded_layers(segmentation_widget, 7) - check_not_editable(segmentation_widget, standard_space=False) + check_not_editable(segmentation_widget, atlas_space=False) -def test_load_standard_space(segmentation_widget): - segmentation_widget.standard_space = True +def test_load_atlas_space(segmentation_widget): + segmentation_widget.atlas_space = True segmentation_widget.plugin = ( - "brainglobe-napari-io.brainreg_read_dir_standard_space" + "brainglobe-napari-io.brainreg_read_dir_atlas_space" ) segmentation_widget.directory = brainreg_dir segmentation_widget.load_brainreg_directory() check_loaded_layers(segmentation_widget, 4) - check_not_editable(segmentation_widget, standard_space=True) + check_not_editable(segmentation_widget, atlas_space=True) def test_layer_deletion(segmentation_widget): @@ -35,7 +35,7 @@ def test_layer_deletion(segmentation_widget): assert len(segmentation_widget.viewer.layers) == 0 segmentation_widget.viewer.add_points(np.array([[1, 1], [2, 2]])) assert len(segmentation_widget.viewer.layers) == 1 - segmentation_widget.standard_space = False + segmentation_widget.atlas_space = False segmentation_widget.plugin = "brainglobe-napari-io.brainreg_read_dir" segmentation_widget.directory = brainreg_dir segmentation_widget.load_brainreg_directory() @@ -51,10 +51,10 @@ def check_loaded_layers(widget, num_layers): assert widget.annotations_layer.name == widget.atlas.atlas_name -def check_not_editable(widget, standard_space=False): +def check_not_editable(widget, atlas_space=False): assert widget.base_layer.editable is False assert widget.annotations_layer.editable is False - if not standard_space: + if not atlas_space: assert widget.viewer.layers["Hemispheres"].editable is False @@ -72,9 +72,9 @@ def test_load_atlas(segmentation_widget, tmp_path): def test_general(segmentation_widget): - segmentation_widget.standard_space = True + segmentation_widget.atlas_space = True segmentation_widget.plugin = ( - "brainglobe-napari-io.brainreg_read_dir_standard_space" + "brainglobe-napari-io.brainreg_read_dir_atlas_space" ) segmentation_widget.directory = brainreg_dir segmentation_widget.load_brainreg_directory() @@ -104,23 +104,23 @@ def check_paths(widget): assert ( widget.paths.segmentation_directory - == brainreg_dir / "manual_segmentation" / "standard_space" + == brainreg_dir / "manual_segmentation" / "atlas_space" ) assert ( widget.paths.regions_directory - == brainreg_dir / "manual_segmentation" / "standard_space" / "regions" + == brainreg_dir / "manual_segmentation" / "atlas_space" / "regions" ) assert ( widget.paths.region_summary_csv == brainreg_dir / "manual_segmentation" - / "standard_space" + / "atlas_space" / "regions" / "summary.csv" ) assert ( widget.paths.tracks_directory - == brainreg_dir / "manual_segmentation" / "standard_space" / "tracks" + == brainreg_dir / "manual_segmentation" / "atlas_space" / "tracks" ) diff --git a/tests/tests/test_integration/test_gui/test_region_ui_functionality.py b/tests/tests/test_integration/test_gui/test_region_ui_functionality.py index abf05b6..acc1b7c 100644 --- a/tests/tests/test_integration/test_gui/test_region_ui_functionality.py +++ b/tests/tests/test_integration/test_gui/test_region_ui_functionality.py @@ -9,7 +9,7 @@ brainreg_dir = Path.cwd() / "tests" / "data" / "brainreg_output" validate_regions_dir = ( - brainreg_dir / "manual_segmentation" / "standard_space" / "regions" + brainreg_dir / "manual_segmentation" / "atlas_space" / "regions" ) @@ -17,7 +17,7 @@ def test_regions_dir(tmp_path): tmp_input_dir = tmp_path / "brainreg_output" test_regions_dir = ( - tmp_input_dir / "manual_segmentation" / "standard_space" / "regions" + tmp_input_dir / "manual_segmentation" / "atlas_space" / "regions" ) return test_regions_dir diff --git a/tests/tests/test_integration/test_gui/test_track_ui_functionality.py b/tests/tests/test_integration/test_gui/test_track_ui_functionality.py index 0534f6c..6b72308 100644 --- a/tests/tests/test_integration/test_gui/test_track_ui_functionality.py +++ b/tests/tests/test_integration/test_gui/test_track_ui_functionality.py @@ -7,7 +7,7 @@ brainreg_dir = Path.cwd() / "tests" / "data" / "brainreg_output" validate_tracks_dir = ( - brainreg_dir / "manual_segmentation" / "standard_space" / "tracks" + brainreg_dir / "manual_segmentation" / "atlas_space" / "tracks" ) @@ -15,7 +15,7 @@ def test_tracks_dir(tmp_path): tmp_input_dir = tmp_path / "brainreg_output" test_tracks_dir = ( - tmp_input_dir / "manual_segmentation" / "standard_space" / "tracks" + tmp_input_dir / "manual_segmentation" / "atlas_space" / "tracks" ) return test_tracks_dir