Skip to content

Commit

Permalink
default displayed props
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgarcia committed Jan 15, 2025
1 parent 3c1e195 commit 941a053
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
33 changes: 22 additions & 11 deletions src/spikeinterface/widgets/sorting_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from ..core import SortingAnalyzer


_default_displayed_unit_properties = ["firing_rate", "num_spikes", "x", "y", "amplitude", "snr", "rp_violation"]

class SortingSummaryWidget(BaseWidget):
"""
Plots spike sorting summary.
Expand Down Expand Up @@ -44,14 +46,14 @@ class SortingSummaryWidget(BaseWidget):
label_choices : list or None, default: None
List of labels to be added to the curation table
(sortingview backend)
displayed_units_properties : list or None, default: None
displayed_unit_properties : list or None, default: None
List of properties to be added to the unit table.
These may be drawn from the sorting extractor, and, if available,
the quality_metrics/template_metrics/unit_locations extensions of the SortingAnalyzer.
See all properties available with sorting.get_property_keys(), and, if available,
analyzer.get_extension("quality_metrics").get_data().columns and
analyzer.get_extension("template_metrics").get_data().columns.
extra_units_properties : None dict, default: None
extra_unit_properties : None dict, default: None
A dict with extra units properties to display.
curation_dict : dict or None
When curation is True, optionaly the viewer can get a previous 'curation_dict'
Expand All @@ -71,8 +73,8 @@ def __init__(
max_amplitudes_per_unit=None,
min_similarity_for_correlograms=0.2,
curation=False,
displayed_units_properties=None,
extra_units_properties=None,
displayed_unit_properties=None,
extra_unit_properties=None,
label_choices=None,
curation_dict=None,
label_definitions=None,
Expand All @@ -82,8 +84,12 @@ def __init__(
):

if unit_table_properties is not None:
warnings.warn("plot_sorting_summary() : unit_table_properties is deprecated, use displayed_units_properties instead")
displayed_units_properties = unit_table_properties
warnings.warn(
"plot_sorting_summary() : unit_table_properties is deprecated, use displayed_unit_properties instead",
category=DeprecationWarning,
stacklevel=2,
)
displayed_unit_properties = unit_table_properties


sorting_analyzer = self.ensure_sorting_analyzer(sorting_analyzer)
Expand All @@ -98,13 +104,18 @@ def __init__(
if curation_dict is not None and label_definitions is not None:
raise ValueError("curation_dict and label_definitions are mutualy exclusive, they cannot be not None both")

if displayed_unit_properties is None:
displayed_unit_properties = list(_default_displayed_unit_properties)
if extra_unit_properties is not None:
displayed_unit_properties += list(extra_unit_properties.keys())

data_plot = dict(
sorting_analyzer=sorting_analyzer,
unit_ids=unit_ids,
sparsity=sparsity,
min_similarity_for_correlograms=min_similarity_for_correlograms,
displayed_units_properties=displayed_units_properties,
extra_units_properties=extra_units_properties,
displayed_unit_properties=displayed_unit_properties,
extra_unit_properties=extra_unit_properties,
curation=curation,
label_choices=label_choices,
max_amplitudes_per_unit=max_amplitudes_per_unit,
Expand Down Expand Up @@ -183,7 +194,7 @@ def plot_sortingview(self, data_plot, **backend_kwargs):

# unit ids
v_units_table = generate_unit_table_view(
dp.sorting_analyzer, dp.displayed_units_properties, similarity_scores=similarity_scores
dp.sorting_analyzer, dp.displayed_unit_properties, similarity_scores=similarity_scores
)

if dp.curation:
Expand Down Expand Up @@ -226,7 +237,7 @@ def plot_spikeinterface_gui(self, data_plot, **backend_kwargs):
curation=data_plot["curation"],
curation_dict=data_plot["curation_dict"],
label_definitions=data_plot["label_definitions"],
extra_units_properties=data_plot["extra_units_properties"],
displayed_units_properties=data_plot["displayed_units_properties"],
extra_unit_properties=data_plot["extra_unit_properties"],
displayed_unit_properties=data_plot["displayed_unit_properties"],
)

12 changes: 8 additions & 4 deletions src/spikeinterface/widgets/utils_sortingview.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def generate_unit_table_view(

if isinstance(sorting_or_sorting_analyzer, SortingAnalyzer):
analyzer = sorting_or_sorting_analyzer
units_tables = make_units_table_from_sorting(analyzer)
units_tables = make_units_table_from_analyzer(analyzer)
sorting = analyzer.sorting
else:
sorting = sorting_or_sorting_analyzer
units_tables = make_units_table_from_analyzer(sorting)
units_tables = make_units_table_from_sorting(sorting)
# analyzer = None

if unit_properties is None:
Expand All @@ -79,7 +79,9 @@ def generate_unit_table_view(
dtype_convertor = {"i": "int", "u": "int", "f": "float", "U": "str", "S": "str", "b": "bool"}

ut_columns = []
for col in units_tables.columns:
for col in unit_properties:
if col not in units_tables.columns:
continue
values = units_tables[col].to_numpy()
if values.dtype.kind in dtype_convertor:
txt_dtype = dtype_convertor[values.dtype.kind]
Expand All @@ -88,7 +90,9 @@ def generate_unit_table_view(
ut_rows = []
for unit_index, unit_id in enumerate(sorting.unit_ids):
row_values = {}
for col in units_tables.columns:
for col in unit_properties:
if col not in units_tables.columns:
continue
values = units_tables[col].to_numpy()
if values.dtype.kind in dtype_convertor:
value = values[unit_index]
Expand Down

0 comments on commit 941a053

Please sign in to comment.