From bef2c05da80c617ea7ca6d5cef83796ce1d333ab Mon Sep 17 00:00:00 2001 From: zm711 <92116279+zm711@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:22:12 -0400 Subject: [PATCH 1/8] add neuronexus allego --- .../extractors/neoextractors/__init__.py | 2 + .../extractors/neoextractors/neuronexus.py | 66 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/spikeinterface/extractors/neoextractors/neuronexus.py diff --git a/src/spikeinterface/extractors/neoextractors/__init__.py b/src/spikeinterface/extractors/neoextractors/__init__.py index bf52de7c1d..5ecceb4b39 100644 --- a/src/spikeinterface/extractors/neoextractors/__init__.py +++ b/src/spikeinterface/extractors/neoextractors/__init__.py @@ -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 from .neuroscope import ( NeuroScopeRecordingExtractor, NeuroScopeSortingExtractor, @@ -54,6 +55,7 @@ MCSRawRecordingExtractor, NeuralynxRecordingExtractor, NeuroScopeRecordingExtractor, + NeuronexusRecordingExtractor, NixRecordingExtractor, OpenEphysBinaryRecordingExtractor, OpenEphysLegacyRecordingExtractor, diff --git a/src/spikeinterface/extractors/neoextractors/neuronexus.py b/src/spikeinterface/extractors/neoextractors/neuronexus.py new file mode 100644 index 0000000000..e8bf470e25 --- /dev/null +++ b/src/spikeinterface/extractors/neoextractors/neuronexus.py @@ -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 + 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 + 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, + 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()))) + + @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") From 9040d8b50e04fd4b2c8e2bf8d070ce9726dc7406 Mon Sep 17 00:00:00 2001 From: zm711 <92116279+zm711@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:34:26 -0400 Subject: [PATCH 2/8] add tests --- src/spikeinterface/extractors/tests/test_neoextractors.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/spikeinterface/extractors/tests/test_neoextractors.py b/src/spikeinterface/extractors/tests/test_neoextractors.py index acd7ebe8ad..450a06c4e9 100644 --- a/src/spikeinterface/extractors/tests/test_neoextractors.py +++ b/src/spikeinterface/extractors/tests/test_neoextractors.py @@ -181,6 +181,14 @@ class NeuroScopeSortingTest(SortingCommonTestSuite, unittest.TestCase): ] +class NeuronexusRecordingTest(RecordingCommonTestSuite, unittest.TestCase): + 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"] From 359e52496ea4df81899aa9bf09462913ffb718f1 Mon Sep 17 00:00:00 2001 From: zm711 <92116279+zm711@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:20:49 -0400 Subject: [PATCH 3/8] fix neuronexus name --- src/spikeinterface/extractors/neoextractors/neuronexus.py | 8 ++++---- src/spikeinterface/extractors/tests/test_neoextractors.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/extractors/neoextractors/neuronexus.py b/src/spikeinterface/extractors/neoextractors/neuronexus.py index e8bf470e25..1787320179 100644 --- a/src/spikeinterface/extractors/neoextractors/neuronexus.py +++ b/src/spikeinterface/extractors/neoextractors/neuronexus.py @@ -7,9 +7,9 @@ from .neobaseextractor import NeoBaseRecordingExtractor, NeoBaseSortingExtractor -class NeuronexusRecordingExtractor(NeoBaseRecordingExtractor): +class NeuroNexusRecordingExtractor(NeoBaseRecordingExtractor): """ - Class for reading data from Neuronexus Allego. + Class for reading data from NeuroNexus Allego. Based on :py:class:`neo.rawio.NeuronexusRawIO` @@ -33,7 +33,7 @@ class NeuronexusRecordingExtractor(NeoBaseRecordingExtractor): """ - NeoRawIOClass = "NeuronexusRawIO" + NeoRawIOClass = "NeuroNexusRawIO" def __init__( self, @@ -63,4 +63,4 @@ def map_to_neo_kwargs(cls, file_path): return neo_kwargs -read_neuronexus = define_function_from_class(source_class=NeuronexusRecordingExtractor, name="read_neuronexus") +read_neuronexus = define_function_from_class(source_class=NeuroNexusRecordingExtractor, name="read_neuronexus") diff --git a/src/spikeinterface/extractors/tests/test_neoextractors.py b/src/spikeinterface/extractors/tests/test_neoextractors.py index 450a06c4e9..98bbb1bf3d 100644 --- a/src/spikeinterface/extractors/tests/test_neoextractors.py +++ b/src/spikeinterface/extractors/tests/test_neoextractors.py @@ -182,7 +182,7 @@ class NeuroScopeSortingTest(SortingCommonTestSuite, unittest.TestCase): class NeuronexusRecordingTest(RecordingCommonTestSuite, unittest.TestCase): - ExtractorClass = NeuronexusRecordingExtractor + ExtractorClass = NeuroNexusRecordingExtractor downloads = ["neuronexus"] entities = [ ("neuronexus/allego_1/allego_2__uid0701-13-04-49.xdat.json", {"stream_id": "0"}), From ad61187a7c51868dc902770ec537b3a9ed61df58 Mon Sep 17 00:00:00 2001 From: zm711 <92116279+zm711@users.noreply.github.com> Date: Fri, 20 Sep 2024 08:24:15 -0400 Subject: [PATCH 4/8] Heberto feedback --- .../extractors/neoextractors/neuronexus.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/spikeinterface/extractors/neoextractors/neuronexus.py b/src/spikeinterface/extractors/neoextractors/neuronexus.py index 1787320179..bfaae7bf7f 100644 --- a/src/spikeinterface/extractors/neoextractors/neuronexus.py +++ b/src/spikeinterface/extractors/neoextractors/neuronexus.py @@ -17,9 +17,9 @@ class NeuroNexusRecordingExtractor(NeoBaseRecordingExtractor): ---------- file_path : str The file path to the metadata .xdat.json file of an Allego session - stream_id : str, default: None + stream_id : str | None, default: None If there are several streams, specify the stream id you want to load. - stream_name : str, default: None + 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. @@ -37,11 +37,11 @@ class NeuroNexusRecordingExtractor(NeoBaseRecordingExtractor): def __init__( self, - file_path, - stream_id=None, - stream_name=None, - all_annotations=False, - use_names_as_ids=False, + 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__( @@ -53,7 +53,7 @@ def __init__( **neo_kwargs, ) - self._kwargs.update(dict(file_path=str(Path(file_path).absolute()))) + self._kwargs.update(dict(file_path=str(Path(file_path).resolve()))) @classmethod def map_to_neo_kwargs(cls, file_path): From 3fc601a29359277fc4aaa11b750a30bb45ac6311 Mon Sep 17 00:00:00 2001 From: Zach McKenzie <92116279+zm711@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:58:15 -0400 Subject: [PATCH 5/8] Fix capitalization --- src/spikeinterface/extractors/neoextractors/__init__.py | 4 ++-- src/spikeinterface/extractors/tests/test_neoextractors.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/extractors/neoextractors/__init__.py b/src/spikeinterface/extractors/neoextractors/__init__.py index 5ecceb4b39..dfa947740b 100644 --- a/src/spikeinterface/extractors/neoextractors/__init__.py +++ b/src/spikeinterface/extractors/neoextractors/__init__.py @@ -9,7 +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 +from .neuronexus import NeuronNexusRecordingExtractor, read_neuronexus from .neuroscope import ( NeuroScopeRecordingExtractor, NeuroScopeSortingExtractor, @@ -55,7 +55,7 @@ MCSRawRecordingExtractor, NeuralynxRecordingExtractor, NeuroScopeRecordingExtractor, - NeuronexusRecordingExtractor, + NeuroNexusRecordingExtractor, NixRecordingExtractor, OpenEphysBinaryRecordingExtractor, OpenEphysLegacyRecordingExtractor, diff --git a/src/spikeinterface/extractors/tests/test_neoextractors.py b/src/spikeinterface/extractors/tests/test_neoextractors.py index 98bbb1bf3d..1251774fce 100644 --- a/src/spikeinterface/extractors/tests/test_neoextractors.py +++ b/src/spikeinterface/extractors/tests/test_neoextractors.py @@ -181,7 +181,7 @@ class NeuroScopeSortingTest(SortingCommonTestSuite, unittest.TestCase): ] -class NeuronexusRecordingTest(RecordingCommonTestSuite, unittest.TestCase): +class NeuroNexusRecordingTest(RecordingCommonTestSuite, unittest.TestCase): ExtractorClass = NeuroNexusRecordingExtractor downloads = ["neuronexus"] entities = [ From 1d64fc7014de581415b9aeadc39ef735b9dbc390 Mon Sep 17 00:00:00 2001 From: Zach McKenzie <92116279+zm711@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:03:11 -0400 Subject: [PATCH 6/8] oops --- src/spikeinterface/extractors/neoextractors/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/extractors/neoextractors/__init__.py b/src/spikeinterface/extractors/neoextractors/__init__.py index dfa947740b..03d517b46e 100644 --- a/src/spikeinterface/extractors/neoextractors/__init__.py +++ b/src/spikeinterface/extractors/neoextractors/__init__.py @@ -9,7 +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 NeuronNexusRecordingExtractor, read_neuronexus +from .neuronexus import NeuroNexusRecordingExtractor, read_neuronexus from .neuroscope import ( NeuroScopeRecordingExtractor, NeuroScopeSortingExtractor, From 1dea1cf512609e8ed8ebc0c1438caa8d3e5858be Mon Sep 17 00:00:00 2001 From: zm711 <92116279+zm711@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:29:19 -0400 Subject: [PATCH 7/8] add assert messaging --- src/spikeinterface/extractors/tests/common_tests.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/extractors/tests/common_tests.py b/src/spikeinterface/extractors/tests/common_tests.py index 5432efa9f3..61cfc2a153 100644 --- a/src/spikeinterface/extractors/tests/common_tests.py +++ b/src/spikeinterface/extractors/tests/common_tests.py @@ -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 == ( + 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) From 8c99c87a3529cc75b40acd88e0cee0ecd4891456 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Wed, 9 Oct 2024 14:53:48 -0600 Subject: [PATCH 8/8] Update src/spikeinterface/extractors/neoextractors/neuronexus.py Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/extractors/neoextractors/neuronexus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/extractors/neoextractors/neuronexus.py b/src/spikeinterface/extractors/neoextractors/neuronexus.py index bfaae7bf7f..dca482b28a 100644 --- a/src/spikeinterface/extractors/neoextractors/neuronexus.py +++ b/src/spikeinterface/extractors/neoextractors/neuronexus.py @@ -15,7 +15,7 @@ class NeuroNexusRecordingExtractor(NeoBaseRecordingExtractor): Parameters ---------- - file_path : str + 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.