Skip to content

Commit 669aff8

Browse files
committed
Merge branch 'main' of github.com:SpikeInterface/spikeinterface into reset-times
2 parents 8c0ff56 + c240155 commit 669aff8

5 files changed

Lines changed: 33 additions & 20 deletions

File tree

src/spikeinterface/core/core_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def is_dict_extractor(d: dict) -> bool:
201201
extractor_dict_element = namedtuple(typename="extractor_dict_element", field_names=["value", "name", "access_path"])
202202

203203

204-
def extractor_dict_iterator(extractor_dict: dict) -> Generator[extractor_dict_element]:
204+
def extractor_dict_iterator(extractor_dict: dict) -> Generator[extractor_dict_element, None, None]:
205205
"""
206206
Iterator for recursive traversal of a dictionary.
207207
This function explores the dictionary recursively and yields the path to each value along with the value itself.

src/spikeinterface/core/recording_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _init_binary_worker(recording, file_path_dict, dtype, byte_offest, cast_unsi
6969
def write_binary_recording(
7070
recording: "BaseRecording",
7171
file_paths: list[Path | str] | Path | str,
72-
dtype: np.ndtype = None,
72+
dtype: np.typing.DTypeLike = None,
7373
add_file_extension: bool = True,
7474
byte_offset: int = 0,
7575
auto_cast_uint: bool = True,

src/spikeinterface/generation/drift_tools.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ def interpolate_templates(templates_array, source_locations, dest_locations, int
4040
source_locations = np.asarray(source_locations)
4141
dest_locations = np.asarray(dest_locations)
4242
if dest_locations.ndim == 2:
43-
new_shape = templates_array.shape
43+
new_shape = (*templates_array.shape[:2], len(dest_locations))
4444
elif dest_locations.ndim == 3:
45-
new_shape = (dest_locations.shape[0],) + templates_array.shape
45+
new_shape = (
46+
dest_locations.shape[0],
47+
*templates_array.shape[:2],
48+
dest_locations.shape[1],
49+
)
4650
else:
4751
raise ValueError(f"Incorrect dimensions for dest_locations: {dest_locations.ndim}. Dimensions can be 2 or 3. ")
4852

src/spikeinterface/postprocessing/template_metrics.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
import numpy as np
1010
import warnings
11-
from typing import Optional
1211
from copy import deepcopy
1312

1413
from ..core.sortinganalyzer import register_result_extension, AnalyzerExtension
15-
from ..core import ChannelSparsity
1614
from ..core.template_tools import get_template_extremum_channel
1715
from ..core.template_tools import get_dense_templates_array
1816

@@ -238,13 +236,17 @@ def _compute_metrics(self, sorting_analyzer, unit_ids=None, verbose=False, **job
238236

239237
for metric_name in metrics_single_channel:
240238
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
248250
template_metrics.at[index, metric_name] = value
249251

250252
# compute metrics multi_channel
@@ -274,12 +276,16 @@ def _compute_metrics(self, sorting_analyzer, unit_ids=None, verbose=False, **job
274276
sampling_frequency_up = sampling_frequency
275277

276278
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
283289
template_metrics.at[index, metric_name] = value
284290
return template_metrics
285291

src/spikeinterface/qualitymetrics/quality_metric_calculator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ def _compute_metrics(self, sorting_analyzer, unit_ids=None, verbose=False, **job
164164
pc_metric_names = [k for k in metric_names if k in _possible_pc_metric_names]
165165
if len(pc_metric_names) > 0 and not self.params["skip_pc_metrics"]:
166166
if not sorting_analyzer.has_extension("principal_components"):
167-
raise ValueError("waveform_principal_component must be provied")
167+
raise ValueError(
168+
"To compute principal components base metrics, the principal components "
169+
"extension must be computed first."
170+
)
168171
pc_metrics = compute_pc_metrics(
169172
sorting_analyzer,
170173
unit_ids=non_empty_unit_ids,

0 commit comments

Comments
 (0)