Skip to content
Open
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
21 changes: 21 additions & 0 deletions spikeinterface_gui/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,27 @@ def make_manual_merge_if_possible(self, merge_unit_ids):
print(f"Merged unit group: {[str(u) for u in merge_unit_ids]}")
return True


def remove_units_from_merge_if_possible(self, merge_unit_ids):
"""
Check if selected units are in a merge group. If they are, remove them.
"""
if not self.curation:
return False

merges = self.curation_data["merges"]
for i, merge in enumerate(merges):
if set(merge_unit_ids).issubset(set(merge['unit_ids'])):
merge_ids_with_removed_ids = list(set(merge['unit_ids']).difference(set(merge_unit_ids)))
if len(merge_ids_with_removed_ids) > 1:
merges[i]['unit_ids'] = merge_ids_with_removed_ids
return True
else:
return False

return False


def make_manual_split_if_possible(self, unit_id):
"""
Check if the a unit_id can be split into a new split in the curation_data.
Expand Down
24 changes: 21 additions & 3 deletions spikeinterface_gui/unitlistview.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def _qt_make_layout(self):
act.triggered.connect(self._qt_delete_unit)
act = self.menu.addAction('Merge selected')
act.triggered.connect(self._qt_merge_selected)
act = self.menu.addAction('Remove from merge')
act.triggered.connect(self._qt_remove_from_merge)
self.shortcut_delete = QT.QShortcut(self.qt_widget)
self.shortcut_delete.setKey(QT.QKeySequence("ctrl+d"))
self.shortcut_delete.activated.connect(self._qt_on_delete_shortcut)
Expand Down Expand Up @@ -156,11 +158,17 @@ def _qt_refresh_visibility_items(self):
from .myqt import QT

self.table.itemChanged.disconnect(self._qt_on_item_changed)

visible_unit_ids = self.controller.get_visible_unit_ids()

view_target_unit_id = visible_unit_ids[0]
target_item = self.items_visibility[view_target_unit_id]
self.table.scrollToItem(target_item, QT.QAbstractItemView.PositionAtCenter)

for unit_id in self.controller.unit_ids:
item = self.items_visibility[unit_id]
item.setCheckState(QT.Qt.Unchecked)
for unit_id in self.controller.get_visible_unit_ids():
for unit_id in visible_unit_ids:
item = self.items_visibility[unit_id]
item.setCheckState(QT.Qt.Checked)
self._qt_refresh_color_icons()
Expand Down Expand Up @@ -435,9 +443,19 @@ def _qt_merge_selected(self):
"merged, or split already."
)
return
self.notify_manual_curation_updated()

else:
self.notify_manual_curation_updated()

def _qt_remove_from_merge(self):
merge_unit_ids = self.get_selected_unit_ids()
success = self.controller.remove_units_from_merge_if_possible(merge_unit_ids)
if not success:
self.warning(
"Could not remove units from a merge. Ensure all selected units are in a merge group, and that you are not leaving zero or one units in the merge group."
)
return
else:
self.notify_manual_curation_updated()

## panel zone ##
def _panel_make_layout(self):
Expand Down