Skip to content

Commit 24c4c0d

Browse files
authored
Improve error message for deprecated metric names (#4358)
1 parent f1f3acb commit 24c4c0d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/spikeinterface/core/analyzer_extension_core.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ class BaseMetric:
828828
needs_job_kwargs = False # whether the metric needs job_kwargs
829829
supports_periods = False # whether the metric function supports periods
830830
depend_on = [] # extensions the metric depends on
831+
deprecated_names = [] # list of metric names used by previous versions of spikeinterface
831832

832833
# the metric function must have the signature:
833834
# def metric_function(sorting_analyzer, unit_ids, **metric_params)
@@ -1035,15 +1036,25 @@ def _set_params(
10351036
ValueError
10361037
If any of the metric names are not in the available metrics.
10371038
"""
1038-
# check metric names
10391039
if metric_names is None:
10401040
metric_names = [m.metric_name for m in self.metric_list]
10411041
else:
1042+
# check if any given names are from previous versions of spikeinterface
1043+
deprecated_name_error_message = ""
1044+
for metric in self.metric_list:
1045+
for deprecated_name in metric.deprecated_names:
1046+
if deprecated_name in metric_names:
1047+
deprecated_name_error_message += f"The metric '{deprecated_name}' has been re-named or re-organized. You can now compute it using the metric name '{metric.metric_name}'.\n"
1048+
if len(deprecated_name_error_message) > 0:
1049+
raise ValueError(deprecated_name_error_message)
1050+
1051+
# check metric names
10421052
for metric_name in metric_names:
10431053
if metric_name not in [m.metric_name for m in self.metric_list]:
10441054
raise ValueError(
10451055
f"Metric {metric_name} not in available metrics {[m.metric_name for m in self.metric_list]}"
10461056
)
1057+
10471058
# check dependencies
10481059
metrics_to_remove = []
10491060
for metric_name in metric_names:

src/spikeinterface/metrics/quality/pca_metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Mahalanobis(BaseMetric):
5454
}
5555
depend_on = ["principal_components"]
5656
needs_tmp_data = True
57+
deprecated_names = ["l_ratio", "isolation_distance"]
5758

5859

5960
def _d_prime_metric_function(sorting_analyzer, unit_ids, tmp_data, **metric_params):
@@ -318,6 +319,7 @@ class NearestNeighborAdvanced(BaseMetric):
318319
depend_on = ["principal_components", "waveforms", "templates"]
319320
needs_tmp_data = True
320321
needs_job_kwargs = True
322+
deprecated_names = ["nn_isolation", "nn_noise_overlap"]
321323

322324

323325
def _silhouette_metric_function(sorting_analyzer, unit_ids, tmp_data, **metric_params):

src/spikeinterface/metrics/template/metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ class NumberOfPeaks(BaseMetric):
656656
"num_negative_peaks": "Number of negative peaks in the template",
657657
}
658658
needs_tmp_data = True
659+
deprecated_names = ["num_positive_peaks", "num_negative_peaks"]
659660

660661

661662
single_channel_metrics = [
@@ -699,6 +700,7 @@ class VelocityFits(BaseMetric):
699700
"velocity_below": "Velocity of the spike propagation below the max channel in um/ms",
700701
}
701702
needs_tmp_data = True
703+
deprecated_names = ["velocity_above", "velocity_below"]
702704

703705

704706
def multi_channel_metric(unit_function, sorting_analyzer, unit_ids, tmp_data, **metric_params):

0 commit comments

Comments
 (0)