Skip to content

Commit bbf7daf

Browse files
zm711h-mayorquin
andauthored
Add neuronexus allego recording Extractor (#3235)
* add neuronexus allego * add tests * fix neuronexus name * Heberto feedback * Fix capitalization * oops * add assert messaging * Update src/spikeinterface/extractors/neoextractors/neuronexus.py Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --------- Co-authored-by: Heberto Mayorquin <h.mayorquin@gmail.com>
1 parent 275e501 commit bbf7daf

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

src/spikeinterface/extractors/neoextractors/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .mearec import MEArecRecordingExtractor, MEArecSortingExtractor, read_mearec
1010
from .mcsraw import MCSRawRecordingExtractor, read_mcsraw
1111
from .neuralynx import NeuralynxRecordingExtractor, NeuralynxSortingExtractor, read_neuralynx, read_neuralynx_sorting
12+
from .neuronexus import NeuroNexusRecordingExtractor, read_neuronexus
1213
from .neuroscope import (
1314
NeuroScopeRecordingExtractor,
1415
NeuroScopeSortingExtractor,
@@ -54,6 +55,7 @@
5455
MCSRawRecordingExtractor,
5556
NeuralynxRecordingExtractor,
5657
NeuroScopeRecordingExtractor,
58+
NeuroNexusRecordingExtractor,
5759
NixRecordingExtractor,
5860
OpenEphysBinaryRecordingExtractor,
5961
OpenEphysLegacyRecordingExtractor,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
5+
from spikeinterface.core.core_tools import define_function_from_class
6+
7+
from .neobaseextractor import NeoBaseRecordingExtractor, NeoBaseSortingExtractor
8+
9+
10+
class NeuroNexusRecordingExtractor(NeoBaseRecordingExtractor):
11+
"""
12+
Class for reading data from NeuroNexus Allego.
13+
14+
Based on :py:class:`neo.rawio.NeuronexusRawIO`
15+
16+
Parameters
17+
----------
18+
file_path : str | Path
19+
The file path to the metadata .xdat.json file of an Allego session
20+
stream_id : str | None, default: None
21+
If there are several streams, specify the stream id you want to load.
22+
stream_name : str | None, default: None
23+
If there are several streams, specify the stream name you want to load.
24+
all_annotations : bool, default: False
25+
Load exhaustively all annotations from neo.
26+
use_names_as_ids : bool, default: False
27+
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the
28+
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO.
29+
30+
In Neuronexus the ids provided by NeoRawIO are the hardware channel ids stored as `ntv_chan_name` within
31+
the metada and the names are the `chan_names`
32+
33+
34+
"""
35+
36+
NeoRawIOClass = "NeuroNexusRawIO"
37+
38+
def __init__(
39+
self,
40+
file_path: str | Path,
41+
stream_id: str | None = None,
42+
stream_name: str | None = None,
43+
all_annotations: bool = False,
44+
use_names_as_ids: bool = False,
45+
):
46+
neo_kwargs = self.map_to_neo_kwargs(file_path)
47+
NeoBaseRecordingExtractor.__init__(
48+
self,
49+
stream_id=stream_id,
50+
stream_name=stream_name,
51+
all_annotations=all_annotations,
52+
use_names_as_ids=use_names_as_ids,
53+
**neo_kwargs,
54+
)
55+
56+
self._kwargs.update(dict(file_path=str(Path(file_path).resolve())))
57+
58+
@classmethod
59+
def map_to_neo_kwargs(cls, file_path):
60+
61+
neo_kwargs = {"filename": str(file_path)}
62+
63+
return neo_kwargs
64+
65+
66+
read_neuronexus = define_function_from_class(source_class=NeuroNexusRecordingExtractor, name="read_neuronexus")

src/spikeinterface/extractors/tests/common_tests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ def test_open(self):
5252
num_samples = rec.get_num_samples(segment_index=segment_index)
5353

5454
full_traces = rec.get_traces(segment_index=segment_index)
55-
assert full_traces.shape == (num_samples, num_chans)
56-
assert full_traces.dtype == dtype
55+
assert full_traces.shape == (
56+
num_samples,
57+
num_chans,
58+
), f"{full_traces.shape} != {(num_samples, num_chans)}"
59+
assert full_traces.dtype == dtype, f"{full_traces.dtype} != {dtype=}"
5760

5861
traces_sample_first = rec.get_traces(segment_index=segment_index, start_frame=0, end_frame=1)
5962
assert traces_sample_first.shape == (1, num_chans)

src/spikeinterface/extractors/tests/test_neoextractors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ class NeuroScopeSortingTest(SortingCommonTestSuite, unittest.TestCase):
181181
]
182182

183183

184+
class NeuroNexusRecordingTest(RecordingCommonTestSuite, unittest.TestCase):
185+
ExtractorClass = NeuroNexusRecordingExtractor
186+
downloads = ["neuronexus"]
187+
entities = [
188+
("neuronexus/allego_1/allego_2__uid0701-13-04-49.xdat.json", {"stream_id": "0"}),
189+
]
190+
191+
184192
class PlexonRecordingTest(RecordingCommonTestSuite, unittest.TestCase):
185193
ExtractorClass = PlexonRecordingExtractor
186194
downloads = ["plexon"]

0 commit comments

Comments
 (0)