From b954bd3737fb9665225ac214718e6bc084606e4d Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Thu, 10 Oct 2024 13:49:37 -0600 Subject: [PATCH 1/2] add skip channels to EDF interface --- .../ecephys/edf/edfdatainterface.py | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/neuroconv/datainterfaces/ecephys/edf/edfdatainterface.py b/src/neuroconv/datainterfaces/ecephys/edf/edfdatainterface.py index 119e9f8d2..ef169f66f 100644 --- a/src/neuroconv/datainterfaces/ecephys/edf/edfdatainterface.py +++ b/src/neuroconv/datainterfaces/ecephys/edf/edfdatainterface.py @@ -1,3 +1,5 @@ +from typing import Optional + from pydantic import FilePath from ..baserecordingextractorinterface import BaseRecordingExtractorInterface @@ -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 + + 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 @@ -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"])), ) - 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"], From 99fd8d6c23027d06d8fed816802bf48f26911dc2 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Thu, 10 Oct 2024 14:00:59 -0600 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c7bc13be..d748d79e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ## Features * Using in-house `GenericDataChunkIterator` [PR #1068](https://github.com/catalystneuro/neuroconv/pull/1068) * Data interfaces now perform source (argument inputs) validation with the json schema [PR #1020](https://github.com/catalystneuro/neuroconv/pull/1020) +* Added `channels_to_skip` to `EDFRecordingInterface` so the user can skip non-neural channels [PR #1110](https://github.com/catalystneuro/neuroconv/pull/1110) ## Improvements * Remove dev test from PR [PR #1092](https://github.com/catalystneuro/neuroconv/pull/1092)