Skip to content
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

Merged
merged 11 commits into from
Oct 9, 2024
2 changes: 2 additions & 0 deletions src/spikeinterface/extractors/neoextractors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .mearec import MEArecRecordingExtractor, MEArecSortingExtractor, read_mearec
from .mcsraw import MCSRawRecordingExtractor, read_mcsraw
from .neuralynx import NeuralynxRecordingExtractor, NeuralynxSortingExtractor, read_neuralynx, read_neuralynx_sorting
from .neuronexus import NeuronexusRecordingExtractor, read_neuronexus
zm711 marked this conversation as resolved.
Show resolved Hide resolved
from .neuroscope import (
NeuroScopeRecordingExtractor,
NeuroScopeSortingExtractor,
Expand Down Expand Up @@ -54,6 +55,7 @@
MCSRawRecordingExtractor,
NeuralynxRecordingExtractor,
NeuroScopeRecordingExtractor,
NeuronexusRecordingExtractor,
zm711 marked this conversation as resolved.
Show resolved Hide resolved
NixRecordingExtractor,
OpenEphysBinaryRecordingExtractor,
OpenEphysLegacyRecordingExtractor,
Expand Down
66 changes: 66 additions & 0 deletions src/spikeinterface/extractors/neoextractors/neuronexus.py
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can take path as well, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because we cast it to a path to resolve. I can add that :)

h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved
The file path to the metadata .xdat.json file of an Allego session
stream_id : str, default: None
If there are several streams, specify the stream id you want to load.
stream_name : str, 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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str or Path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type hints while Sam is away. haha.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I thought that he was against doing them himself I was not aware he dislikes them in principle : O

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now you know :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x D

Ah, OK, disregard

stream_id=None,
stream_name=None,
all_annotations=False,
use_names_as_ids=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).absolute())))
h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved

@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")
8 changes: 8 additions & 0 deletions src/spikeinterface/extractors/tests/test_neoextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ class NeuroScopeSortingTest(SortingCommonTestSuite, unittest.TestCase):
]


class NeuronexusRecordingTest(RecordingCommonTestSuite, unittest.TestCase):
zm711 marked this conversation as resolved.
Show resolved Hide resolved
ExtractorClass = NeuronexusRecordingExtractor
downloads = ["neuronexus"]
entities = [
("neuronexus/allego_1/allego_2__uid0701-13-04-49.xdat.json", {"stream_id": "0"}),
]


class PlexonRecordingTest(RecordingCommonTestSuite, unittest.TestCase):
ExtractorClass = PlexonRecordingExtractor
downloads = ["plexon"]
Expand Down
Loading