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

Fix plot_sorting_summary widget #3627

Merged
merged 3 commits into from
Jan 20, 2025
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
2 changes: 1 addition & 1 deletion src/spikeinterface/widgets/sorting_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ..core import SortingAnalyzer


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


class SortingSummaryWidget(BaseWidget):
Expand Down
25 changes: 19 additions & 6 deletions src/spikeinterface/widgets/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def setUpClass(cls):
spike_amplitudes=dict(),
unit_locations=dict(),
spike_locations=dict(),
quality_metrics=dict(metric_names=["snr", "isi_violation", "num_spikes", "amplitude_cutoff"]),
quality_metrics=dict(
metric_names=["snr", "isi_violation", "num_spikes", "firing_rate", "amplitude_cutoff"]
),
template_metrics=dict(),
correlograms=dict(),
template_similarity=dict(),
Expand Down Expand Up @@ -531,26 +533,37 @@ def test_plot_sorting_summary(self):
possible_backends = list(sw.SortingSummaryWidget.get_possible_backends())
for backend in possible_backends:
if backend not in self.skip_backends:
sw.plot_sorting_summary(self.sorting_analyzer_dense, backend=backend, **self.backend_kwargs[backend])
sw.plot_sorting_summary(self.sorting_analyzer_sparse, backend=backend, **self.backend_kwargs[backend])
sw.plot_sorting_summary(
self.sorting_analyzer_dense,
displayed_unit_properties=[],
backend=backend,
**self.backend_kwargs[backend],
)
sw.plot_sorting_summary(
self.sorting_analyzer_sparse,
displayed_unit_properties=[],
backend=backend,
**self.backend_kwargs[backend],
)
sw.plot_sorting_summary(
self.sorting_analyzer_sparse,
sparsity=self.sparsity_strict,
displayed_unit_properties=[],
backend=backend,
**self.backend_kwargs[backend],
)
# add unit_properties
# select unit_properties
sw.plot_sorting_summary(
self.sorting_analyzer_sparse,
unit_table_properties=["firing_rate", "snr"],
displayed_unit_properties=["firing_rate", "snr"],
backend=backend,
**self.backend_kwargs[backend],
)
# adding a missing property should raise a warning
with self.assertWarns(UserWarning):
sw.plot_sorting_summary(
self.sorting_analyzer_sparse,
unit_table_properties=["missing_property"],
displayed_unit_properties=["missing_property"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we changed the naming? this is a breaking change? I never use this argument but do others?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Alessio wants to test if a properties is not present. We decided to not raise an error make user life easier.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelgarcia I think he means the argument!!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the change in another PR.
I prefer this one which more easy to understand.
It is back compatible.
Few users I think were using it (only for sorting view).
Now it will be usable with spikeinterface-gui.

backend=backend,
**self.backend_kwargs[backend],
)
Expand Down
2 changes: 1 addition & 1 deletion src/spikeinterface/widgets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def make_units_table_from_analyzer(
all_df.append(df)

if analyzer.get_extension("template_metrics") is not None:
all_df = analyzer.get_extension("template_metrics").get_data()
df = analyzer.get_extension("template_metrics").get_data()
samuelgarcia marked this conversation as resolved.
Show resolved Hide resolved
all_df.append(df)

if len(all_df) > 0:
Expand Down
6 changes: 2 additions & 4 deletions src/spikeinterface/widgets/utils_sortingview.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ def generate_unit_table_view(
# keep only selected columns
unit_properties = np.array(unit_properties)
keep = np.isin(unit_properties, units_tables.columns)
if sum(keep) < len(unit_properties):
warn(f"Some unit properties are not in the sorting: {unit_properties[~keep]}")
unit_properties = unit_properties[keep]
units_tables = units_tables.loc[:, unit_properties]

dtype_convertor = {"i": "int", "u": "int", "f": "float", "U": "str", "S": "str", "b": "bool"}

ut_columns = []
for col in unit_properties:
if col not in units_tables.columns:
samuelgarcia marked this conversation as resolved.
Show resolved Hide resolved
continue
values = units_tables[col].to_numpy()
if values.dtype.kind in dtype_convertor:
txt_dtype = dtype_convertor[values.dtype.kind]
Expand All @@ -90,8 +90,6 @@ def generate_unit_table_view(
for unit_index, unit_id in enumerate(sorting.unit_ids):
row_values = {}
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
Loading