Skip to content

Commit

Permalink
Merge pull request #2801 from samuelgarcia/analyzer_sharedlmem
Browse files Browse the repository at this point in the history
Remove SharedMemory from SortingAnalyzer and use NumpySorting instead.
  • Loading branch information
alejoe91 authored May 3, 2024
2 parents fa710f1 + 25dd6d3 commit 42e1f02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/spikeinterface/core/numpyextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ def from_sorting(source_sorting: BaseSorting, with_metadata=False, copy_spike_ve
spike_vector = source_sorting.to_spike_vector()
if copy_spike_vector:
spike_vector = spike_vector.copy()
sorting = NumpySorting(spike_vector, source_sorting.get_sampling_frequency(), source_sorting.unit_ids)
sorting = NumpySorting(spike_vector, source_sorting.get_sampling_frequency(), source_sorting.unit_ids.copy())
if with_metadata:
sorting.copy_metadata(source_sorting)
source_sorting.copy_metadata(sorting)
return sorting

@staticmethod
Expand Down
19 changes: 11 additions & 8 deletions src/spikeinterface/core/sortinganalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .recording_tools import check_probe_do_not_overlap, get_rec_attributes
from .core_tools import check_json, retrieve_importing_provenance
from .job_tools import split_job_kwargs
from .numpyextractors import SharedMemorySorting
from .numpyextractors import NumpySorting
from .sparsity import ChannelSparsity, estimate_sparsity
from .sortingfolder import NumpyFolderSorting
from .zarrextractors import get_default_zarr_compressor, ZarrSortingExtractor
Expand Down Expand Up @@ -296,8 +296,9 @@ def create_memory(cls, sorting, recording, sparsity, return_scaled, rec_attribut
# a copy is done to avoid shared dict between instances (which can block garbage collector)
rec_attributes = rec_attributes.copy()

# a copy of sorting is created directly in shared memory format to avoid further duplication of spikes.
sorting_copy = SharedMemorySorting.from_sorting(sorting, with_metadata=True)
# a copy of sorting is copied in memory for fast access
sorting_copy = NumpySorting.from_sorting(sorting, with_metadata=True, copy_spike_vector=True)

sorting_analyzer = SortingAnalyzer(
sorting=sorting_copy,
recording=recording,
Expand Down Expand Up @@ -375,8 +376,10 @@ def load_from_binary_folder(cls, folder, recording=None):
folder = Path(folder)
assert folder.is_dir(), f"This folder does not exists {folder}"

# load internal sorting copy and make it sharedmem
sorting = SharedMemorySorting.from_sorting(NumpyFolderSorting(folder / "sorting"), with_metadata=True)
# load internal sorting copy in memory
sorting = NumpySorting.from_sorting(
NumpyFolderSorting(folder / "sorting"), with_metadata=True, copy_spike_vector=True
)

# load recording if possible
if recording is None:
Expand Down Expand Up @@ -537,10 +540,10 @@ def load_from_zarr(cls, folder, recording=None):

zarr_root = zarr.open(folder, mode="r")

# load internal sorting and make it sharedmem
# load internal sorting in memory
# TODO propagate storage_options
sorting = SharedMemorySorting.from_sorting(
ZarrSortingExtractor(folder, zarr_group="sorting"), with_metadata=True
sorting = NumpySorting.from_sorting(
ZarrSortingExtractor(folder, zarr_group="sorting"), with_metadata=True, copy_spike_vector=True
)

# load recording if possible
Expand Down

0 comments on commit 42e1f02

Please sign in to comment.