Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b6726e8
Timing the computations of quality metrics
yger Jan 8, 2026
8d489a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 8, 2026
5f5e13e
Optimize get_num_spikes
yger Jan 8, 2026
cb39bcc
Merge branch 'optimize_metrics' of github.com:yger/spikeinterface int…
yger Jan 8, 2026
2f6e44a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 8, 2026
2f934f3
Optimization of sd_ratio. Could be more aggresive if needed
yger Jan 8, 2026
23d5469
Merge branch 'optimize_metrics' of github.com:yger/spikeinterface int…
yger Jan 8, 2026
9cecc8c
Fix
yger Jan 8, 2026
0a36416
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 8, 2026
4e91004
Minor speedup for amplitude_cv
yger Jan 8, 2026
1b32e00
Merge branch 'optimize_metrics' of github.com:yger/spikeinterface int…
yger Jan 8, 2026
e11475b
WIP
yger Jan 8, 2026
2c31113
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 8, 2026
4b14ab8
More metrics
yger Jan 9, 2026
54067c2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2026
19dc2c7
Metrics
yger Jan 9, 2026
d27991d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2026
904d02c
WIP
yger Jan 9, 2026
33f107f
WIP
yger Jan 9, 2026
15273f5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2026
34b5f3e
WIP
yger Jan 9, 2026
2d1ba58
Merge branch 'optimize_metrics' of github.com:yger/spikeinterface int…
yger Jan 9, 2026
9007a27
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2026
98abb5b
More optimizations
yger Jan 10, 2026
6956119
Merge branch 'optimize_metrics' of github.com:yger/spikeinterface int…
yger Jan 10, 2026
7094197
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2026
2975fec
Optimize synchrony also
yger Jan 10, 2026
fa87bb3
Merge branch 'optimize_metrics' of github.com:yger/spikeinterface int…
yger Jan 10, 2026
2025820
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2026
c40200c
Drift metrics
yger Jan 11, 2026
80ba186
WIP
yger Jan 11, 2026
b38b149
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 11, 2026
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
20 changes: 16 additions & 4 deletions src/spikeinterface/core/analyzer_extension_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,9 @@ def _compute_metrics(
-------
metrics : pd.DataFrame
DataFrame containing the computed metrics for each unit.
run_times : dict
Dictionary containing the computation time for each metric.

"""
import pandas as pd

Expand All @@ -1121,11 +1124,17 @@ def _compute_metrics(

metrics = pd.DataFrame(index=unit_ids, columns=list(column_names_dtypes.keys()))

run_times = {}

for metric_name in metric_names:
metric = [m for m in self.metric_list if m.metric_name == metric_name][0]
column_names = list(metric.metric_columns.keys())
import time

t_start = time.perf_counter()
try:
metric_params = self.params["metric_params"].get(metric_name, {})

res = metric.compute(
sorting_analyzer,
unit_ids=unit_ids,
Expand All @@ -1139,6 +1148,8 @@ def _compute_metrics(
res = {unit_id: np.nan for unit_id in unit_ids}
else:
res = namedtuple("MetricResult", column_names)(*([np.nan] * len(column_names)))
t_end = time.perf_counter()
run_times[metric_name] = t_end - t_start

# res is a namedtuple with several dictionary entries (one per column)
if isinstance(res, dict):
Expand All @@ -1150,7 +1161,7 @@ def _compute_metrics(

metrics = self._cast_metrics(metrics)

return metrics
return metrics, run_times

def _run(self, **job_kwargs):

Expand All @@ -1161,7 +1172,7 @@ def _run(self, **job_kwargs):
job_kwargs = fix_job_kwargs(job_kwargs)

# compute the metrics which have been specified by the user
computed_metrics = self._compute_metrics(
computed_metrics, run_times = self._compute_metrics(
sorting_analyzer=self.sorting_analyzer, unit_ids=None, metric_names=metrics_to_compute, **job_kwargs
)

Expand Down Expand Up @@ -1189,6 +1200,7 @@ def _run(self, **job_kwargs):
computed_metrics[column_name] = extension.data["metrics"][column_name]

self.data["metrics"] = computed_metrics
self.data["runtime_s"] = run_times

def _get_data(self):
# convert to correct dtype
Expand Down Expand Up @@ -1265,7 +1277,7 @@ def _merge_extension_data(
metrics = pd.DataFrame(index=all_unit_ids, columns=old_metrics.columns)

metrics.loc[not_new_ids, :] = old_metrics.loc[not_new_ids, :]
metrics.loc[new_unit_ids, :] = self._compute_metrics(
metrics.loc[new_unit_ids, :], _ = self._compute_metrics(
sorting_analyzer=new_sorting_analyzer, unit_ids=new_unit_ids, metric_names=metric_names, **job_kwargs
)
metrics = self._cast_metrics(metrics)
Expand Down Expand Up @@ -1309,7 +1321,7 @@ def _split_extension_data(
metrics = pd.DataFrame(index=all_unit_ids, columns=old_metrics.columns)

metrics.loc[not_new_ids, :] = old_metrics.loc[not_new_ids, :]
metrics.loc[new_unit_ids_f, :] = self._compute_metrics(
metrics.loc[new_unit_ids_f, :], _ = self._compute_metrics(
sorting_analyzer=new_sorting_analyzer, unit_ids=new_unit_ids_f, metric_names=metric_names, **job_kwargs
)
metrics = self._cast_metrics(metrics)
Expand Down
Loading
Loading