Skip to content

Commit 8317eb5

Browse files
authored
Merge pull request #2606 from DradeAW/patch-2
Fix analyzer sampling frequency check
2 parents 265b62e + d1befac commit 8317eb5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/spikeinterface/core/sortinganalyzer.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from itertools import chain
66
import os
77
import json
8+
import math
89
import pickle
910
import weakref
1011
import shutil
@@ -237,7 +238,21 @@ def create(
237238
return_scaled=True,
238239
):
239240
# some checks
240-
assert sorting.sampling_frequency == recording.sampling_frequency
241+
if sorting.sampling_frequency != recording.sampling_frequency:
242+
if math.isclose(sorting.sampling_frequency, recording.sampling_frequency, abs_tol=1e-2, rel_tol=1e-5):
243+
warnings.warn(
244+
"Sorting and Recording have a small difference in sampling frequency. "
245+
"This could be due to rounding of floats. Using the sampling frequency from the Recording."
246+
)
247+
# we make a copy here to change the smapling frequency
248+
sorting = NumpySorting.from_sorting(sorting, with_metadata=True, copy_spike_vector=True)
249+
sorting._sampling_frequency = recording.sampling_frequency
250+
else:
251+
raise ValueError(
252+
f"Sorting and Recording sampling frequencies are too different: "
253+
f"recording: {recording.sampling_frequency} - sorting: {sorting.sampling_frequency}. "
254+
"Ensure that you are associating the correct Recording and Sorting when creating a SortingAnalyzer."
255+
)
241256
# check that multiple probes are non-overlapping
242257
all_probes = recording.get_probegroup().probes
243258
check_probe_do_not_overlap(all_probes)

0 commit comments

Comments
 (0)