Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ classifiers = [
]

dependencies = [
"spikeinterface[full]>=0.104.0",
"markdown"
# "spikeinterface[full]>=0.104.0",
"spikeinterface @ git+https://github.com/SpikeInterface/spikeinterface.git",
"markdown",
"glasbey"
]

[project.urls]
Expand Down
3 changes: 1 addition & 2 deletions spikeinterface_gui/backend_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ def on_active_view_updated(self, param):
view._panel_view_is_active = False

def on_unit_color_changed(self, param):
if not self._active:
return
# In this case we send it also if the view is not active, because we want to update colors anyways
for view in self.controller.views:
if param.obj.view == view:
continue
Expand Down
31 changes: 23 additions & 8 deletions spikeinterface_gui/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from copy import deepcopy

from spikeinterface.widgets.utils import get_unit_colors
from spikeinterface import compute_sparsity
from spikeinterface.core import get_template_extremum_channel, BaseEvent
from spikeinterface.core.sorting_tools import spike_vector_to_indices
Expand All @@ -25,6 +24,7 @@
_default_main_settings = dict(
max_visible_units=10,
color_mode='color_by_unit',
num_colors=20,
use_times=False
)

Expand Down Expand Up @@ -382,8 +382,8 @@ def __init__(
curation_data = json.load(f)

elif self.analyzer.format == "zarr":
import zarr
zarr_root = zarr.open(self.analyzer.folder, mode='r')
from spikeinterface.core.zarrextractors import super_zarr_open
zarr_root = super_zarr_open(self.analyzer.folder, mode='r')
if "spikeinterface_gui" in zarr_root.keys() and "curation_data" in zarr_root["spikeinterface_gui"].attrs.keys():
curation_data = zarr_root["spikeinterface_gui"].attrs["curation_data"]

Expand Down Expand Up @@ -548,22 +548,37 @@ def get_information_txt(self):

return txt

def get_divergent_unit_colors(self, num_entries=20):
import glasbey
import matplotlib.colors as mcolors

unit_locations = self.analyzer.get_extension("unit_locations").get_data()
# lexsort by x and y
sorted_inds = np.lexsort((unit_locations[:, 0], unit_locations[:, 1]))

# now assign interleaved colors sequentially to the spatially sorted units
colors = {}
color_array = glasbey.create_palette(num_entries, lightness_bounds=(30, 100), chroma_bounds=(30, 100))
for i, unit_ind in enumerate(sorted_inds):
unit_id = self.unit_ids[unit_ind]
colors[unit_id] = mcolors.to_rgba(color_array[i % num_entries])
return colors


def refresh_colors(self):
if self.backend == "qt":
self._cached_qcolors = {}
elif self.backend == "panel":
pass

if self.main_settings['color_mode'] == 'color_by_unit':
self.colors = get_unit_colors(self.analyzer.sorting, color_engine='matplotlib', map_name='gist_ncar',
shuffle=True, seed=42)
self.colors = self.get_divergent_unit_colors(num_entries=self.main_settings['num_colors'])
elif self.main_settings['color_mode'] == 'color_only_visible':
unit_colors = get_unit_colors(self.analyzer.sorting, color_engine='matplotlib', map_name='gist_ncar',
shuffle=True, seed=42)
unit_colors = self.get_divergent_unit_colors(num_entries=self.main_settings['num_colors'])
self.colors = {unit_id: (0.3, 0.3, 0.3, 1.) for unit_id in self.unit_ids}
for unit_id in self.get_visible_unit_ids():
self.colors[unit_id] = unit_colors[unit_id]
elif self.main_settings['color_mode'] == 'color_by_visibility':
elif self.main_settings['color_mode'] == 'color_by_visibility':
self.colors = {unit_id: (0.3, 0.3, 0.3, 1.) for unit_id in self.unit_ids}
import matplotlib.pyplot as plt
cmap = plt.colormaps['tab10']
Expand Down
24 changes: 24 additions & 0 deletions spikeinterface_gui/correlogramview.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def _compute(self):
# clear cache
self.figure_cache = {}

def on_unit_color_changed(self):
# clear cache
self.figure_cache = {}
self.refresh()

## Qt ##

def _qt_make_layout(self):
Expand Down Expand Up @@ -73,6 +78,15 @@ def _qt_refresh(self):
unit_id2 = visible_unit_ids[c]
if (unit_id1, unit_id2) in self.figure_cache:
plot = self.figure_cache[(unit_id1, unit_id2)]
if self.controller.main_settings["color_mode"] == 'color_by_visibility':
# Update color in cached figure
if r == c:
unit_id = visible_unit_ids[r]
color = colors[unit_id]
for item in plot.items:
if hasattr(item, 'setBrush') and hasattr(item, 'setPen'):
item.setBrush(color)
item.setPen(color)
else:
# create new plot
i = unit_ids.index(visible_unit_ids[r])
Expand Down Expand Up @@ -145,6 +159,16 @@ def _panel_refresh(self):

if (unit1, unit2) in self.figure_cache:
fig = self.figure_cache[(unit1, unit2)]
# for the color_by_visibility
if self.controller.main_settings["color_mode"] == 'color_by_visibility':
# Update color in cached figure
if r == c:
unit_id = visible_unit_ids[r]
color = colors[unit_id]
for renderer in fig.renderers:
if hasattr(renderer, 'glyph') and hasattr(renderer.glyph, 'fill_color'):
renderer.glyph.fill_color = color
renderer.glyph.line_color = color
Comment thread
chrishalcrow marked this conversation as resolved.
else:
# create new figure
i = unit_ids.index(unit1)
Expand Down
13 changes: 11 additions & 2 deletions spikeinterface_gui/mainsettingsview.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{'name': 'max_visible_units', 'type': 'int', 'value' : 10 },
{'name': 'color_mode', 'type': 'list', 'value' : 'color_by_unit',
'limits': ['color_by_unit', 'color_only_visible', 'color_by_visibility']},
{'name': 'num_colors', 'type': 'int', 'value' : 20},
{'name': 'use_times', 'type': 'bool', 'value': False}
]

Expand All @@ -30,7 +31,7 @@ def __init__(self, controller=None, parent=None, backend="qt"):


def on_max_visible_units_changed(self):
max_visible = self.main_settings['max_visible_units']
max_visible = self.main_settings_sync['max_visible_units']
self.controller.main_settings['max_visible_units'] = max_visible

visible_ids = self.controller.get_visible_unit_ids()
Expand All @@ -40,11 +41,14 @@ def on_max_visible_units_changed(self):
self.notify_unit_visibility_changed()

def on_change_color_mode(self):

self.controller.main_settings['color_mode'] = self.main_settings['color_mode']
self.controller.refresh_colors()
self.notify_unit_color_changed()

def on_num_colors_changed(self):
self.controller.main_settings['num_colors'] = self.main_settings['num_colors']
self.controller.refresh_colors()
self.notify_unit_color_changed()

def on_use_times(self):
self.controller.main_settings['use_times'] = self.main_settings['use_times']
Expand Down Expand Up @@ -115,6 +119,7 @@ def _qt_make_layout(self):

self.main_settings.param('max_visible_units').sigValueChanged.connect(self.on_max_visible_units_changed)
self.main_settings.param('color_mode').sigValueChanged.connect(self.on_change_color_mode)
self.main_settings.param('num_colors').sigValueChanged.connect(self.on_num_colors_changed)
self.main_settings.param('use_times').sigValueChanged.connect(self.on_use_times)

def qt_make_settings_dict(self, view):
Expand Down Expand Up @@ -150,6 +155,7 @@ def _panel_make_layout(self):
name=f"Main settings")
self.main_settings._parameterized.param.watch(self._panel_on_max_visible_units_changed, 'max_visible_units')
self.main_settings._parameterized.param.watch(self._panel_on_change_color_mode, 'color_mode')
self.main_settings._parameterized.param.watch(self._panel_on_num_colors_changed, 'num_colors')
self.main_settings._parameterized.param.watch(self._panel_on_use_times, 'use_times')
self.layout = pn.Column(self.save_setting_button, self.main_settings_layout, sizing_mode="stretch_both")

Expand All @@ -170,6 +176,9 @@ def _panel_on_max_visible_units_changed(self, event):
def _panel_on_change_color_mode(self, event):
self.on_change_color_mode()

def _panel_on_num_colors_changed(self, event):
self.on_num_colors_changed()

def _panel_on_use_times(self, event):
self.on_use_times()

Expand Down
Loading
Loading