Skip to content
Snippets Groups Projects
Commit bbddfde7 authored by s200431's avatar s200431
Browse files

Main code for data preprocessing and feature estimation

parent b930aea4
Branches
No related tags found
No related merge requests found
......@@ -36,14 +36,14 @@ the different parts easier (Default shortcut: Ctrl + Shift + O)
# Set working directory
import os
wkdir = "/Users/benj3542/Desktop/Uni/Noter/Semester_6/Bachelor/resting-state-eeg-analysis/"
wkdir = "/home/s200431"
os.chdir(wkdir)
# Load all libraries from the Preamble
from Preamble import *
# %% Load preprocessed epochs and questionnaire data
load_path = "./PreprocessedData"
load_path = "home/s200431/PreprocessedData"
# Get filenames
files = []
......@@ -79,6 +79,9 @@ Drop_epochs_df = Drop_epochs_df.sort_values(by=["Subject_ID"]).reset_index(drop=
### Load questionnaire data
# For the purposes of this demonstration I will make a dummy dataframe
# The original code imported csv files with questionnaire data and group status
final_qdf = pd.read_csv(r'/data/raw/FOR_DTU/Questionnaires_for_DTU.csv')
"""
final_qdf = pd.DataFrame({"Subject_ID":Subject_id,
"Age":[23,26],
"Gender":[0,0],
......@@ -87,10 +90,11 @@ final_qdf = pd.DataFrame({"Subject_ID":Subject_id,
"Q1":[1.2, 2.3],
"Q2":[1.7, 1.5],
"Qn":[2.1,1.0]})
"""
# Define cases as >= 44 total PCL
# Type: numpy array with subject id
cases = np.array(final_qdf["Subject_ID"][final_qdf["PCL_total"]>=44])
cases = np.array(final_qdf["Subject_ID"][final_qdf["PCL_t7"]>=44])
n_groups = 2
Groups = ["CTRL", "PTSD"]
......@@ -755,7 +759,7 @@ for i in range(len(order)):
maps[i][m] *= sign_swap[i][m]
# Plot the maps and save
save_path = "/Users/benj3542/Desktop/Uni/Noter/Semester_6/Bachelor/resting-state-eeg-analysis/Figures/Microstates"
save_path = "/home/s200431/Figures/Microstates"
labels = ["EC", "EO"]
for i in range(len(labels)):
fig, axarr = plt.subplots(1, n_maps, figsize=(20,5))
......
Main.py 0 → 100755
This diff is collapsed.
......@@ -34,6 +34,7 @@ import autoreject # Automatic EEG artifact detection
import mlxtend # Sequential Forward Selection
from mne.time_frequency import *
from mne.time_frequency import psd_multitaper
from mne.preprocessing import (ICA, create_eog_epochs, create_ecg_epochs, corrmap)
from mne.stats import spatio_temporal_cluster_test, permutation_cluster_test
from mne.channels import find_ch_adjacency
......
......@@ -25,7 +25,7 @@ Link to the demonstration data: www.bci2000.org
# Set working directory
import os
wkdir = "/home/s200431"
wkdir = "/home/s200431/"
os.chdir(wkdir)
# Load all libraries from the Preamble
......@@ -37,10 +37,10 @@ from mne.datasets import eegbci
# The EEGBCI200 is task based, but we will treat it as "resting-state"
# And the 2 runs as Eyes Closed and Eyes Open
n_subjects = 78
Subject_id = list(range(1,n_subjects+1))
n_subjects = 91
Subject_id = list(range(52,n_subjects+52))
# Download and get filenames
<<<<<<< HEAD
data_path = "/data/may2020/QEEG"
files = []
for r, d, f in os.walk(data_path):
......@@ -55,7 +55,7 @@ n_subjects = 51
Subject_id = list(range(1,n_subjects+1))
# Original code to get filenames in a folder
data_path = "/data/raw/FOR_DTU/rawEEGforDTU"
=======
from mne.datasets import eegbci
files = []
......@@ -64,28 +64,26 @@ for i in range(n_subjects):
files.append(raw_fnames)
"""
# Original code to get filenames in a folder
data_path = "/Users/benj3542/Desktop/Uni/Noter/Semester_6/Bachelor/Test_bdf"
>>>>>>> 592a824fc18e7b7d354f8c8638fd1d4cda16ad34
data_path = "/data/sep2020"
"""
# Get filenames
holder = []
files = []
for r, d, f in os.walk(data_path):
for file in f:
if ".bdf" in file:
<<<<<<< HEAD
if ".set" in file:
holder.append(os.path.join(r, file))
files.append(holder)
holder = []
files.pop(0)
"""
=======
holder.append((os.path.join(r, file)))
files.append(holder)
holder = []
files.pop(0)
"""
>>>>>>> 592a824fc18e7b7d354f8c8638fd1d4cda16ad34
files = []
for r, d, f in os.walk(data_path):
for file in f:
if ".set" in file:
files.append(os.path.join(r, file))
# Eye status
anno_to_event = {'Eyes Closed': 1, 'Eyes Open': 2} # manually defined event id
eye_status = list(anno_to_event.keys())
......@@ -97,15 +95,16 @@ n_epochs_trial = int(60/epoch_len) # number of epochs in a trial
n_trials = 2 # 1 eyes closed followed by 1 eyes open
# Montage settings
montage = mne.channels.make_standard_montage('standard_1005')
#montage = mne.channels.read_custom_montage(filename) # custom montage file
fname = "/home/glia/Analysis/Channel_locations/SMARTING_fixed.loc"
#montage = mne.channels.make_standard_montage('standard_1005')
montage = mne.channels.read_custom_montage(fname) # custom montage file
#mne.io.read_raw_eeglab(files[0][1], preload = True)
# %% Load, filter and epoch (Steps 1 to 5)
# Pre-allocate memory
epochs = [0]*n_subjects
for i in range(n_subjects):
# MNE python supports many EEG formats. Make sure to use the proper one
raw = mne.io.concatenate_raws([mne.io.read_raw_bdf(f,preload = True) for f in files[i]])
raw = mne.io.read_raw_eeglab(files[i],preload = True, verbose = 0)
# Fix EEGBCI channel names
eegbci.standardize(raw)
# Set montage
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment