-
Notifications
You must be signed in to change notification settings - Fork 0
/
Epochs.py
78 lines (57 loc) · 1.96 KB
/
Epochs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import neurokit2 as nk
import pandas as pd
import numpy as np
def getMarkers(marker, timestamps):
videos = list()
onset = list()
offset = list()
for timestamp, markers in zip(timestamps, marker):
if markers[1] == "1" and "baseline" not in markers:
offset.append(timestamp)
videos.append(markers[0])
elif markers[1] == "1" and "baseline" in markers:
offset.append(timestamp)
videos.append(markers[0])
elif markers[1] == "0":
onset.append(timestamp)
return onset, offset, videos
def getMarkersIndex(onset, offset, time_Opensignals):
onset_index = list()
offset_index = list()
for i in range(0, len(onset)):
onset_index.append(np.where(time_Opensignals >= onset[i])[0][0])
offset_index.append(np.where(time_Opensignals <= offset[i])[0][-1])
return onset_index, offset_index
def CalculateEventsDiff(onset, offset):
events_diff = list()
for i in range(0, len(onset)):
events_diff.append(offset[i] - onset[i])
return events_diff
def getOnset4sec(epochs):
onset_4s = {}
for keys in epochs.keys():
onset_list = list()
for i in range(0, len(epochs[keys]["Time"]), 4000):
onset_list.append(i)
onset_4s[keys] = onset_list
return onset_4s
def getEpochs4sec(epochs, onset_4s, fs, epoch_duration=4):
data = {}
for keys in epochs.keys():
d = {
"Time": epochs[keys]["Time"],
"ECG": epochs[keys]["ECG"],
"EDA": epochs[keys]["EDA"],
"EDA_Clean": epochs[keys]["EDA_Clean"],
"EDA_Tonic": epochs[keys]["EDA_Tonic"],
"EDA_Phasic": epochs[keys]["EDA_Phasic"],
}
df = pd.DataFrame(data=d)
data[keys] = nk.epochs_create(
df,
events=onset_4s[keys],
sampling_rate=fs,
epochs_start=0,
epochs_end=epoch_duration,
)
return data