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 skip channels to EDF interface #1110

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
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
32 changes: 29 additions & 3 deletions src/neuroconv/datainterfaces/ecephys/edf/edfdatainterface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from pydantic import FilePath

from ..baserecordingextractorinterface import BaseRecordingExtractorInterface
Expand All @@ -23,7 +25,22 @@ def get_source_schema(cls) -> dict:
source_schema["properties"]["file_path"]["description"] = "Path to the .edf file."
return source_schema

def __init__(self, file_path: FilePath, verbose: bool = True, es_key: str = "ElectricalSeries"):
def _source_data_to_extractor_kwargs(self, source_data: dict) -> dict:

extractor_kwargs = source_data.copy()
extractor_kwargs.pop("channels_to_skip")
extractor_kwargs["all_annotations"] = True
extractor_kwargs["use_names_as_ids"] = True
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bendichter
This is necessary to display meaningful names that the user can suppress with the newly added parameter. Otherwise, the channel ids are "1", "2", "3", etc.

This is technically a breaking change because we are changing the way we add the data to the NWBFile but I also consider this an improvement:

image


return extractor_kwargs

def __init__(
self,
file_path: FilePath,
verbose: bool = True,
es_key: str = "ElectricalSeries",
channels_to_skip: Optional[list] = None,
):
"""
Load and prepare data for EDF.
Currently, only continuous EDF+ files (EDF+C) and original EDF files (EDF) are supported
Expand All @@ -36,15 +53,24 @@ def __init__(self, file_path: FilePath, verbose: bool = True, es_key: str = "Ele
verbose : bool, default: True
Allows verbose.
es_key : str, default: "ElectricalSeries"
Key for the ElectricalSeries metadata
channels_to_skip : list, default: None
Channels to skip when adding the data to the nwbfile. These parameter can be used to skip non-neural
channels that are present in the EDF file.
"""
get_package(
package_name="pyedflib",
excluded_platforms_and_python_versions=dict(darwin=dict(arm=["3.8", "3.9"])),
excluded_platforms_and_python_versions=dict(darwin=dict(arm=["3.9"])),
h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved
)

super().__init__(file_path=file_path, verbose=verbose, es_key=es_key)
super().__init__(file_path=file_path, verbose=verbose, es_key=es_key, channels_to_skip=channels_to_skip)
self.edf_header = self.recording_extractor.neo_reader.edf_header

# We remove the channels that are not neural
if channels_to_skip:
self.recording_extractor = self.recording_extractor.remove_channels(remove_channel_ids=channels_to_skip)

def extract_nwb_file_metadata(self) -> dict:
nwbfile_metadata = dict(
session_start_time=self.edf_header["startdate"],
Expand Down
Loading