Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove functionality to load atlas #156

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions brainglobe_segmentation/atlas/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from bg_atlasapi.list_atlases import descriptors, utils


def lateralise_atlas_image(
masked_atlas_annotations,
hemispheres,
Expand All @@ -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.
Expand Down
37 changes: 0 additions & 37 deletions brainglobe_segmentation/layout/gui_elements.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,12 @@
from qtpy.QtWidgets import (
QCheckBox,
QComboBox,
QDoubleSpinBox,
QLabel,
QPushButton,
QSpinBox,
)


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,
Expand Down
103 changes: 2 additions & 101 deletions brainglobe_segmentation/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 0 additions & 13 deletions tests/tests/test_integration/test_gui/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
12 changes: 0 additions & 12 deletions tests/tests/test_unit/test_atlas/test_atlas_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading