Skip to content

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
38 changes: 38 additions & 0 deletions Pre-processing/PlotAllChannels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np
import matplotlib.pyplot as plt
from mne.io import concatenate_raws, read_raw_edf
import os


#Load Data
filename = '00003010_s003_t000'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's fine for now, but when I integrate with front end I want to pull this filename from the api call instead of hardcoded

fileformat = '.edf'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk if this would be necessary if filename passed through api call

load_path = 'C:/Users/User/Desktop/CSE 481C - Neruo Capstone/Project Repo/Data/TUH/' + filename + fileformat
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general relative paths are preferred, but passing in filename should make this a non-issue. When web-hosting this will be a more interesting problem. We should try to have pre-processing code run on the front end

print(load_path)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove debugging code when we integrate w master

raw = read_raw_edf(load_path, preload=True)

#Inspect the .edf file
print(raw.info)

#Make a directory
directory = filename + '_allChannels'
parent_path = 'C:/Users/User/Desktop/CSE 481C - Neruo Capstone/Project Repo/Data/GeneratedPlots/'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! once again relative paths, maybe something like os.pwd()

path = os.path.join(parent_path, directory)
os.mkdir(path)

#Plotting begins!
#Raw data
#todo: instead of scrolly image, get a static image
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get this running on the front end, we might not even need to save anything! Tricky problem though since browser only runs js/css/html

bigPlot = raw.plot(duration=1200, block=True, show_scrollbars = False)
bigPlotName = path + '/' + filename + '_all' + '_RAW'
bigPlot.savefig(bigPlotName)
#plt.show()

#Power spectrum
#raw.plot_psd(tmax=np.inf)
#plt.show()

#Power spectrum
psd_fig = raw.plot_psd(show=False)
saveNamePower = path + '/' + filename + '_all' + '_psd'
psd_fig.savefig(saveNamePower, dpi = 300)
51 changes: 51 additions & 0 deletions Pre-processing/PlotOneChannel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import numpy as np
import matplotlib.pyplot as plt
from mne.io import concatenate_raws, read_raw_edf
import os


#Load Data
filename = '00003010_s003_t000'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note as above, relative paths + filename either passed in, or raw data is

fileformat = '.edf'
load_path = 'C:/Users/User/Desktop/CSE 481C - Neruo Capstone/Project Repo/Data/TUH/' + filename + fileformat
print(load_path)
raw = read_raw_edf(load_path, preload=True)

#Inspect the .edf file
channel_names = raw.info['ch_names']
len_channels = len(channel_names)
print(channel_names)
print("Total Channels: ", len_channels)

#Make a directory
directory = filename
parent_path = 'C:/Users/User/Desktop/CSE 481C - Neruo Capstone/Project Repo/Data/GeneratedPlots/'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relative path

path = os.path.join(parent_path, directory)
os.mkdir(path)

def makePlots(i):
#Select the required Channel
requiredChannel = channel_names[i]
copy = raw.copy()
copy.pick(requiredChannel)

#Plotting begins!
data, times = copy[:, :]
fig = plt.figure()
plt.plot(times, data.T);
plt.xlabel('Seconds')
plt.ylabel('$\mu V$')
plt.title('Channel: ' + str(requiredChannel));
saveNameRAW = path + '/' + filename + '_' + requiredChannel + '_RAW'
plt.savefig(saveNameRAW, dpi = 300)
plt.close(fig)


#Power spectrum
psd_fig = copy.plot_psd(show=False)
saveNamePower = path + '/' + filename + '_' + requiredChannel + '_psd'
psd_fig.savefig(saveNamePower, dpi = 300)

ran = range(1, len_channels)
for i in ran:
makePlots(i)
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"postcss": "^8.2.9",
"postcss": "^8.2.12",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
"react-scripts": "^4.0.3",
"web-vitals": "^1.0.1",
"yarn": "^1.22.10"
},
"scripts": {
"build:css": "postcss src/styles/tailwind.css -o src/styles/app.css",
"watch:css": "postcss src/styles/tailwind.css -o src/styles/app.css --watch",
"react-scripts:start": "sleep 5 && react-scripts start",
"react-scripts:start": "timeout 5 && react-scripts start",
Copy link
Collaborator

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed.

"start": "run-p watch:css react-scripts:start",
"start-api": "cd api && venv/bin/flask run --no-debugger",
"build": "run-s build:css react-scripts:build",
Expand Down
15 changes: 7 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The 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"
Expand Down Expand Up @@ -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=="
Expand Down Expand Up @@ -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=="
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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" "*"

Expand Down Expand Up @@ -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=="
Expand Down