major updates
Esse commit está contido em:
@@ -0,0 +1,57 @@
|
||||
import mne
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import yasa
|
||||
from mne.time_frequency import tfr_morlet, tfr_multitaper
|
||||
%matplotlib qt
|
||||
|
||||
data_path = "P:\\3013102.01\\Data\\"
|
||||
participant_session = ['NL_DNDRS_0004__ses-2']
|
||||
|
||||
for idx, c_subj in enumerate(participant_session):
|
||||
|
||||
participant_number = c_subj.split('__')[0]
|
||||
session_number = c_subj.split('__')[1]
|
||||
|
||||
# Reading EEG data
|
||||
path_EEG_L = data_path + participant_number +'\\' + session_number + '\\eeg\\EEG L.edf'
|
||||
path_EEG_R = data_path + participant_number +'\\' + session_number + '\\eeg\\EEG R.edf'
|
||||
|
||||
# Load the EDF file
|
||||
raw_EEG_L = mne.io.read_raw_edf(path_EEG_L, preload=True)
|
||||
raw_EEG_R = mne.io.read_raw_edf(path_EEG_R, preload=True)
|
||||
|
||||
raw_EEG_L.filter(l_freq=.3, h_freq=30)
|
||||
raw_EEG_R.filter(l_freq=.3, h_freq=30)
|
||||
|
||||
raw_EEG_L_get_data = np.ravel(raw_EEG_L.get_data(units="uV"))
|
||||
raw_EEG_R_get_data = np.ravel(raw_EEG_R.get_data(units="uV"))
|
||||
|
||||
loc = raw_EEG_L_get_data[7190*256:]
|
||||
roc = raw_EEG_R_get_data[7190*256:]
|
||||
|
||||
plt.plot(loc)
|
||||
plt.plot(roc)
|
||||
|
||||
REM_events = yasa.rem_detect(loc = loc, roc = roc, sf=256, hypno=None, include=4, amplitude=(30, 325), duration=(0.1, 1.2), freq_rem=(0.2, 8), remove_outliers=True, verbose=False)
|
||||
REM_events.summary()
|
||||
REM_events.plot_average(time_before=1, time_after=1);
|
||||
|
||||
# Let's get a boolean mask of the REMs in data
|
||||
mask = REM_events.get_mask()
|
||||
|
||||
loc_highlight = loc * mask[0, :]
|
||||
roc_highlight = roc * mask[1, :]
|
||||
|
||||
loc_highlight[loc_highlight == 0] = np.nan
|
||||
roc_highlight[roc_highlight == 0] = np.nan
|
||||
|
||||
plt.figure(figsize=(16, 4.5))
|
||||
plt.plot(loc, 'slategrey', label='LOC')
|
||||
plt.plot(roc, 'grey', label='ROC')
|
||||
plt.plot( loc_highlight, 'indianred')
|
||||
plt.plot( roc_highlight, 'indianred')
|
||||
plt.xlabel('Time (seconds)')
|
||||
plt.ylabel('Amplitude (uV)')
|
||||
plt.title('REM sleep EOG data')
|
||||
plt.legend()
|
||||
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
BIN
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
Arquivo binário não exibido.
@@ -0,0 +1,77 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Wed Aug 2 18:31:25 2023
|
||||
|
||||
@author: mahjaf
|
||||
"""
|
||||
import mne
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from mne.time_frequency import tfr_morlet, tfr_multitaper
|
||||
%matplotlib qt
|
||||
|
||||
data_path = "P:\\3013102.01\\Data\\"
|
||||
participant_session = ['NL_DNDRS_0004__ses-2']
|
||||
LRLR_events = {'NL_DNDRS_0004__ses-2': [7197, 7226, 7276, 7457, 7482, 7492]}
|
||||
|
||||
for idx, c_subj in enumerate(participant_session):
|
||||
|
||||
participant_number = c_subj.split('__')[0]
|
||||
session_number = c_subj.split('__')[1]
|
||||
|
||||
# Reading EEG data
|
||||
path_EEG_L = data_path + participant_number +'\\' + session_number + '\\eeg\\EEG L.edf'
|
||||
path_EEG_R = data_path + participant_number +'\\' + session_number + '\\eeg\\EEG R.edf'
|
||||
|
||||
# Load the EDF file
|
||||
raw_EEG_L = mne.io.read_raw_edf(path_EEG_L, preload=True)
|
||||
raw_EEG_R = mne.io.read_raw_edf(path_EEG_R, preload=True)
|
||||
|
||||
fs = int(raw_EEG_L.info['sfreq'])
|
||||
|
||||
# Set up the events for creating epochs
|
||||
num_rows = len(LRLR_events[c_subj])
|
||||
events = np.zeros((num_rows, 3), dtype = 'int')
|
||||
|
||||
# Fill the first column with the values from the Python list
|
||||
events[:, 0] = [element * fs for element in LRLR_events[c_subj]]
|
||||
events[:, 1] = 0
|
||||
events[:, 2] = 1
|
||||
|
||||
# Create epochs for seconds 5-10 (event ID 1) and seconds 15-20 (event ID 2)
|
||||
epochs_EEG_L = mne.Epochs(raw_EEG_L, events, event_id=1, tmin=0, tmax=20, baseline=None)
|
||||
epochs_EEG_R = mne.Epochs(raw_EEG_R, events, event_id=1, tmin=0, tmax=20, baseline=None)
|
||||
|
||||
epochs_EEG_L_get_data = np.transpose(np.squeeze(epochs_EEG_L.get_data()))
|
||||
epochs_EEG_R_get_data = np.transpose(np.squeeze(epochs_EEG_R.get_data()))
|
||||
|
||||
for item in np.arange(len(LRLR_events[c_subj])):
|
||||
print(item)
|
||||
plt.figure()
|
||||
plt.plot(epochs_EEG_L_get_data[:, item])
|
||||
plt.plot(epochs_EEG_R_get_data[:, item])
|
||||
|
||||
|
||||
epochs.plot()
|
||||
|
||||
epochs.plot_psd(fmin=.1, fmax=15, tmin=0, tmax=5, average=True)
|
||||
|
||||
freqs = np.arange(5., 30., 1.)
|
||||
|
||||
# You can trade time resolution or frequency resolution or both
|
||||
# in order to get a reduction in variance
|
||||
|
||||
n_cycles = freqs / 2.
|
||||
power = tfr_morlet(epochs, freqs=freqs, n_cycles=n_cycles, return_itc=False)
|
||||
power.plot([0], baseline=(0., 0.1), mode='mean', vmin=, vmax=3.,
|
||||
title='Sim: Using Morlet wavelet')
|
||||
|
||||
##
|
||||
n_cycles = freqs *5
|
||||
time_bandwidth = 2.0 # Least possible frequency-smoothing (1 taper)
|
||||
power = tfr_multitaper(epochs, freqs=freqs, n_cycles=n_cycles,
|
||||
time_bandwidth=time_bandwidth, return_itc=False)
|
||||
power.plot()
|
||||
# Plot results. Baseline correct based on first 100 ms.
|
||||
power.plot([0], baseline=(5., 5.1), mode='mean', vmin=-1., vmax=3.,
|
||||
title='Sim: Least smoothing, most variance')
|
||||
+65
-24
@@ -183,17 +183,23 @@ class OfflineDreamento():
|
||||
|
||||
self.checkbox_plot_EMG_quality_evaluation.grid(row = 5, column = 4, sticky="w")
|
||||
|
||||
#%% Checkbox for automatic eye movement detector
|
||||
self.automatic_REM_event_deetction = IntVar(value=1)
|
||||
self.checkbox_automatic_REM_event_deetction = Checkbutton(self.frame_import, text = "Automatic REM event detection",
|
||||
font = 'Calibri 11 ', variable = self.automatic_REM_event_deetction)
|
||||
|
||||
self.checkbox_automatic_REM_event_deetction.grid(row = 6, column = 4, sticky="w")
|
||||
#%% Checkbox for plotting periodogram
|
||||
self.plot_psd = IntVar(value = 0)
|
||||
self.checkbox_plot_psd = Checkbutton(self.frame_import, text = "Plot peridogram",
|
||||
font = 'Calibri 11 ', variable = self.plot_psd)
|
||||
|
||||
self.checkbox_plot_psd.grid(row = 6, column = 4, sticky="w", pady = 10)
|
||||
self.checkbox_plot_psd.grid(row = 7, column = 4, sticky="w", pady = 10)
|
||||
#%% Label to select the desired analysis
|
||||
#Label to read data and extract features
|
||||
self.label_analysis_data = Label(self.frame_import, text = "Select the data to analyze:",
|
||||
font = 'Calibri 13 ')
|
||||
self.label_analysis_data.grid(row = 7 , column = 4, sticky="w")
|
||||
self.label_analysis_data.grid(row = 8 , column = 4, sticky="w")
|
||||
|
||||
#%% Checkbox for plotting spectrograms with markers
|
||||
self.analysis_signal_options = IntVar(value = 1)
|
||||
@@ -201,7 +207,7 @@ class OfflineDreamento():
|
||||
font = 'Calibri 11 ', variable = self.analysis_signal_options,\
|
||||
value = 1, command=self.analysis_signal_options_button_activator)
|
||||
|
||||
self.checkbox_plot_additional_EMG.grid(row = 8, column = 4, sticky="w", pady = 10)
|
||||
self.checkbox_plot_additional_EMG.grid(row = 9, column = 4, sticky="w", pady = 10)
|
||||
|
||||
|
||||
#%% Checkbox for analyzing ZMax Hypndoyne only
|
||||
@@ -210,14 +216,14 @@ class OfflineDreamento():
|
||||
font = 'Calibri 11 ', variable = self.analysis_signal_options, value = 2,\
|
||||
command=self.analysis_signal_options_button_activator)
|
||||
|
||||
self.checkbox_ZMax_Hypno_Dreamento.grid(row = 9, column = 4, sticky="w", pady = 10)
|
||||
self.checkbox_ZMax_Hypno_Dreamento.grid(row = 10, column = 4, sticky="w", pady = 10)
|
||||
#%% Checkbox for analyzing ZMax Hypndoyne only
|
||||
self.ZMax_Hypno_only = IntVar(value = 0)
|
||||
self.checkbox_ZMax_Hypno_only = Radiobutton(self.frame_import, text = "HDRecorder",
|
||||
font = 'Calibri 11 ', variable = self.analysis_signal_options, value = 3,\
|
||||
command=self.analysis_signal_options_button_activator)
|
||||
|
||||
self.checkbox_ZMax_Hypno_only.grid(row = 10, column = 4, sticky="w", pady = 10)
|
||||
self.checkbox_ZMax_Hypno_only.grid(row = 11, column = 4, sticky="w", pady = 10)
|
||||
|
||||
#%% EMG Y SCALE
|
||||
#Label to read data and extract features
|
||||
@@ -427,8 +433,14 @@ class OfflineDreamento():
|
||||
sigScript_org = sigScript_org[:, 1]
|
||||
|
||||
# Read EMG
|
||||
print('Loading EEG file ... Please wait')
|
||||
EMG_data = mne.io.read_raw_brainvision(self.path_to_EMG , preload = True)
|
||||
print('Loading EEG file ... Please wait')
|
||||
if (self.path_to_EMG[-4:] == 'vhdr' or self.path_to_EMG[-4:] == 'VHDR'):
|
||||
|
||||
EMG_data = mne.io.read_raw_brainvision(self.path_to_EMG , preload = True)
|
||||
|
||||
elif (self.path_to_EMG[-3:] == 'edf' or self.path_to_EMG[-3:] == 'EDF'):
|
||||
EMG_data = mne.io.read_raw_edf(self.path_to_EMG, preload = True)
|
||||
|
||||
|
||||
print('EEG and EMG imported successfully')
|
||||
# Read annotations
|
||||
@@ -452,7 +464,7 @@ class OfflineDreamento():
|
||||
EMG_data_get1 = self.butter_bandpass_filter(data = EMG_data_get1, lowcut=10, highcut=100, fs = 256, order = 2)
|
||||
EMG_data_get2 = self.butter_bandpass_filter(data = EMG_data_get2, lowcut=10, highcut=100, fs = 256, order = 2)
|
||||
EMG_data_get3 = self.butter_bandpass_filter(data = EMG_data_get3, lowcut=10, highcut=100, fs = 256, order = 2)
|
||||
t_sync = np.arange(time_sync_event[0] - 256*5, time_sync_event[0] + 256*15)
|
||||
t_sync = np.arange(time_sync_event[0] - 256*5, time_sync_event[0] + 256*30)
|
||||
|
||||
# notch filtering
|
||||
notch_freq = 50 # set the notch frequency to 50 Hz
|
||||
@@ -1079,8 +1091,8 @@ class OfflineDreamento():
|
||||
|
||||
global EMG_files_list
|
||||
|
||||
self.filenames = filedialog.askopenfilenames(title = 'select EMG file (.vhdr)',
|
||||
filetype = (("vhdr", "*.vhdr"),("vhdr", "*.vhdr"), ("All Files", "*.*")))
|
||||
self.filenames = filedialog.askopenfilenames(title = 'select EMG file (.vhdr or .edf)',
|
||||
filetype = (("vhdr", "*.vhdr"),("edf", "*.edf"), ("All Files", "*.*")))
|
||||
EMG_files_list = self.frame_import.tk.splitlist(self.filenames)
|
||||
self.n_label_files = len(EMG_files_list)
|
||||
|
||||
@@ -1905,9 +1917,18 @@ class OfflineDreamento():
|
||||
|
||||
|
||||
# read EMG
|
||||
self.EMG_raw = mne.io.read_raw_brainvision(self.path_to_EMG)
|
||||
self.EMG_raw = self.EMG_raw.resample(int(256))
|
||||
if (self.path_to_EMG[-4:] == 'vhdr' or self.path_to_EMG[-4:] == 'VHDR'):
|
||||
|
||||
self.EMG_raw = mne.io.read_raw_brainvision(self.path_to_EMG)
|
||||
self.EMG_raw = self.EMG_raw.resample(int(256))
|
||||
|
||||
|
||||
elif (self.path_to_EMG[-3:] == 'edf' or self.path_to_EMG[-3:] == 'EDF'):
|
||||
|
||||
self.EMG_raw = mne.io.read_raw_edf(self.path_to_EMG, preload = True)
|
||||
|
||||
self.EMG_filtered = self.EMG_raw.filter(l_freq=10, h_freq=100)
|
||||
self.EMG_filtered = self.EMG_filtered.resample(int(256))
|
||||
self.EMG_filtered_data1 = self.EMG_filtered.get_data()[0]
|
||||
self.EMG_filtered_data2 = self.EMG_filtered.get_data()[1]
|
||||
self.EMG_filtered_data1_minus_2 = self.EMG_filtered_data1 - self.EMG_filtered_data2
|
||||
@@ -1925,8 +1946,15 @@ class OfflineDreamento():
|
||||
self.EMG_filtered_data1_minus_2 = signal.filtfilt(b, a, self.EMG_filtered_data1_minus_2, axis=0)
|
||||
|
||||
self.desired_EMG_scale_val = int(self.EMG_scale_options_val.get())
|
||||
self.desired_EMG_scale= [-1e-6* self.desired_EMG_scale_val, 1e-6* self.desired_EMG_scale_val]
|
||||
|
||||
if (self.path_to_EMG[-4:] == 'vhdr' or self.path_to_EMG[-4:] == 'VHDR'):
|
||||
|
||||
|
||||
self.desired_EMG_scale= [-1e-6* self.desired_EMG_scale_val, 1e-6* self.desired_EMG_scale_val]
|
||||
elif (self.path_to_EMG[-3:] == 'edf' or self.path_to_EMG[-3:] == 'EDF'):
|
||||
|
||||
|
||||
self.desired_EMG_scale= [-1 * self.desired_EMG_scale_val, 1* self.desired_EMG_scale_val]
|
||||
|
||||
# Check whether the user already synced EMG vs. EEG or not
|
||||
print(f'shape EMG signals = {np.shape(self.EMG_filtered_data1)}')
|
||||
|
||||
@@ -2215,16 +2243,27 @@ class OfflineDreamento():
|
||||
ax_proba.set_xticks([])
|
||||
|
||||
# read EMG
|
||||
self.EMG_raw = mne.io.read_raw_brainvision(self.path_to_EMG)
|
||||
self.EMG_raw = self.EMG_raw.resample(int(256))
|
||||
if (self.path_to_EMG[-4:] == 'vhdr' or self.path_to_EMG[-4:] == 'VHDR'):
|
||||
|
||||
self.EMG_raw = mne.io.read_raw_brainvision(self.path_to_EMG)
|
||||
self.EMG_raw = self.EMG_raw.resample(int(256))
|
||||
|
||||
elif (self.path_to_EMG[-3:] == 'edf' or self.path_to_EMG[-3:] == 'EDF'):
|
||||
self.EMG_raw = mne.io.read_raw_edf(self.path_to_EMG, preload = True)
|
||||
|
||||
self.EMG_filtered = self.EMG_raw.filter(l_freq=10, h_freq=100)
|
||||
self.EMG_filtered_data1 = self.EMG_filtered.get_data()[0]
|
||||
self.EMG_filtered_data2 = self.EMG_filtered.get_data()[1]
|
||||
self.EMG_filtered_data1_minus_2 = self.EMG_filtered_data1 - self.EMG_filtered_data2
|
||||
|
||||
self.desired_EMG_scale_val = int(self.EMG_scale_options_val.get())
|
||||
self.desired_EMG_scale= [-1e-6* self.desired_EMG_scale_val, 1e-6* self.desired_EMG_scale_val]
|
||||
|
||||
if (self.path_to_EMG[-4:] == 'vhdr' or self.path_to_EMG[-4:] == 'VHDR'):
|
||||
|
||||
self.desired_EMG_scale= [-1e-6* self.desired_EMG_scale_val, 1e-6* self.desired_EMG_scale_val]
|
||||
elif (self.path_to_EMG[-3:] == 'edf' or self.path_to_EMG[-3:] == 'EDF'):
|
||||
|
||||
self.desired_EMG_scale= [-1 * self.desired_EMG_scale_val, 1* self.desired_EMG_scale_val]
|
||||
|
||||
# Check whether the user already synced EMG vs. EEG or not
|
||||
print(f'shape EMG signals = {np.shape(self.EMG_filtered_data1)}')
|
||||
|
||||
@@ -2882,9 +2921,9 @@ class OfflineDreamento():
|
||||
|
||||
#%% Bulk autoscoring function
|
||||
def bulk_autoscoring(self, DreamentoScorer_path = ".\\DreamentoScorer\\",\
|
||||
model_path = "DreamentoScorer_model_beta_January2023.sav",\
|
||||
standard_scaler_path = "StandardScaler_td=3_bidirectional_Trainedon_500_estimator_3013097-06_1st_iter_121222.sav",\
|
||||
feat_selection_path = "Selected_Features_BoturaAfterTD=3_Bidirectional_500_estimator_3013097-06_121222.pickle",\
|
||||
model_path = "PooledData_Full_20percent_valid.sav",\
|
||||
standard_scaler_path = "StandardScaler_PooledDataset_Full_20percent_valid.sav",\
|
||||
feat_selection_path = "Selected_Features_BoturaAfterTD=3_Bidirectional_Donders2022_19-04-2023.pickle",\
|
||||
apply_post_scoring_N1_correction = True,\
|
||||
fs = 256):
|
||||
|
||||
@@ -3073,7 +3112,7 @@ class OfflineDreamento():
|
||||
fig,AX = plt.subplots(nrows=4, figsize=(12, 6), gridspec_kw={'height_ratios': [3,3,1,1]})
|
||||
print('initiating the plot')
|
||||
# Increase font size while preserving original
|
||||
plt.legend(loc = 'right', prop={'size': 6})
|
||||
#plt.legend(loc = 'right', prop={'size': 6})
|
||||
old_fontsize = plt.rcParams["font.size"]
|
||||
plt.rcParams.update({"font.size": 9})
|
||||
ax0 = plt.subplot(4,1,1)
|
||||
@@ -3108,7 +3147,7 @@ class OfflineDreamento():
|
||||
x.append(i-1)
|
||||
y.append(p)
|
||||
x.append(i)
|
||||
ax2.step(x, y, where='post', color = 'black', linewidth = 1)
|
||||
ax2.step(x, y, where='post', color = 'black', linewidth = 2)
|
||||
rem = [i for i,j in enumerate(self.y_pred) if (self.y_pred[i]==4)]
|
||||
for i in np.arange(len(rem)) -1:
|
||||
ax2.plot([rem[i]-1, rem[i]], [-1,-1] , linewidth = 2, color = 'red')
|
||||
@@ -3124,7 +3163,7 @@ class OfflineDreamento():
|
||||
ax1.set_title(folder_autoscoring + 'EEG R')
|
||||
|
||||
self.y_pred_proba.plot(ax = ax3, kind="area", alpha=0.8, stacked=True, lw=0, color = ['black', 'olive', 'deepskyblue', 'purple', 'red'])
|
||||
|
||||
#ax3.legend().remove()
|
||||
#plt.tight_layout()
|
||||
# Save results?
|
||||
if int(self.checkbox_save_bulk_autoscoring_txt_results_val.get()) == 1:
|
||||
@@ -3167,6 +3206,7 @@ class OfflineDreamento():
|
||||
if int(self.checkbox_close_plots_val.get()) == 1:
|
||||
plt.close()
|
||||
# Store all stats in a single excel file
|
||||
|
||||
df = pd.DataFrame(data=self.all_stats)
|
||||
df = (df.T)
|
||||
path_to_save_all_stats = os.path.dirname(self.bulk_autoscoring_files_list[0]) + '\\Dreamento_all_sleep_stats.xlsx'
|
||||
@@ -4201,6 +4241,7 @@ class OfflineDreamento():
|
||||
|
||||
print('mouse cliked --> move plot')
|
||||
ax_tmp.set_xlim((np.floor(event.xdata)- int(7680/256/2), np.floor(event.xdata)+ int(7680/256/2)))
|
||||
|
||||
plt.draw()
|
||||
print(f'clicked sample{ {event.xdata}}')
|
||||
print(f'adjust xlm {(np.floor(event.xdata)- int(7680/2), np.floor(event.xdata)+ int(7680/2))}')
|
||||
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+2
-1
@@ -82,8 +82,9 @@ N.B. A complete **tutorial on how to run real-time Dreamento** can be found [HER
|
||||
```
|
||||
cd directory/to/Dreamento
|
||||
conda activate offlinedreamento
|
||||
python OfflineDreamento.py
|
||||
spyder
|
||||
```
|
||||
When spyder pops up, open ```offlinedreamento.py``` and proceed with the desired analysis. **If you are interested in autoscoring, we highly recommend this method. Otherwise, if you run offlinedreamento directly through command prompt you may get errors while autoscoring.
|
||||
You can post-process your recordings with Dreamento in three cases: (1) While having (Dreamento + Hypnodyne HDRecorder + data with other measurement modality, e.g., EMG), (2) Dreamento + Hypnodyne HDRecorder **WITHOUT** havign parallel recording with other measurement modality, and (3) recordings by ZMax only (e.g., online via HDRecorder or offline by pushing the record button on the headband).
|
||||
|
||||
1. Demo on post-processing (Dreamento + Hypnodyne HDRecorder + EMG data): [LINK](https://youtu.be/NzDdLlAd_F8)
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Mon Aug 7 13:03:03 2023
|
||||
|
||||
@author: mahjaf
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import yasa
|
||||
import mne
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
path_to_BrainAmp_file = 'P:\\3013097.06\\BrainAmpEEG_DCM\\'
|
||||
subj = 'pilot_005.vhdr'
|
||||
|
||||
raw = mne.io.read_raw_brainvision(path_to_BrainAmp_file + subj, preload = True)
|
||||
fs = raw.info['sfreq']
|
||||
ch_names = raw.info['ch_names']
|
||||
|
||||
all_markers_with_timestamps = []
|
||||
for counter, marker in enumerate(markers.values()):
|
||||
|
||||
all_markers.append(marker)
|
||||
|
||||
for counter, marker in enumerate(markers.keys()):
|
||||
all_timestamp_markers.append(marker)
|
||||
|
||||
for i in np.arange(len(all_markers)):
|
||||
all_markers_with_timestamps.append(all_markers[i]+ '__'+ all_timestamp_markers[i])
|
||||
select_marker_for_sync()
|
||||
|
||||
# =============================================================================
|
||||
# # Get the data arrays for the specified channels
|
||||
# data_a, times = raw[raw.ch_names.index('C3')]
|
||||
# data_b, _ = raw[raw.ch_names.index('TP10')]
|
||||
#
|
||||
# # Calculate the difference between channel_a and channel_b
|
||||
# channel_diff = data_a - data_b
|
||||
#
|
||||
# ch_info = mne.create_info(ch_names=['a_minus_b'], sfreq=raw.info['sfreq'], ch_types=['eeg'])
|
||||
#
|
||||
# raw_diff = mne.io.RawArray(data=channel_diff, info=ch_info)
|
||||
#
|
||||
# raw.add_channels([raw_diff], force_update_info=True)
|
||||
#
|
||||
# raw_get = raw.get_data()
|
||||
#
|
||||
# =============================================================================
|
||||
# Concatenate the new channel with the original raw data
|
||||
desired_EEG_channels = ['C3', 'TP10']
|
||||
desired_EOG_channels = ['HEOG', 'TP10']
|
||||
desired_EMG_channels = ['EMG1', 'TP10']
|
||||
desired_channels = desired_EEG_channels + desired_EOG_channels + desired_EMG_channels
|
||||
ch_indices = [raw.ch_names.index(ch) for ch in desired_channels]
|
||||
|
||||
# Compute the derivation data
|
||||
derivation_data_eeg = raw.get_data(picks=ch_indices[0]) - raw.get_data(picks=ch_indices[1])
|
||||
derivation_data_eog = raw.get_data(picks=ch_indices[2]) - raw.get_data(picks=ch_indices[3])
|
||||
derivation_data_emg = raw.get_data(picks=ch_indices[4]) - raw.get_data(picks=ch_indices[5])
|
||||
|
||||
# Create an info object for the derivation channel
|
||||
derivation_info_EEG = mne.create_info(['EEG ' + desired_channels[0] + '-' + desired_channels[1]], raw.info['sfreq'], ch_types='eeg')
|
||||
derivation_info_EOG = mne.create_info(['EOG ' + desired_channels[2] + '-' + desired_channels[3]], raw.info['sfreq'], ch_types='eog')
|
||||
derivation_info_EMG = mne.create_info(['EMG ' + desired_channels[4] + '-' + desired_channels[5]], raw.info['sfreq'], ch_types='emg')
|
||||
|
||||
# Create an Evoked object for the derivation data
|
||||
derivation_evoked_EEG = mne.io.RawArray(data=derivation_data_eeg, info=derivation_info_EEG)
|
||||
derivation_evoked_EOG = mne.io.RawArray(data=derivation_data_eog, info=derivation_info_EOG)
|
||||
derivation_evoked_EMG = mne.io.RawArray(data=derivation_data_emg, info=derivation_info_EMG)
|
||||
|
||||
# Adding new derivations
|
||||
raw.add_channels([derivation_evoked_EEG], force_update_info=True)
|
||||
raw.add_channels([derivation_evoked_EOG], force_update_info=True)
|
||||
raw.add_channels([derivation_evoked_EMG], force_update_info=True)
|
||||
|
||||
|
||||
sls = yasa.SleepStaging(raw, eeg_name=derivation_info_EEG.ch_names[0],\
|
||||
eog_name = derivation_evoked_EOG.ch_names[0],\
|
||||
emg_name = derivation_evoked_EMG.ch_names[0])
|
||||
|
||||
hypno_pred = sls.predict() # Predict the sleep stages
|
||||
hypno_pred = yasa.hypno_str_to_int(hypno_pred) # Convert "W" to 0, "N1" to 1, etc
|
||||
yasa.plot_hypnogram(hypno_pred); # Plot
|
||||
|
||||
np.savetxt('output.txt', hypno_pred, fmt='%d')
|
||||
@@ -33775,3 +33775,178 @@
|
||||
2023-02-13 13:21:53 [INFO ] Initializing the model ...
|
||||
2023-02-13 13:21:53 [INFO ] Shape:
|
||||
2023-02-13 13:21:53 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 14:21:13 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 14:21:13 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 14:21:13 [INFO ] Initializing the model ...
|
||||
2023-06-30 14:21:13 [INFO ] Shape:
|
||||
2023-06-30 14:21:13 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 14:21:43 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 14:21:43 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 14:21:43 [INFO ] Initializing the model ...
|
||||
2023-06-30 14:21:43 [INFO ] Shape:
|
||||
2023-06-30 14:21:43 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:38:32 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:38:32 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:38:32 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:38:32 [INFO ] Shape:
|
||||
2023-06-30 15:38:32 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:39:02 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:39:02 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:39:02 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:39:02 [INFO ] Shape:
|
||||
2023-06-30 15:39:02 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:39:32 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:39:32 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:39:32 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:39:32 [INFO ] Shape:
|
||||
2023-06-30 15:39:32 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:40:02 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:40:02 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:40:02 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:40:02 [INFO ] Shape:
|
||||
2023-06-30 15:40:02 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:40:33 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:40:33 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:40:33 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:40:33 [INFO ] Shape:
|
||||
2023-06-30 15:40:33 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:41:03 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:41:03 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:41:03 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:41:03 [INFO ] Shape:
|
||||
2023-06-30 15:41:03 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:41:33 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:41:33 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:41:33 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:41:33 [INFO ] Shape:
|
||||
2023-06-30 15:41:33 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:42:03 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:42:03 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:42:03 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:42:03 [INFO ] Shape:
|
||||
2023-06-30 15:42:03 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:42:34 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:42:34 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:42:34 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:42:34 [INFO ] Shape:
|
||||
2023-06-30 15:42:34 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:43:04 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:43:04 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:43:04 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:43:04 [INFO ] Shape:
|
||||
2023-06-30 15:43:04 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:43:34 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:43:34 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:43:34 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:43:34 [INFO ] Shape:
|
||||
2023-06-30 15:43:34 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:44:05 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:44:05 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:44:05 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:44:05 [INFO ] Shape:
|
||||
2023-06-30 15:44:05 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:44:35 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:44:35 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:44:35 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:44:35 [INFO ] Shape:
|
||||
2023-06-30 15:44:35 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:45:05 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:45:05 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:45:05 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:45:05 [INFO ] Shape:
|
||||
2023-06-30 15:45:05 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:45:35 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:45:35 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:45:35 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:45:35 [INFO ] Shape:
|
||||
2023-06-30 15:45:35 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:46:06 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:46:06 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:46:06 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:46:06 [INFO ] Shape:
|
||||
2023-06-30 15:46:06 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:46:36 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:46:36 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:46:36 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:46:36 [INFO ] Shape:
|
||||
2023-06-30 15:46:36 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:47:06 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:47:06 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:47:06 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:47:06 [INFO ] Shape:
|
||||
2023-06-30 15:47:06 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:47:37 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:47:37 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:47:37 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:47:37 [INFO ] Shape:
|
||||
2023-06-30 15:47:37 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:48:07 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:48:07 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:48:07 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:48:07 [INFO ] Shape:
|
||||
2023-06-30 15:48:07 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:48:37 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:48:37 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:48:37 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:48:37 [INFO ] Shape:
|
||||
2023-06-30 15:48:37 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:49:08 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:49:08 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:49:08 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:49:08 [INFO ] Shape:
|
||||
2023-06-30 15:49:08 [INFO ] (1, 7680, 1, 1)
|
||||
2023-06-30 15:49:38 [INFO ] Loading new array for prediciton...
|
||||
2023-06-30 15:49:38 [INFO ]
|
||||
=======================================
|
||||
|
||||
2023-06-30 15:49:38 [INFO ] Initializing the model ...
|
||||
2023-06-30 15:49:38 [INFO ] Shape:
|
||||
2023-06-30 15:49:38 [INFO ] (1, 7680, 1, 1)
|
||||
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
2
|
||||
0
|
||||
2
|
||||
0
|
||||
0
|
||||
0
|
||||
2
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
2
|
||||
2
|
||||
2
|
||||
0
|
||||
0
|
||||
2
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
4
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
4
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
4
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
1
|
||||
Referência em uma Nova Issue
Bloquear um usuário