Skip to content

Commit 7487236

Browse files
h-mayorquinclaude
andauthored
Add copy_sorting option to SortingAnalyzer.create_memory (#4668)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2e56462 commit 7487236

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/spikeinterface/core/sortinganalyzer.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,9 @@ def load(cls, folder, recording=None, load_extensions=True, format="auto", backe
592592
return sorting_analyzer
593593

594594
@classmethod
595-
def create_memory(cls, sorting, recording, sparsity, return_in_uV, peak_sign, peak_mode, rec_attributes):
595+
def create_memory(
596+
cls, sorting, recording, sparsity, return_in_uV, peak_sign, peak_mode, rec_attributes, copy_sorting=True
597+
):
596598
# used by create and save_as
597599

598600
if rec_attributes is None:
@@ -603,11 +605,17 @@ def create_memory(cls, sorting, recording, sparsity, return_in_uV, peak_sign, pe
603605
# a copy is done to avoid shared dict between instances (which can block garbage collector)
604606
rec_attributes = rec_attributes.copy()
605607

606-
# a copy of sorting is copied in memory for fast access
607-
sorting_copy = NumpySorting.from_sorting(sorting, with_metadata=True, copy_spike_vector=True)
608+
if copy_sorting:
609+
# a copy of sorting is materialized in memory for fast access
610+
analyzer_sorting = NumpySorting.from_sorting(sorting, with_metadata=True, copy_spike_vector=True)
611+
else:
612+
# keep the given (possibly lazy) sorting as-is: its spike times are read on demand rather
613+
# than materialized up front. Useful for large streamed sortings where a view may need only
614+
# a few units' trains (e.g. curation from stored templates + metrics).
615+
analyzer_sorting = sorting
608616

609617
sorting_analyzer = SortingAnalyzer(
610-
sorting=sorting_copy,
618+
sorting=analyzer_sorting,
611619
recording=recording,
612620
rec_attributes=rec_attributes,
613621
format="memory",

0 commit comments

Comments
 (0)