Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #564 from catalystneuro/add_spikeinterface_support…
Browse files Browse the repository at this point in the history
…_to_openephys

Add spikeinterface support to `OpenEphysRecordingExtractorInterface`
  • Loading branch information
CodyCBakerPhD authored Jul 1, 2022
2 parents 00d74e4 + 9017e99 commit 0cfc0d1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
4 changes: 2 additions & 2 deletions docs/conversion_examples_gallery/recording/openephys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Convert OpenEphys data to NWB using :py:class:`~nwb_conversion_tools.datainterfa
>>> folder_path = f"{ECEPHY_DATA_PATH}/openephysbinary/v0.4.4.1_with_video_tracking"
>>> # Change the folder_path to the appropiate location in your system
>>> interface = OpenEphysRecordingExtractorInterface(folder_path=folder_path, verbose=False)
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
Loading Open-Ephys: reading settings...
Decoding data from binary format
Reading oebin file
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # session_start_time is required for conversion. If it cannot be inferred
>>> # automatically from the source files you must supply one.
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific")).isoformat()
Expand Down
1 change: 1 addition & 0 deletions requirements-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ sonpy>=1.7.1
tiffile==2018.10.18
ndx-dandi-icephys>=0.4.0
pillow==9.1.1
pyopenephys==1.1.2
1 change: 1 addition & 0 deletions requirements-minimal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ roiextractors @ git+https://github.com/catalystneuro/roiextractors.git@1d50cbeb1
lxml>=4.6.5
scipy>=1.4.1
click # must be unspecified version to handle platform/pyVersion
pyopenephys>=1.1.2
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Authors: Luiz Tauffer."""
import pytz
import spikeextractors as se
"""Authors: Heberto Mayorquin, Luiz Tauffer."""
from typing import Optional

import pyopenephys
import spikeextractors as se
from spikeinterface.extractors import OpenEphysBinaryRecordingExtractor

from ..baserecordingextractorinterface import BaseRecordingExtractorInterface
from ..basesortingextractorinterface import BaseSortingExtractorInterface
from ....utils import get_schema_from_method_signature, FolderPathType
Expand All @@ -11,7 +13,7 @@
class OpenEphysRecordingExtractorInterface(BaseRecordingExtractorInterface):
"""Primary data interface class for converting a OpenEphysRecordingExtractor."""

RX = se.OpenEphysRecordingExtractor
RX = OpenEphysBinaryRecordingExtractor

@classmethod
def get_source_schema(cls):
Expand All @@ -27,27 +29,36 @@ def __init__(
folder_path: FolderPathType,
experiment_id: Optional[int] = 0,
recording_id: Optional[int] = 0,
stub_test: Optional[bool] = False,
stub_test: bool = False,
verbose: bool = True,
spikeextractors_backend: bool = False,
):
super().__init__(
folder_path=folder_path, experiment_id=experiment_id, recording_id=recording_id, verbose=verbose
)
self.spikeextractors_backend = spikeextractors_backend
if spikeextractors_backend:
self.RX = se.OpenEphysRecordingExtractor

super().__init__(
folder_path=folder_path, experiment_id=experiment_id, recording_id=recording_id, verbose=verbose
)

else:
super().__init__(folder_path=folder_path, verbose=verbose)

if stub_test:
self.subset_channels = [0, 1]

def get_metadata(self):
"""Auto-fill as much of the metadata as possible. Must comply with metadata schema."""
metadata = super().get_metadata()

# Open file and extract info
session_start_time = self.recording_extractor._fileobj.experiments[0].datetime
session_start_time_tzaware = pytz.timezone("EST").localize(session_start_time)

metadata["NWBFile"] = dict(
session_start_time=session_start_time_tzaware.strftime("%Y-%m-%dT%H:%M:%S"),
)
if self.spikeextractors_backend:
session_start_time = self.recording_extractor._fileobj.experiments[0].datetime
else:
folder_path = self.source_data["folder_path"]
fileobj = pyopenephys.File(folder_path)
session_start_time = fileobj.experiments[0].datetime

metadata["NWBFile"] = dict(session_start_time=session_start_time)
return metadata


Expand Down
21 changes: 16 additions & 5 deletions tests/test_on_data/test_gin_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@


def custom_name_func(testcase_func, param_num, param):
interface_name = param.kwargs["data_interface"].__name__
reduced_interface_name = interface_name.replace("Recording", "").replace("Interface", "").replace("Sorting", "")

return (
f"{testcase_func.__name__}_{param_num}_"
f"{parameterized.to_safe_name(param.kwargs['data_interface'].__name__)}"
f"{parameterized.to_safe_name(reduced_interface_name)}"
f"_{param.kwargs.get('case_name', '')}"
)

Expand Down Expand Up @@ -98,16 +101,24 @@ class TestConverter(NWBConverter):
data_interface=NeuralynxRecordingInterface,
interface_kwargs=dict(folder_path=str(DATA_PATH / "neuralynx" / "Cheetah_v5.7.4" / "original_data")),
),
param(
data_interface=OpenEphysRecordingExtractorInterface,
interface_kwargs=dict(folder_path=str(DATA_PATH / "openephysbinary" / "v0.4.4.1_with_video_tracking")),
),
param(
data_interface=AxonaRecordingExtractorInterface,
interface_kwargs=dict(file_path=str(DATA_PATH / "axona" / "axona_raw.bin")),
),
]

for spikeextractors_backend in [True, False]:
parameterized_recording_list.append(
param(
data_interface=OpenEphysRecordingExtractorInterface,
interface_kwargs=dict(
folder_path=str(DATA_PATH / "openephysbinary" / "v0.4.4.1_with_video_tracking"),
spikeextractors_backend=spikeextractors_backend,
),
case_name=f"spikeextractors_backend={spikeextractors_backend}",
)
)

for spikeextractors_backend in [True, False]:
parameterized_recording_list.append(
param(
Expand Down

0 comments on commit 0cfc0d1

Please sign in to comment.