Skip to content

Commit

Permalink
Remove SharedMemory from SortingAnalyzer and use NumpySorting instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgarcia committed May 3, 2024
1 parent fa710f1 commit fea6cb4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/spikeinterface/core/numpyextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ 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)
return sorting
Expand Down
17 changes: 8 additions & 9 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,8 @@ 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,11 +538,9 @@ 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
if recording is None:
Expand Down

0 comments on commit fea6cb4

Please sign in to comment.