-
Notifications
You must be signed in to change notification settings - Fork 1
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
Preprocessing #10
base: master
Are you sure you want to change the base?
Preprocessing #10
Changes from 1 commit
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from mne.io import concatenate_raws, read_raw_edf | ||
import os | ||
|
||
|
||
#Load Data | ||
load_path = 'C:/Users/User/Desktop/CSE 481C - Neruo Capstone/Project Repo/Data/TUH/00003010_s003_t000.edf' | ||
filename = '00003010_s003_t000' | ||
fileformat = '.edf' | ||
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. 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 | ||
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. 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) | ||
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. 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/' | ||
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. Nice! once again relative paths, maybe something like os.pwd() |
||
path = os.path.join(parent_path, directory) | ||
os.mkdir(path) | ||
|
||
#Plotting begins! | ||
#Raw data | ||
raw.plot(duration=100, block=True) | ||
plt.show() | ||
#todo: instead of scrolly image, get a static image | ||
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. 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 | ||
raw.plot_psd(tmax=np.inf) | ||
plt.show() | ||
psd_fig = raw.plot_psd(show=False) | ||
saveNamePower = path + '/' + filename + '_all' + '_psd' | ||
psd_fig.savefig(saveNamePower, dpi = 300) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,51 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from mne.io import concatenate_raws, read_raw_edf | ||
import os | ||
|
||
|
||
#Load Data | ||
load_path = 'C:/Users/User/Desktop/CSE 481C - Neruo Capstone/Project Repo/Data/TUH/00003010_s003_t000.edf' | ||
filename = '00003010_s003_t000' | ||
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 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 | ||
print(raw.info['ch_names']) | ||
ch_name = raw.info['ch_names'] | ||
print("Total Channels: ", len(ch_name)) | ||
|
||
#Select the required Channel | ||
requiredChannel = ch_name[1] | ||
raw.pick(requiredChannel) | ||
|
||
#Plotting begins! | ||
data, times = raw[:, :] | ||
fig = plt.subplots(figsize=(10,8)) | ||
plt.plot(times, data.T); | ||
plt.xlabel('Seconds') | ||
plt.ylabel('$\mu V$') | ||
plt.title('Channels: 1-5'); | ||
plt.legend(raw.ch_names[1:2]); | ||
plt.show() | ||
|
||
|
||
#Power spectrum | ||
raw.plot_psd(tmax=np.inf) | ||
plt.show() | ||
|
||
|
||
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/' | ||
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. 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) |
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.
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