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 plexon2 recording, sorting and event support #1736

Merged
merged 16 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/build-test-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ runs:
tar xvzf git-annex-standalone-amd64.tar.gz
echo "$(pwd)/git-annex.linux" >> $GITHUB_PATH
shell: bash
- name: Install wine (needed for Plexon2)
run: |
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo dpkg --add-architecture i386
sudo apt-get update -qq
sudo apt-get install -yqq --allow-downgrades libc6:i386 libgcc-s1:i386 libstdc++6:i386 wine
shell: bash
Copy link
Member

Choose a reason for hiding this comment

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

This can be quite heavy and not needed (unless plexon2 wrapper changes). We could make a manual workflow that installs wine and tests plexon2 only.

Otherwise we can make an install_wine.yml action and install + run plexon2 tests only if plexon2 has changed.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extractors = [
"ONE-api>=1.19.1",
"ibllib>=2.21.0",
"pymatreader>=0.0.32", # For cell explorer matlab files
"zugbruecke", # For plexon2
]

streaming_extractors = [
Expand Down
18 changes: 16 additions & 2 deletions src/spikeinterface/extractors/neoextractors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
read_openephys_event,
)
from .plexon import PlexonRecordingExtractor, PlexonSortingExtractor, read_plexon, read_plexon_sorting
from .plexon2 import (
Plexon2SortingExtractor,
Plexon2RecordingExtractor,
Plexon2EventExtractor,
read_plexon2,
read_plexon2_sorting,
read_plexon2_event,
)
from .spike2 import Spike2RecordingExtractor, read_spike2
from .spikegadgets import SpikeGadgetsRecordingExtractor, read_spikegadgets
from .spikeglx import SpikeGLXRecordingExtractor, read_spikeglx
Expand All @@ -49,12 +57,18 @@
OpenEphysBinaryRecordingExtractor,
OpenEphysLegacyRecordingExtractor,
PlexonRecordingExtractor,
Plexon2RecordingExtractor,
Spike2RecordingExtractor,
SpikeGadgetsRecordingExtractor,
SpikeGLXRecordingExtractor,
TdtRecordingExtractor,
]

neo_sorting_extractors_list = [BlackrockSortingExtractor, MEArecSortingExtractor, NeuralynxSortingExtractor]
neo_sorting_extractors_list = [
BlackrockSortingExtractor,
MEArecSortingExtractor,
NeuralynxSortingExtractor,
Plexon2SortingExtractor,
]

neo_event_extractors_list = [AlphaOmegaEventExtractor, OpenEphysBinaryEventExtractor]
neo_event_extractors_list = [AlphaOmegaEventExtractor, OpenEphysBinaryEventExtractor, Plexon2EventExtractor]
103 changes: 103 additions & 0 deletions src/spikeinterface/extractors/neoextractors/plexon2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from spikeinterface.core.core_tools import define_function_from_class

from .neobaseextractor import NeoBaseRecordingExtractor, NeoBaseSortingExtractor, NeoBaseEventExtractor


class Plexon2RecordingExtractor(NeoBaseRecordingExtractor):
"""
Class for reading plexon pl2 files.

Based on :py:class:`neo.rawio.Plexon2RawIO`

Parameters
----------
file_path: str
The file path to load the recordings from.
stream_id: str, optional
If there are several streams, specify the stream id you want to load.
stream_name: str, optional
If there are several streams, specify the stream name you want to load.
all_annotations: bool, default: False
Load exhaustively all annotations from neo.
"""

mode = "file"
NeoRawIOClass = "Plexon2RawIO"
name = "plexon2"

def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=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, **neo_kwargs
)
self._kwargs.update({"file_path": str(file_path)})

@classmethod
def map_to_neo_kwargs(cls, file_path):
neo_kwargs = {"filename": str(file_path)}
return neo_kwargs


class Plexon2SortingExtractor(NeoBaseSortingExtractor):
"""
Class for reading plexon spiking data from .pl2 files.

Based on :py:class:`neo.rawio.Plexon2RawIO`

Parameters
----------
file_path: str
The file path to load the recordings from.
sampling_frequency: float, default: None
The sampling frequency of the sorting (required for multiple streams with different sampling frequencies).
"""

mode = "file"
NeoRawIOClass = "Plexon2RawIO"
neo_returns_frames = True
name = "plexon2"

def __init__(self, file_path, sampling_frequency=None):
from neo.rawio import Plexon2RawIO

neo_kwargs = self.map_to_neo_kwargs(file_path)
neo_reader = Plexon2RawIO(**neo_kwargs)
neo_reader.parse_header()
NeoBaseSortingExtractor.__init__(self, sampling_frequency=sampling_frequency, **neo_kwargs)
self._kwargs.update({"file_path": str(file_path), "sampling_frequency": sampling_frequency})

@classmethod
def map_to_neo_kwargs(cls, file_path):
neo_kwargs = {"filename": str(file_path)}
return neo_kwargs


class Plexon2EventExtractor(NeoBaseEventExtractor):
"""
Class for reading plexon spiking data from .pl2 files.

Based on :py:class:`neo.rawio.Plexon2RawIO`

Parameters
----------
folder_path: str

"""

mode = "file"
NeoRawIOClass = "Plexon2RawIO"
name = "plexon2"

def __init__(self, folder_path, block_index=None):
neo_kwargs = self.map_to_neo_kwargs(folder_path)
NeoBaseEventExtractor.__init__(self, block_index=block_index, **neo_kwargs)

@classmethod
def map_to_neo_kwargs(cls, folder_path):
neo_kwargs = {"filename": str(folder_path)}
return neo_kwargs


read_plexon2 = define_function_from_class(source_class=Plexon2RecordingExtractor, name="read_plexon2")
read_plexon2_sorting = define_function_from_class(source_class=Plexon2SortingExtractor, name="read_plexon2_sorting")
read_plexon2_event = define_function_from_class(source_class=Plexon2EventExtractor, name="read_plexon2_event")
24 changes: 23 additions & 1 deletion src/spikeinterface/extractors/tests/test_neoextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class NeuroScopeSortingTest(SortingCommonTestSuite, unittest.TestCase):
]


class Plexon2EventTest(EventCommonTestSuite, unittest.TestCase):
ExtractorClass = Plexon2EventExtractor
downloads = ["plexon"]
entities = [
("plexon/4chDemoPL2.pl2"),
]


class PlexonRecordingTest(RecordingCommonTestSuite, unittest.TestCase):
ExtractorClass = PlexonRecordingExtractor
downloads = ["plexon"]
Expand All @@ -129,6 +137,14 @@ class PlexonRecordingTest(RecordingCommonTestSuite, unittest.TestCase):
]


class Plexon2RecordingTest(RecordingCommonTestSuite, unittest.TestCase):
ExtractorClass = Plexon2RecordingExtractor
downloads = ["plexon"]
entities = [
("plexon/4chDemoPL2.pl2", {"stream_id": "3"}),
]


class PlexonSortingTest(SortingCommonTestSuite, unittest.TestCase):
ExtractorClass = PlexonSortingExtractor
downloads = ["plexon"]
Expand All @@ -137,6 +153,12 @@ class PlexonSortingTest(SortingCommonTestSuite, unittest.TestCase):
]


class Plexon2SortingTest(SortingCommonTestSuite, unittest.TestCase):
ExtractorClass = Plexon2SortingExtractor
downloads = ["plexon"]
entities = [("plexon/4chDemoPL2.pl2", {"sampling_frequency": 40000})]


class NeuralynxRecordingTest(RecordingCommonTestSuite, unittest.TestCase):
ExtractorClass = NeuralynxRecordingExtractor
downloads = ["neuralynx"]
Expand Down Expand Up @@ -304,7 +326,7 @@ def test_pickling(self):
# test = PlexonRecordingTest()
# test = PlexonSortingTest()
# test = NeuralynxRecordingTest()
test = BlackrockRecordingTest()
test = Plexon2RecordingTest()
# test = MCSRawRecordingTest()
# test = KiloSortSortingTest()
# test = Spike2RecordingTest()
Expand Down