Skip to content

Commit

Permalink
Fix NpySnippets
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoe91 committed Oct 2, 2023
1 parent cf65301 commit 8343d3a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/spikeinterface/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def __init__(self, main_ids: Sequence) -> None:
# 'main_ids' will either be channel_ids or units_ids
# They is used for properties
self._main_ids = np.array(main_ids)
assert self._main_ids.dtype.kind in "uiSU", "Main IDs can only be integers (signed/unsigned) or strings"
if len(self._main_ids) > 0:
assert self._main_ids.dtype.kind in "uiSU", "Main IDs can only be integers (signed/unsigned) or strings"

# dict at object level
self._annotations = {}
Expand Down
4 changes: 2 additions & 2 deletions src/spikeinterface/core/baserecordingsnippets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations
from pathlib import Path

import numpy as np
Expand All @@ -19,7 +19,7 @@ class BaseRecordingSnippets(BaseExtractor):

has_default_locations = False

def __init__(self, sampling_frequency: float, channel_ids: List, dtype):
def __init__(self, sampling_frequency: float, channel_ids: list[str, int], dtype: np.dtype):
BaseExtractor.__init__(self, channel_ids)
self._sampling_frequency = sampling_frequency
self._dtype = np.dtype(dtype)
Expand Down
2 changes: 0 additions & 2 deletions src/spikeinterface/core/basesnippets.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import List, Union
from pathlib import Path
from .base import BaseSegment
from .baserecordingsnippets import BaseRecordingSnippets
import numpy as np
from warnings import warn
from probeinterface import Probe, ProbeGroup, write_probeinterface, read_probeinterface, select_axes

# snippets segments?

Expand Down
5 changes: 4 additions & 1 deletion src/spikeinterface/core/npysnippetsextractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def __init__(
num_segments = len(file_paths)
data = np.load(file_paths[0], mmap_mode="r")

if channel_ids is None:
channel_ids = np.arange(data["snippet"].shape[2])

BaseSnippets.__init__(
self,
sampling_frequency,
Expand Down Expand Up @@ -84,7 +87,7 @@ def write_snippets(snippets, file_paths, dtype=None):
arr = np.empty(n, dtype=snippets_t, order="F")
arr["frame"] = snippets.get_frames(segment_index=i)
arr["snippet"] = snippets.get_snippets(segment_index=i).astype(dtype, copy=False)

file_paths[i].parent.mkdir(parents=True, exist_ok=True)
np.save(file_paths[i], arr)


Expand Down

0 comments on commit 8343d3a

Please sign in to comment.