Spaces:
Running
Running
Mohammad Javad Darvishi
commited on
Commit
·
5fdbc81
1
Parent(s):
7342363
'load and plot *.edf files'
Browse files
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
edf_file.edf
|
| 2 |
+
__pycache__/*
|
| 3 |
+
*.pyc
|
app.py
CHANGED
|
@@ -2,21 +2,18 @@
|
|
| 2 |
import streamlit as st
|
| 3 |
import mne
|
| 4 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Load the edf file
|
| 7 |
edf_file = st.file_uploader("Upload an EEG edf file", type="edf")
|
|
|
|
|
|
|
| 8 |
if edf_file is not None:
|
| 9 |
-
raw = mne.io.read_raw_edf(edf_file)
|
| 10 |
-
st.write(f"Loaded {edf_file.name} with {raw.info['nchan']} channels")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
st.write(f"Selected channel: {channel}")
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
ax.plot(raw.times, raw[channel][0].T)
|
| 19 |
-
ax.set_xlabel("Time (s)")
|
| 20 |
-
ax.set_ylabel("Amplitude (µV)")
|
| 21 |
-
ax.set_title(f"EEG signal of {channel}")
|
| 22 |
-
st.pyplot(fig)
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import mne
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
+
import os
|
| 6 |
+
from misc import *
|
| 7 |
+
|
| 8 |
|
| 9 |
# Load the edf file
|
| 10 |
edf_file = st.file_uploader("Upload an EEG edf file", type="edf")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
if edf_file is not None:
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Read the file
|
| 16 |
+
raw = read_file(edf_file)
|
|
|
|
| 17 |
|
| 18 |
+
# Preprocess and plot the data
|
| 19 |
+
preprocessing_and_plotting(raw)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
misc.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import mne
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def preprocessing_and_plotting(raw):
|
| 9 |
+
# Select the first channel
|
| 10 |
+
channel = raw.ch_names[0]
|
| 11 |
+
st.write(f"Selected channel: {channel}")
|
| 12 |
+
|
| 13 |
+
# Plot the first channel
|
| 14 |
+
fig, ax = plt.subplots()
|
| 15 |
+
ax.plot(raw.times, raw[channel][0].T)
|
| 16 |
+
ax.set_xlabel("Time (s)")
|
| 17 |
+
ax.set_ylabel("Amplitude (µV)")
|
| 18 |
+
ax.set_title(f"EEG signal of {channel}")
|
| 19 |
+
st.pyplot(fig)
|
| 20 |
+
|
| 21 |
+
def read_file(edf_file):
|
| 22 |
+
# To read file as bytes:
|
| 23 |
+
bytes_data = edf_file.getvalue()
|
| 24 |
+
# Open a file named "output.bin" in the current directory in write binary mode
|
| 25 |
+
with open('edf_file.edf', "wb") as f:
|
| 26 |
+
# Write the bytes data to the file
|
| 27 |
+
f.write(bytes_data)
|
| 28 |
+
|
| 29 |
+
raw = mne.io.read_raw_edf('edf_file.edf')
|
| 30 |
+
st.write(f"Loaded {edf_file.name} with {raw.info['nchan']} channels")
|
| 31 |
+
return raw
|
run.sh
CHANGED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
streamlit run app.py
|