-
Notifications
You must be signed in to change notification settings - Fork 1
Preprocessing #10
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
base: master
Are you sure you want to change the base?
Preprocessing #10
Changes from all commits
2cae096
4b20ac7
d63c821
fe6af28
ffe62eb
066e288
cb30512
3053240
4cdf309
6ee5d20
bd7124d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: mne | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- python>=3.8 | ||
- pip | ||
- numpy | ||
- scipy | ||
- matplotlib | ||
- numba | ||
- pandas | ||
- xlrd | ||
- scikit-learn | ||
- h5py | ||
- pillow | ||
- statsmodels | ||
- jupyter | ||
- joblib | ||
- psutil | ||
- numexpr | ||
- imageio | ||
- tqdm | ||
- spyder-kernels>=1.10.0 | ||
- imageio-ffmpeg>=0.4.1 | ||
- vtk>=9.0.1 | ||
- pyvista>=0.30 | ||
- pyvistaqt>=0.4 | ||
- qdarkstyle | ||
- darkdetect | ||
- mayavi | ||
- PySurfer | ||
- dipy | ||
- nibabel | ||
- nilearn | ||
- python-picard | ||
- pyqt!=5.15.3 | ||
- mne | ||
- mffpy>=0.5.7 | ||
- ipywidgets | ||
- pip: | ||
- ipyvtklink |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from mne.io import concatenate_raws, read_raw_edf | ||
from tfr_raw_psd import spectral_power, plot_tfr_and_raw_bin_width_all_channel, load | ||
|
||
# ------------------------------------------------------ | ||
|
||
if __name__ == '__main__': | ||
load_path, filename = load() | ||
raw = read_raw_edf(load_path, preload=True) | ||
|
||
#Bandpass filter 0.1Hz - 50Hz | ||
raw = raw.filter(0.1, 50) | ||
|
||
# Resample to 100 Hz | ||
raw = raw.resample(100, npad='auto') | ||
|
||
print(raw.info) | ||
binNumber = 10 | ||
|
||
#Plot TFR and RAW data for the corresponding time for all channels | ||
plot_tfr_and_raw_bin_width_all_channel(raw = raw, start=100, stop=350, filename=filename, binNumber=binNumber) | ||
|
||
#Plot Spectral Power Density Plot of all channels | ||
spectral_power(raw=raw, filename=filename) | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import mne | ||
import os | ||
|
||
# ----------------------------------------------------- | ||
|
||
def spectral_power(raw, filename): | ||
channel_names = raw.info['ch_names'] | ||
|
||
# Make a directory path | ||
directory = filename + '_tfr_raw_spd' | ||
# parent_path = 'C:/Users/User/Desktop/CSE 481C - Neruo Capstone/Project Repo/Data/GeneratedPlots/' | ||
parent_path = os.getcwd() + '/saved_plots/' | ||
path = os.path.join(parent_path, directory) | ||
|
||
# If directory does not exist then make it | ||
if (os.path.exists(path) == False): | ||
os.mkdir(path) | ||
|
||
for i in range(len(channel_names)): | ||
|
||
# Select the required channel | ||
requiredChannel = channel_names[i] | ||
|
||
# Power spectrum | ||
copy = raw.copy() | ||
copy.pick(requiredChannel) | ||
psd_fig = copy.plot_psd(show=False) | ||
saveNamePower = path + '/' + filename + '_' + str(requiredChannel) + '_psd' | ||
psd_fig.savefig(saveNamePower, dpi=300) | ||
|
||
|
||
# ----------------------------------------------------- | ||
|
||
def plot_tfr_and_raw_bin_width_all_channel(raw, start, stop, filename, binNumber): | ||
# Channel Info | ||
channel_names = raw.info['ch_names'] | ||
|
||
# Setting reference | ||
raw.set_eeg_reference(ref_channels=['EEG CZ-LE']) | ||
rawLength = int(len(raw) / raw.info['sfreq']) | ||
print(rawLength) | ||
|
||
# Construct events | ||
events = mne.make_fixed_length_events(raw, duration=rawLength - 1) | ||
|
||
# Construct Epochs | ||
epochs = mne.Epochs(raw, events, preload=True, tmin=0, tmax=rawLength - 1, baseline=None) | ||
|
||
# Plotting TFRs | ||
frequencies = np.arange(1, 50, 1) | ||
power = mne.time_frequency.tfr_morlet(epochs, n_cycles=2, return_itc=False, freqs=frequencies, decim=3) # Run this only once | ||
|
||
#debug | ||
print(filename) | ||
print(binNumber) | ||
|
||
# Make a directory path | ||
directory = filename + '_tfr_raw_spd' | ||
# parent_path = 'C:/Users/User/Desktop/CSE 481C - Neruo Capstone/Project Repo/Data/GeneratedPlots/' | ||
parent_path = os.getcwd() + '/saved_plots/' | ||
path = os.path.join(parent_path, directory) | ||
|
||
#If directory does not exist then make it | ||
if(os.path.exists(path) == False): | ||
os.mkdir(path) | ||
|
||
for i in range(len(channel_names)): | ||
|
||
# Select the required channel | ||
requiredChannel = channel_names[i] | ||
|
||
#Plot RAW | ||
copy = raw.copy() | ||
copy.pick(requiredChannel) | ||
copy.crop(tmin=start, tmax=stop, include_tmax=True) | ||
|
||
# Plotting begins! | ||
data, times = copy[:, :] | ||
fig = plt.figure() | ||
ax = fig.add_subplot(111) | ||
ax.plot(times, data.T, linewidth=0.5); | ||
ax.set_xticklabels([]) | ||
|
||
|
||
plt.xlabel('Seconds') | ||
plt.ylabel('$\mu V$') | ||
plt.title('Channel: ' + str(requiredChannel)); | ||
positions = np.arange(0, start-stop, 1) | ||
|
||
|
||
|
||
saveNameRAW = path + '/' + filename + '_' + 'bn' + str(binNumber) + '_' + str(requiredChannel) + '_raw' | ||
plt.savefig(saveNameRAW, dpi=300) | ||
plt.close(fig) | ||
|
||
# Plot TFR | ||
tfr_fig = power.plot(requiredChannel, tmin=start, tmax=stop, vmin=-0.000000005, vmax=0.000000005, show=False) | ||
saveNamePower = path + '/' + filename + '_' + 'bn' + str(binNumber) + '_' + str(requiredChannel) + '_tfr' | ||
tfr_fig.savefig(saveNamePower, dpi=300) | ||
|
||
|
||
# ----------------------------------------------------- | ||
|
||
def load(): | ||
# Load Data | ||
filename = '00000258_s001_t000' | ||
fileformat = '.edf' | ||
load_path = 'C:/Users/User/Desktop/CSE 481C - Neruo Capstone/Project Repo/Data/TUSZ/v1.5.2/edf/dev/02_tcp_le/002/00000258/s001_2003_07_16/' \ | ||
+ filename + fileformat | ||
return load_path, filename | ||
|
||
# ----------------------------------------------------- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,7 @@ | |
"resolved" "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.13.13.tgz" | ||
"version" "7.13.13" | ||
dependencies: | ||
"@babel/compat-data" "^7.13.12" | ||
"@babel/compat-data" "^7.13.15" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same with these changes. We should probably have an OS-specific switch that determines the correct versions here. |
||
"@babel/helper-validator-option" "^7.12.17" | ||
"browserslist" "^4.14.5" | ||
"semver" "^6.3.0" | ||
|
@@ -237,8 +237,8 @@ | |
"resolved" "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.13.0.tgz" | ||
"version" "7.13.0" | ||
dependencies: | ||
"@babel/traverse" "^7.13.0" | ||
"@babel/types" "^7.13.0" | ||
"@babel/traverse" "^7.13.15" | ||
"@babel/types" "^7.13.16" | ||
|
||
"@babel/helper-member-expression-to-functions@^7.13.0", "@babel/helper-member-expression-to-functions@^7.13.12": | ||
"integrity" "sha512-48ql1CLL59aKbU94Y88Xgb2VFy7a95ykGRbJJaaVv+LX5U8wFpLfiGXJJGUozsmA1oEh/o5Bp60Voq7ACyA/Sw==" | ||
|
@@ -836,7 +836,7 @@ | |
"resolved" "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.12.13.tgz" | ||
"version" "7.12.13" | ||
dependencies: | ||
"@babel/helper-plugin-utils" "^7.12.13" | ||
"@babel/helper-plugin-utils" "^7.13.0" | ||
|
||
"@babel/plugin-transform-classes@^7.12.1", "@babel/plugin-transform-classes@^7.13.0": | ||
"integrity" "sha512-9BtHCPUARyVH1oXGcSJD3YpsqRLROJx5ZNP6tN5vnk17N0SVf9WCtf8Nuh1CFmgByKKAIMstitKduoCmsaDK5g==" | ||
|
@@ -1443,7 +1443,7 @@ | |
"version" "7.13.15" | ||
dependencies: | ||
"@babel/code-frame" "^7.12.13" | ||
"@babel/generator" "^7.13.9" | ||
"@babel/generator" "^7.13.16" | ||
"@babel/helper-function-name" "^7.12.13" | ||
"@babel/helper-split-export-declaration" "^7.12.13" | ||
"@babel/parser" "^7.13.15" | ||
|
@@ -2092,7 +2092,6 @@ | |
"resolved" "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz" | ||
"version" "7.1.1" | ||
dependencies: | ||
"@types/events" "*" | ||
"@types/minimatch" "*" | ||
"@types/node" "*" | ||
|
||
|
@@ -2306,8 +2305,8 @@ | |
"resolved" "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.21.0.tgz" | ||
"version" "4.21.0" | ||
dependencies: | ||
"@typescript-eslint/types" "4.21.0" | ||
"@typescript-eslint/visitor-keys" "4.21.0" | ||
"@typescript-eslint/types" "4.22.0" | ||
"@typescript-eslint/visitor-keys" "4.22.0" | ||
|
||
"@typescript-eslint/[email protected]": | ||
"integrity" "sha512-+3+FCUJIahE9q0lDi1WleYzjCwJs5hIsbugIgnbB+dSCYUxl8L6PwmsyOPFZde2hc1DlTo/xnkOgiTLSyAbHiQ==" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
windows specific changes should be handled dynamically and not hardcoded. We should think about this carefully before merging to master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed.