Skip to content

Commit 4ce1622

Browse files
authored
Copy the recording from original sorting during NumpySorting.from_sorting() (#4417)
1 parent 8f79421 commit 4ce1622

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/spikeinterface/core/numpyextractors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ def from_sorting(source_sorting: BaseSorting, with_metadata=False, copy_spike_ve
281281
if copy_spike_vector:
282282
spike_vector = spike_vector.copy()
283283
sorting = NumpySorting(spike_vector, source_sorting.get_sampling_frequency(), source_sorting.unit_ids.copy())
284+
if source_sorting.has_recording():
285+
sorting._recording = source_sorting._recording
284286
if with_metadata:
285287
source_sorting.copy_metadata(sorting)
286288
return sorting

src/spikeinterface/core/sortinganalyzer.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def create(
354354
"Sorting and Recording have a small difference in sampling frequency. "
355355
"This could be due to rounding of floats. Using the sampling frequency from the Recording."
356356
)
357-
# we make a copy here to change the smapling frequency
357+
# we make a copy here to change the sampling frequency
358358
sorting = NumpySorting.from_sorting(sorting, with_metadata=True, copy_spike_vector=True)
359359
sorting._sampling_frequency = recording.sampling_frequency
360360
else:
@@ -491,7 +491,7 @@ def create_binary_folder(cls, folder, sorting, recording, sparsity, return_in_uV
491491
warnings.warn("The Recording is not serializable! The recording link will be lost for future load")
492492
else:
493493
assert rec_attributes is not None, "recording or rec_attributes must be provided"
494-
warnings.warn("Recording not provided, instntiating SortingAnalyzer in recordingless mode.")
494+
warnings.warn("Recording not provided, instantiating SortingAnalyzer in recordingless mode.")
495495

496496
if sorting.check_serializability("json"):
497497
sorting.dump(folder / "sorting_provenance.json", relative_to=folder)
@@ -543,21 +543,16 @@ def load_from_binary_folder(cls, folder, recording=None, backend_options=None):
543543
NumpyFolderSorting(folder / "sorting"), with_metadata=True, copy_spike_vector=True
544544
)
545545

546-
# load recording if possible
546+
# Try to load the recording if not provided
547547
if recording is None:
548-
# try to load the recording if not provided
549-
for type in ("json", "pickle"):
550-
filename = folder / f"recording.{type}"
548+
for file_ext in ("json", "pickle"):
549+
filename = folder / f"recording.{file_ext}"
551550
if filename.exists():
552551
try:
553552
recording = load(filename, base_folder=folder)
554553
break
555554
except:
556-
recording = None
557-
else:
558-
# TODO maybe maybe not??? : do we need to check attributes match internal rec_attributes
559-
# Note this will make the loading too slow
560-
pass
555+
pass
561556

562557
# recording attributes
563558
rec_attributes_file = folder / "recording_info" / "recording_attributes.json"

0 commit comments

Comments
 (0)