-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add neuronexus allego recording Extractor #3235
Changes from all commits
bef2c05
9040d8b
359e524
ad61187
3fc601a
1d64fc7
1dea1cf
98d2f7f
9316ad6
00ad144
8c99c87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from spikeinterface.core.core_tools import define_function_from_class | ||
|
||
from .neobaseextractor import NeoBaseRecordingExtractor, NeoBaseSortingExtractor | ||
|
||
|
||
class NeuroNexusRecordingExtractor(NeoBaseRecordingExtractor): | ||
""" | ||
Class for reading data from NeuroNexus Allego. | ||
|
||
Based on :py:class:`neo.rawio.NeuronexusRawIO` | ||
|
||
Parameters | ||
---------- | ||
file_path : str | Path | ||
The file path to the metadata .xdat.json file of an Allego session | ||
stream_id : str | None, default: None | ||
If there are several streams, specify the stream id you want to load. | ||
stream_name : str | None, default: None | ||
If there are several streams, specify the stream name you want to load. | ||
all_annotations : bool, default: False | ||
Load exhaustively all annotations from neo. | ||
use_names_as_ids : bool, default: False | ||
Determines the format of the channel IDs used by the extractor. If set to True, the channel IDs will be the | ||
names from NeoRawIO. If set to False, the channel IDs will be the ids provided by NeoRawIO. | ||
|
||
In Neuronexus the ids provided by NeoRawIO are the hardware channel ids stored as `ntv_chan_name` within | ||
the metada and the names are the `chan_names` | ||
|
||
|
||
""" | ||
|
||
NeoRawIOClass = "NeuroNexusRawIO" | ||
|
||
def __init__( | ||
self, | ||
file_path: str | Path, | ||
stream_id: str | None = None, | ||
stream_name: str | None = None, | ||
all_annotations: bool = False, | ||
use_names_as_ids: bool = False, | ||
): | ||
neo_kwargs = self.map_to_neo_kwargs(file_path) | ||
NeoBaseRecordingExtractor.__init__( | ||
self, | ||
stream_id=stream_id, | ||
stream_name=stream_name, | ||
all_annotations=all_annotations, | ||
use_names_as_ids=use_names_as_ids, | ||
**neo_kwargs, | ||
) | ||
|
||
self._kwargs.update(dict(file_path=str(Path(file_path).resolve()))) | ||
|
||
@classmethod | ||
def map_to_neo_kwargs(cls, file_path): | ||
|
||
neo_kwargs = {"filename": str(file_path)} | ||
|
||
return neo_kwargs | ||
|
||
|
||
read_neuronexus = define_function_from_class(source_class=NeuroNexusRecordingExtractor, name="read_neuronexus") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,8 +52,11 @@ def test_open(self): | |
num_samples = rec.get_num_samples(segment_index=segment_index) | ||
|
||
full_traces = rec.get_traces(segment_index=segment_index) | ||
assert full_traces.shape == (num_samples, num_chans) | ||
assert full_traces.dtype == dtype | ||
assert full_traces.shape == ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something I like to do is to write expected_shape = (num_samples, num_channels) and then do the assertion so if I Jump in the debugger I have all the variables already loaded. But I think this is OK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I didn't change anything here. I was just getting an error and couldn't see what it was so I rage added this :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I realize, just sharing a pattern. I was going to suggest adding string to the message but this is the testing suite so I think this is fine and your addition is an improvement. |
||
num_samples, | ||
num_chans, | ||
), f"{full_traces.shape} != {(num_samples, num_chans)}" | ||
assert full_traces.dtype == dtype, f"{full_traces.dtype} != {dtype=}" | ||
|
||
traces_sample_first = rec.get_traces(segment_index=segment_index, start_frame=0, end_frame=1) | ||
assert traces_sample_first.shape == (1, num_chans) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we provide an illustrative examples of the names or are they too variable so giving a pattern does not make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't know the pattern super well. We only have the one test file at Neo, so I could write something, but I'm not confident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you think it is still worth putting and I can combine your two pieces of feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Na, let's do it when we know more. No point in adding possible confusing message.