EEG_cls / misc.py
Mohammad Javad Darvishi
'load and plot *.edf files'
5fdbc81
raw
history blame
No virus
873 Bytes
import mne
import streamlit as st
import matplotlib.pyplot as plt
def preprocessing_and_plotting(raw):
# Select the first channel
channel = raw.ch_names[0]
st.write(f"Selected channel: {channel}")
# Plot the first channel
fig, ax = plt.subplots()
ax.plot(raw.times, raw[channel][0].T)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Amplitude (µV)")
ax.set_title(f"EEG signal of {channel}")
st.pyplot(fig)
def read_file(edf_file):
# To read file as bytes:
bytes_data = edf_file.getvalue()
# Open a file named "output.bin" in the current directory in write binary mode
with open('edf_file.edf', "wb") as f:
# Write the bytes data to the file
f.write(bytes_data)
raw = mne.io.read_raw_edf('edf_file.edf')
st.write(f"Loaded {edf_file.name} with {raw.info['nchan']} channels")
return raw