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

WIP : add support for EMG data #1129

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
34 changes: 25 additions & 9 deletions mne_bids/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

DOI = """https://doi.org/10.21105/joss.01896"""

EPHY_ALLOWED_DATATYPES = ["meg", "eeg", "ieeg", "nirs"]
EPHY_ALLOWED_DATATYPES = ["meg", "eeg", "ieeg", "nirs", "emg"]

ALLOWED_DATATYPES = EPHY_ALLOWED_DATATYPES + ["anat", "beh"]

Expand Down Expand Up @@ -84,6 +84,8 @@
".EEG": "Nihon Kohden",
}

emg_manufacturers = {} # TODO

nirs_manufacturers = {".snirf": "SNIRF"}

# file-extension map to mne-python readers
Expand Down Expand Up @@ -115,6 +117,7 @@
MANUFACTURERS = dict()
MANUFACTURERS.update(meg_manufacturers)
MANUFACTURERS.update(eeg_manufacturers)
MANUFACTURERS.update(emg_manufacturers)
MANUFACTURERS.update(ieeg_manufacturers)
MANUFACTURERS.update(nirs_manufacturers)

Expand All @@ -135,6 +138,10 @@
".set", # EEGLAB, potentially accompanied by .fdt
]

allowed_extensions_emg = [
".edf", # European Data Format
]

allowed_extensions_ieeg = [
".vhdr", # BrainVision, accompanied by .vmrk, .eeg
".edf", # European Data Format
Expand All @@ -151,6 +158,7 @@
ALLOWED_DATATYPE_EXTENSIONS = {
"meg": allowed_extensions_meg,
"eeg": allowed_extensions_eeg,
"emg": allowed_extensions_emg,
"ieeg": allowed_extensions_ieeg,
"nirs": allowed_extensions_nirs,
}
Expand All @@ -169,26 +177,31 @@
# allowed suffixes (i.e. last "_" delimiter in the BIDS filenames before
# the extension)
ALLOWED_FILENAME_SUFFIX = [
# datatypes:
"meg",
"markers",
"eeg",
"ieeg",
"emg",
"nirs",
"T1w",
"FLASH", # datatype
"FLASH",
# sidecars:
"participants",
"scans",
"sessions",
"electrodes",
"optodes",
"channels",
"coordsystem",
"events", # sidecars
"events",
# MEG-specific sidecars:
"headshape",
"digitizer", # meg-specific sidecars
"digitizer",
# behavioral:
"beh",
"physio",
"stim", # behavioral
"nirs",
"stim",
]

# converts suffix to known path modalities
Expand All @@ -199,6 +212,7 @@
"markers": "meg",
"eeg": "eeg",
"ieeg": "ieeg",
"emg": "emg",
"T1w": "anat",
"FLASH": "anat",
}
Expand All @@ -207,9 +221,9 @@
ALLOWED_FILENAME_EXTENSIONS = (
ALLOWED_INPUT_EXTENSIONS
+ [".json", ".tsv", ".tsv.gz", ".nii", ".nii.gz"]
+ [".pos", ".eeg", ".vmrk"]
+ [".dat", ".EEG"] # extra datatype-specific metadata files.
+ [".mrk"] # extra eeg extensions # KIT/Yokogawa/Ricoh marker coil
+ [".pos", ".eeg", ".vmrk"] # extra datatype-specific metadata files.
+ [".dat", ".EEG"] # extra eeg extensions
+ [".mrk"] # KIT/Yokogawa/Ricoh marker coil
)

# allowed BIDSPath entities
Expand Down Expand Up @@ -313,6 +327,7 @@
+ BIDS_EEG_COORDINATE_FRAMES
)
ALLOWED_SPACES["ieeg"] = BIDS_SHARED_COORDINATE_FRAMES + BIDS_IEEG_COORDINATE_FRAMES
ALLOWED_SPACES["emg"] = None # TODO revise if we support digitization of EMG sensors
ALLOWED_SPACES["anat"] = None
ALLOWED_SPACES["beh"] = None

Expand Down Expand Up @@ -486,6 +501,7 @@
"Pollonini, L. (2023). fNIRS-BIDS, the Brain Imaging Data Structure "
"Extended to Functional Near-Infrared Spectroscopy. PsyArXiv. "
"https://doi.org/10.31219/osf.io/7nmcp",
"emg": "In preparation",
}


Expand Down
6 changes: 5 additions & 1 deletion mne_bids/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,13 @@ def _handle_datatype(raw, datatype):
datatypes.append("meg")
if "eeg" in raw:
datatypes.append("eeg")
if "emg" in raw:
datatypes.append("emg")
if "fnirs_cw_amplitude" in raw:
datatypes.append("nirs")
if len(datatypes) == 0:
raise ValueError(
"No MEG, EEG or iEEG channels found in data. "
"No MEG, EEG, iEEG, or EMG channels found in data. "
"Please use raw.set_channel_types to set the "
"channel types in the data."
)
Expand All @@ -172,6 +174,8 @@ def _handle_datatype(raw, datatype):
datatype = "meg"
elif "ieeg" in datatypes and "meg" not in datatypes:
datatype = "ieeg"
elif "emg" in datatypes:
datatype = "emg"
else:
raise ValueError(
f"Multiple data types (``{datatypes}``) were "
Expand Down
9 changes: 9 additions & 0 deletions mne_bids/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,13 @@ def _sidecar_json(
("Manufacturer", manufacturer),
]

ch_info_json_emg = [
# ("EEGReference", "n/a"),
# ("EEGGround", "n/a"),
# ("EEGPlacementScheme", _infer_eeg_placement_scheme(raw)),
# ("Manufacturer", manufacturer)
]

ch_info_json_ieeg = [
("iEEGReference", "n/a"),
("ECOGChannelCount", n_ecogchan),
Expand Down Expand Up @@ -1037,6 +1044,8 @@ def _sidecar_json(
append_datatype_json = ch_info_json_meg
elif datatype == "eeg":
append_datatype_json = ch_info_json_eeg
elif datatype == "emg":
append_datatype_json = ch_info_json_emg
elif datatype == "ieeg":
append_datatype_json = ch_info_json_ieeg
elif datatype == "nirs":
Expand Down