diff --git a/brainglobe_segmentation/atlas/utils.py b/brainglobe_segmentation/atlas/utils.py index ed8262e..b3e2d4c 100644 --- a/brainglobe_segmentation/atlas/utils.py +++ b/brainglobe_segmentation/atlas/utils.py @@ -1,6 +1,3 @@ -from bg_atlasapi.list_atlases import descriptors, utils - - def lateralise_atlas_image( masked_atlas_annotations, hemispheres, @@ -24,18 +21,6 @@ def lateralise_atlas_image( return annotation_left, annotation_right -def get_available_atlases(): - """ - Get the available brainglobe atlases - :return: Dict of available atlases (["name":version]) - """ - available_atlases = utils.conf_from_url( - descriptors.remote_url_base.format("last_versions.conf") - ) - available_atlases = dict(available_atlases["atlases"]) - return available_atlases - - def structure_from_viewer(coordinates, atlas_layer, atlas): """ Get brain region info from mouse position in napari viewer. diff --git a/brainglobe_segmentation/layout/gui_elements.py b/brainglobe_segmentation/layout/gui_elements.py index 00bc343..81369bc 100644 --- a/brainglobe_segmentation/layout/gui_elements.py +++ b/brainglobe_segmentation/layout/gui_elements.py @@ -1,6 +1,5 @@ from qtpy.QtWidgets import ( QCheckBox, - QComboBox, QDoubleSpinBox, QLabel, QPushButton, @@ -8,42 +7,6 @@ ) -def add_combobox( - layout, - label, - items, - row: int = 0, - column: int = 0, - label_stack=False, - callback=None, - width=150, - tooltip=None, -): - if label_stack: - combobox_row = row + 1 - combobox_column = column - else: - combobox_row = row - combobox_column = column + 1 - combobox = QComboBox() - combobox.addItems(items) - if callback: - combobox.currentIndexChanged.connect(callback) - combobox.setMaximumWidth = width - - if label is not None: - combobox_label = QLabel(label) - combobox_label.setMaximumWidth = width - layout.addWidget(combobox_label, row, column) - else: - combobox_label = None - - if tooltip: - combobox.setToolTip(tooltip) - layout.addWidget(combobox, combobox_row, combobox_column) - return combobox, combobox_label - - def add_button( label, layout, diff --git a/brainglobe_segmentation/segment.py b/brainglobe_segmentation/segment.py index c27d2fb..78107c1 100644 --- a/brainglobe_segmentation/segment.py +++ b/brainglobe_segmentation/segment.py @@ -3,15 +3,11 @@ import napari import numpy as np -from bg_atlasapi import BrainGlobeAtlas from napari.qt.threading import thread_worker from qtpy import QtCore from qtpy.QtWidgets import QFileDialog, QGridLayout, QGroupBox, QLabel, QWidget -from brainglobe_segmentation.atlas.utils import ( - get_available_atlases, - structure_from_viewer, -) +from brainglobe_segmentation.atlas.utils import structure_from_viewer from brainglobe_segmentation.layout.gui_constants import ( BOUNDARIES_STRING, COLUMN_WIDTH, @@ -23,10 +19,7 @@ WINDOW_HEIGHT, WINDOW_WIDTH, ) -from brainglobe_segmentation.layout.gui_elements import ( - add_button, - add_combobox, -) +from brainglobe_segmentation.layout.gui_elements import add_button from brainglobe_segmentation.layout.utils import display_warning from brainglobe_segmentation.paths import Paths from brainglobe_segmentation.regions.IO import ( @@ -224,8 +217,6 @@ def add_loading_panel(self, row, column=0): "space of the atlas.", ) - self.add_atlas_menu(self.load_data_layout) - self.load_data_layout.setColumnMinimumWidth(0, COLUMN_WIDTH) self.load_data_panel.setLayout(self.load_data_layout) self.load_data_panel.setVisible(True) @@ -271,96 +262,6 @@ def add_saving_panel(self, row): self.save_data_panel.setVisible(False) - # ATLAS INTERACTION ################################################### - - def add_atlas_menu(self, layout): - list_of_atlasses = ["Load atlas"] - available_atlases = get_available_atlases() - for atlas in available_atlases.keys(): - atlas_desc = f"{atlas} v{available_atlases[atlas]}" - list_of_atlasses.append(atlas_desc) - atlas_menu, _ = add_combobox( - layout, - None, - list_of_atlasses, - row=2, - column=0, - label_stack=True, - callback=self.initialise_atlas, - width=COLUMN_WIDTH, - tooltip="Load a BrainGlobe atlas if you don't have " - "a brainreg project to load. Useful for creating " - "illustrations or testing the software.", - ) - - self.atlas_menu = atlas_menu - - def initialise_atlas(self): - atlas_string = self.atlas_menu.currentText() - atlas_name = atlas_string.split(" ")[0].strip() - if atlas_name != self.current_atlas_name: - status = self.remove_layers() - if not status: # Something prevented deletion - self.reset_atlas_menu() - return - else: - print(f"{atlas_string} already selected for segmentation.") - self.reset_atlas_menu() - return - - # Get / set output directory - self.set_output_directory() - if not self.directory: - self.reset_atlas_menu() - return - - self.current_atlas_name = atlas_name - # Instantiate atlas layers - self.load_atlas() - - self.directory = self.directory / atlas_name - self.paths = Paths(self.directory, atlas_space=True) - - self.status_label.setText("Ready") - # Set window title - self.initialise_segmentation_interface() - # Check / load previous regions and tracks - self.region_seg.check_saved_region() - self.track_seg.check_saved_track() - self.reset_atlas_menu() - - def set_output_directory(self): - self.status_label.setText("Loading...") - self.directory = QFileDialog.getExistingDirectory( - self, - "Select output directory", - ) - if self.directory != "": - self.directory = Path(self.directory) - - def load_atlas(self): - atlas = BrainGlobeAtlas(self.current_atlas_name) - self.atlas = atlas - self.base_layer = self.viewer.add_image( - self.atlas.reference, - name="Reference", - ) - self.annotations_layer = self.viewer.add_labels( - self.atlas.annotation, - name=self.atlas.atlas_name, - blending="additive", - opacity=0.3, - visible=False, - ) - self.atlas_space = True - self.prevent_layer_edit() - - def reset_atlas_menu(self): - # Reset menu for atlas - show initial description - self.atlas_menu.blockSignals(True) - self.atlas_menu.setCurrentIndex(0) - self.atlas_menu.blockSignals(False) - # BRAINREG INTERACTION ################################################# def load_brainreg_directory_sample_space(self): diff --git a/tests/tests/test_integration/test_gui/test_gui.py b/tests/tests/test_integration/test_gui/test_gui.py index 08de52e..c4f5892 100644 --- a/tests/tests/test_integration/test_gui/test_gui.py +++ b/tests/tests/test_integration/test_gui/test_gui.py @@ -58,19 +58,6 @@ def check_not_editable(widget, atlas_space=False): assert widget.viewer.layers["Hemispheres"].editable is False -def test_load_atlas(segmentation_widget, tmp_path): - segmentation_widget.directory = tmp_path - segmentation_widget.current_atlas_name = ATLAS_NAME - segmentation_widget.load_atlas() - assert len(segmentation_widget.viewer.layers) == 2 - assert segmentation_widget.base_layer.name == "Reference" - assert segmentation_widget.atlas.atlas_name == ATLAS_NAME - assert ( - segmentation_widget.annotations_layer.name - == segmentation_widget.atlas.atlas_name - ) - - def test_general(segmentation_widget): segmentation_widget.atlas_space = True segmentation_widget.plugin = ( diff --git a/tests/tests/test_unit/test_atlas/test_atlas_utils.py b/tests/tests/test_unit/test_atlas/test_atlas_utils.py index 37dc31d..f74eb4d 100644 --- a/tests/tests/test_unit/test_atlas/test_atlas_utils.py +++ b/tests/tests/test_unit/test_atlas/test_atlas_utils.py @@ -2,18 +2,6 @@ from brainglobe_segmentation.atlas import utils as atlas_utils -atlas_name = "allen_mouse_50um" - - -def test_get_available_atlases(): - atlases = atlas_utils.get_available_atlases() - - # arbitrary selection of atlases - assert float(atlases["allen_mouse_10um"]) >= 0.3 - assert float(atlases["allen_mouse_25um"]) >= 0.3 - assert float(atlases["allen_mouse_50um"]) >= 0.3 - assert float(atlases["mpin_zfish_1um"]) >= 0.4 - def test_lateralise_atlas_image(allen_mouse_50um_atlas): atlas = allen_mouse_50um_atlas