Skip to content

Commit 2c6e800

Browse files
authored
Merge pull request #3716 from alejoe91/fix-sv-properties
Fix `extra_properties` propagation in sorting summary and SV string properties
2 parents 0615ca9 + 62b65e1 commit 2c6e800

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/spikeinterface/widgets/sorting_summary.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class SortingSummaryWidget(BaseWidget):
5656
analyzer.get_extension("template_metrics").get_data().columns.
5757
extra_unit_properties : dict or None, default: None
5858
A dict with extra units properties to display.
59+
The key is the property name and the value must be a numpy.array.
5960
curation_dict : dict or None, default: None
6061
When curation is True, optionaly the viewer can get a previous 'curation_dict'
6162
to continue/check previous curations on this analyzer.
@@ -107,8 +108,8 @@ def __init__(
107108

108109
if displayed_unit_properties is None:
109110
displayed_unit_properties = list(_default_displayed_unit_properties)
110-
if extra_unit_properties is not None:
111-
displayed_unit_properties += list(extra_unit_properties.keys())
111+
if extra_unit_properties is not None:
112+
displayed_unit_properties = displayed_unit_properties + list(extra_unit_properties.keys())
112113

113114
data_plot = dict(
114115
sorting_analyzer=sorting_analyzer,
@@ -195,7 +196,10 @@ def plot_sortingview(self, data_plot, **backend_kwargs):
195196

196197
# unit ids
197198
v_units_table = generate_unit_table_view(
198-
dp.sorting_analyzer, dp.displayed_unit_properties, similarity_scores=similarity_scores
199+
dp.sorting_analyzer,
200+
dp.displayed_unit_properties,
201+
similarity_scores=similarity_scores,
202+
extra_unit_properties=dp.extra_unit_properties,
199203
)
200204

201205
if dp.curation:

src/spikeinterface/widgets/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from warnings import warn
34
import numpy as np
45

56

@@ -342,5 +343,9 @@ def make_units_table_from_analyzer(
342343
# the ndim = 1 is important because we need column only for the display in gui.
343344
if values.dtype.kind in "iuUSfb" and values.ndim == 1:
344345
units_table.loc[:, col] = values
346+
else:
347+
warn(
348+
f"Extra property {col} not added to the units table because it has ndim > 1 or dtype not supported",
349+
)
345350

346351
return units_table

src/spikeinterface/widgets/utils_sortingview.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ def generate_unit_table_view(
5353
sorting_or_sorting_analyzer: SortingAnalyzer | BaseSorting,
5454
unit_properties: list[str] | None = None,
5555
similarity_scores: np.ndarray | None = None,
56+
extra_unit_properties: dict | None = None,
5657
):
5758
import sortingview.views as vv
5859

5960
if isinstance(sorting_or_sorting_analyzer, SortingAnalyzer):
6061
analyzer = sorting_or_sorting_analyzer
61-
units_tables = make_units_table_from_analyzer(analyzer)
62+
units_tables = make_units_table_from_analyzer(analyzer, extra_properties=extra_unit_properties)
6263
sorting = analyzer.sorting
6364
else:
6465
sorting = sorting_or_sorting_analyzer
@@ -78,6 +79,8 @@ def generate_unit_table_view(
7879
units_tables = units_tables.loc[:, unit_properties]
7980

8081
dtype_convertor = {"i": "int", "u": "int", "f": "float", "U": "str", "S": "str", "b": "bool"}
82+
# we add "O": "str" because pandas automatically converts strings to Object dtype
83+
dtype_convertor["O"] = "str"
8184

8285
ut_columns = []
8386
for col in unit_properties:

0 commit comments

Comments
 (0)