-
-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into dev-kim-bugfix
- Loading branch information
Showing
278 changed files
with
59,023 additions
and
2,002,553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
scripts/* linguist-vendored | ||
scripts/* linguist-vendored | ||
*.ipynb linguist-language=Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
# Number of days of inactivity before an issue becomes stale | ||
daysUntilStale: 180 | ||
# Number of days of inactivity before a stale issue is closed | ||
daysUntilClose: 180 | ||
# Issues with these labels will never be considered stale | ||
exemptLabels: | ||
- feature idea 🔥 | ||
- bug 🐛 | ||
# Label to use when marking an issue as stale | ||
staleLabel: inactive 👻 | ||
# Comment to post when marking an issue as stale. Set to `false` to disable | ||
markComment: > | ||
This issue has been automatically marked as inactive because it has not had | ||
recent activity. It will eventually be closed if no further activity occurs. | ||
# Comment to post when closing a stale issue. Set to `false` to disable | ||
closeComment: > | ||
This issue has been inactive for a long time. We're closing it (but feel free to reopen it if need be). | ||
# # Number of days of inactivity before an issue becomes stale | ||
# daysUntilStale: 180 | ||
# # Number of days of inactivity before a stale issue is closed | ||
# daysUntilClose: 180 | ||
# # Issues with these labels will never be considered stale | ||
# exemptLabels: | ||
# - feature idea 🔥 | ||
# - bug 🐛 | ||
# # Label to use when marking an issue as stale | ||
# staleLabel: inactive 👻 | ||
# # Comment to post when marking an issue as stale. Set to `false` to disable | ||
# markComment: > | ||
# This issue has been automatically marked as inactive because it has not had | ||
# recent activity. It will eventually be closed if no further activity occurs. | ||
# # Comment to post when closing a stale issue. Set to `false` to disable | ||
# closeComment: > | ||
# This issue has been inactive for a long time. We're closing it (but feel free to reopen it if need be). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
pull_request: | ||
branches: | ||
- master | ||
- dev | ||
push: | ||
|
||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Script for formatting the LEMON EEG dataset | ||
https://ftp.gwdg.de/pub/misc/MPI-Leipzig_Mind-Brain-Body-LEMON/EEG_MPILMBB_LEMON/EEG_Preprocessed_BIDS_ID/EEG_Preprocessed/ | ||
Steps: | ||
1. Download the ZIP database from https://physionet.org/content/nstdb/1.0.0/ | ||
2. Open it with a zip-opener (WinZip, 7zip). | ||
3. Extract the folder of the same name (named 'mit-bih-noise-stress-test-database-1.0.0') to the same folder as this script. | ||
4. Run this script. | ||
Credits: | ||
pycrostates package by Mathieu Scheltienne and Victor Férat | ||
""" | ||
import os | ||
|
||
import mne | ||
import numpy as np | ||
import pooch | ||
|
||
# Path of the database | ||
path = "https://ftp.gwdg.de/pub/misc/MPI-Leipzig_Mind-Brain-Body-LEMON/EEG_MPILMBB_LEMON/EEG_Preprocessed_BIDS_ID/EEG_Preprocessed/" | ||
|
||
# Create a registry with the file names | ||
files = { | ||
f"sub-01{i:04d}_{j}.{k}": None | ||
for i in range(2, 319) | ||
for j in ["EC", "EO"] | ||
for k in ["fdt", "set"] | ||
} | ||
|
||
# Create fetcher | ||
fetcher = pooch.create( | ||
path="lemon/", | ||
base_url=path, | ||
registry=files, | ||
) | ||
|
||
# Download the files | ||
for sub in files.keys(): | ||
try: | ||
_ = fetcher.fetch(sub) | ||
except: | ||
pass | ||
|
||
print("Finished downloading!") | ||
|
||
# Preprocessing | ||
|
||
# fmt: off | ||
standard_channels = [ | ||
"Fp1", "Fp2", "F7", "F3", "Fz", "F4", "F8", "FC5", | ||
"FC1", "FC2", "FC6", "T7", "C3", "Cz", "C4", "T8", | ||
"CP5", "CP1", "CP2", "CP6", "AFz", "P7", "P3", "Pz", | ||
"P4", "P8", "PO9", "O1", "Oz", "O2", "PO10", "AF7", | ||
"AF3", "AF4", "AF8", "F5", "F1", "F2", "F6", "FT7", | ||
"FC3", "FC4", "FT8", "C5", "C1", "C2", "C6", "TP7", | ||
"CP3", "CPz", "CP4", "TP8", "P5", "P1", "P2", "P6", | ||
"PO7", "PO3", "POz", "PO4", "PO8", | ||
] | ||
# fmt: on | ||
|
||
for sub in os.listdir("lemon/"): | ||
if sub.endswith("fdt") is True or sub.endswith("fif") or "sub" not in sub: | ||
continue | ||
raw = mne.io.read_raw_eeglab("lemon/" + sub, preload=True) | ||
|
||
missing_channels = list(set(standard_channels) - set(raw.info["ch_names"])) | ||
|
||
if len(missing_channels) != 0: | ||
# add the missing channels as bads (array of zeros) | ||
missing_data = np.zeros((len(missing_channels), raw.n_times)) | ||
data = np.vstack([raw.get_data(), missing_data]) | ||
ch_names = raw.info["ch_names"] + missing_channels | ||
ch_types = raw.get_channel_types() + ["eeg"] * len(missing_channels) | ||
info = mne.create_info(ch_names=ch_names, ch_types=ch_types, sfreq=raw.info["sfreq"]) | ||
raw = mne.io.RawArray(data=data, info=info) | ||
raw.info["bads"].extend(missing_channels) | ||
|
||
raw = raw.add_reference_channels("FCz") | ||
raw = raw.reorder_channels(standard_channels) | ||
raw = raw.set_montage("standard_1005") | ||
raw = raw.interpolate_bads() | ||
raw = raw.set_eeg_reference("average").apply_proj() | ||
|
||
raw.save("lemon/" + sub.replace(".set", "") + "_raw.fif", overwrite=True) | ||
|
||
|
||
# Clean-up | ||
for sub in os.listdir("lemon/"): | ||
if sub.endswith("fif"): | ||
continue | ||
os.remove(f"lemon/{sub}") | ||
|
||
print("FINISHED.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
https://openneuro.org/datasets/ds003775/versions/1.0.0 | ||
""" | ||
import os | ||
import shutil | ||
|
||
import mne | ||
import numpy as np | ||
import openneuro as on | ||
|
||
import neurokit2 as nk | ||
|
||
# Download cleaned data (takes some time) | ||
on.download( | ||
dataset="ds003775", | ||
target_dir="eeg/raw", | ||
include="sub-*", | ||
exclude="derivatives/cleaned_data", | ||
) | ||
|
||
# Convert to MNE | ||
path = "eeg/raw/" | ||
for sub in os.listdir(path): | ||
if "sub" not in sub: | ||
continue | ||
print(f"Participant: {sub}") | ||
file = [f for f in os.listdir(path + sub + "/ses-t1/eeg/") if ".edf" in f][0] | ||
raw = mne.io.read_raw_edf(path + sub + "/ses-t1/eeg/" + file, preload=True, verbose=False) | ||
raw = raw.set_montage("biosemi64") | ||
|
||
# Clean | ||
raw = raw.notch_filter(freqs=np.arange(50, 501, 50), verbose=False) | ||
raw.info["bads"], _ = nk.eeg_badchannels( | ||
raw, bad_threshold=0.33, distance_threshold=0.99, show=False | ||
) | ||
print("Bad channels: " + str(len(raw.info['bads']))) | ||
raw = raw.interpolate_bads() | ||
|
||
raw.save("eeg/" + sub + "_raw.fif", overwrite=True) | ||
|
||
print("FINISHED.") | ||
|
||
# Clean-up | ||
shutil.rmtree("eeg/raw/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" | ||
https://openneuro.org/datasets/ds003685/ | ||
""" | ||
import os | ||
import re | ||
import shutil | ||
|
||
import mne | ||
import numpy as np | ||
import openneuro as on | ||
|
||
import neurokit2 as nk | ||
|
||
# Download cleaned data (takes some time) | ||
on.download( | ||
dataset="ds003685", | ||
target_dir="eeg/raw", | ||
include="sub-*/ses-session1/*eyes*", | ||
) | ||
|
||
# Convert to MNE | ||
path = "eeg/raw/" | ||
for sub in os.listdir(path): | ||
if "sub" not in sub or "sub-60" in sub: | ||
continue | ||
print(f"Participant: {sub}") | ||
newpath = path + sub + "/ses-session1/eeg/" | ||
|
||
# The header file is broken as the name in it is incorrect | ||
# ------------------------------------------------------------------------- | ||
for file in [f for f in os.listdir(newpath) if ".vmrk" in f]: | ||
with open(newpath + file, "r+") as f: | ||
text = f.read() # read everything in the file | ||
pattern = re.search("DataFile=.*\\n", text).group(0) | ||
text = text.replace(pattern, pattern.replace(" ", "")) | ||
with open(newpath + file, "r+") as f: | ||
f.write(text) | ||
|
||
for file in [f for f in os.listdir(newpath) if ".vhdr" in f]: | ||
|
||
with open(newpath + file, "r+") as f: | ||
text = f.read() # read everything in the file | ||
pattern = re.search("DataFile=.*\\n", text).group(0) | ||
text = text.replace(pattern, pattern.replace(" ", "")) | ||
pattern = re.search("MarkerFile=.*\\n", text).group(0) | ||
text = text.replace(pattern, pattern.replace(" ", "")) | ||
with open(newpath + file, "r+") as f: | ||
f.write(text) | ||
# ------------------------------------------------------------------------- | ||
|
||
raw = mne.io.read_raw_brainvision(newpath + file, preload=True, verbose=False) | ||
raw = raw.set_eeg_reference("average") | ||
# raw = raw.set_montage("biosemi64") | ||
if "eyesopen" in file: | ||
raw.save("eeg/" + sub + "_eyesopen_raw.fif", overwrite=True) | ||
else: | ||
raw.save("eeg/" + sub + "_eyesclosed_raw.fif", overwrite=True) | ||
|
||
print("FINISHED.") | ||
# Clean-up | ||
shutil.rmtree("eeg/raw/") |
Oops, something went wrong.