|
8 | 8 |
|
9 | 9 | import numpy as np |
10 | 10 | import warnings |
11 | | -from typing import Optional |
12 | 11 | from copy import deepcopy |
13 | 12 |
|
14 | 13 | from ..core.sortinganalyzer import register_result_extension, AnalyzerExtension |
15 | | -from ..core import ChannelSparsity |
16 | 14 | from ..core.template_tools import get_template_extremum_channel |
17 | 15 | from ..core.template_tools import get_dense_templates_array |
18 | 16 |
|
@@ -238,13 +236,17 @@ def _compute_metrics(self, sorting_analyzer, unit_ids=None, verbose=False, **job |
238 | 236 |
|
239 | 237 | for metric_name in metrics_single_channel: |
240 | 238 | func = _metric_name_to_func[metric_name] |
241 | | - value = func( |
242 | | - template_upsampled, |
243 | | - sampling_frequency=sampling_frequency_up, |
244 | | - trough_idx=trough_idx, |
245 | | - peak_idx=peak_idx, |
246 | | - **self.params["metrics_kwargs"], |
247 | | - ) |
| 239 | + try: |
| 240 | + value = func( |
| 241 | + template_upsampled, |
| 242 | + sampling_frequency=sampling_frequency_up, |
| 243 | + trough_idx=trough_idx, |
| 244 | + peak_idx=peak_idx, |
| 245 | + **self.params["metrics_kwargs"], |
| 246 | + ) |
| 247 | + except Exception as e: |
| 248 | + warnings.warn(f"Error computing metric {metric_name} for unit {unit_id}: {e}") |
| 249 | + value = np.nan |
248 | 250 | template_metrics.at[index, metric_name] = value |
249 | 251 |
|
250 | 252 | # compute metrics multi_channel |
@@ -274,12 +276,16 @@ def _compute_metrics(self, sorting_analyzer, unit_ids=None, verbose=False, **job |
274 | 276 | sampling_frequency_up = sampling_frequency |
275 | 277 |
|
276 | 278 | func = _metric_name_to_func[metric_name] |
277 | | - value = func( |
278 | | - template_upsampled, |
279 | | - channel_locations=channel_locations_sparse, |
280 | | - sampling_frequency=sampling_frequency_up, |
281 | | - **self.params["metrics_kwargs"], |
282 | | - ) |
| 279 | + try: |
| 280 | + value = func( |
| 281 | + template_upsampled, |
| 282 | + channel_locations=channel_locations_sparse, |
| 283 | + sampling_frequency=sampling_frequency_up, |
| 284 | + **self.params["metrics_kwargs"], |
| 285 | + ) |
| 286 | + except Exception as e: |
| 287 | + warnings.warn(f"Error computing metric {metric_name} for unit {unit_id}: {e}") |
| 288 | + value = np.nan |
283 | 289 | template_metrics.at[index, metric_name] = value |
284 | 290 | return template_metrics |
285 | 291 |
|
|
0 commit comments