-
Notifications
You must be signed in to change notification settings - Fork 0
/
signals_cutting.py
210 lines (184 loc) · 14.1 KB
/
signals_cutting.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# Used packages and libraries
import os.path
import shutil
import glob
import neurokit
import pandas as pd
import math
from datetime import datetime
from os import listdir
# Extraction paths to every used subject data. corrupted_signal_subjects are rejected subject due to incoplete data
path_of_subjects = 'C:\\Users\\Przemek\\Documents\\PILTOR_bysubject\\'
corrupted_signal_subjects = ['A018','A024','A027','A042', 'A043','A058','A059','A078','A079',
'A080','A081','A082','A083','A085','A086','A087','A088','A090','A123']
subjects = [name for name in listdir(path_of_subjects) if name not in corrupted_signal_subjects and name[0] == "A"]
### Loop for every subject
for subj in subjects:
# Preparing files and paths to process
path = "C:\\Users\\Przemek\\Documents\\PILTOR_bysubject\\" + subj + "\\"
os.chdir(path)
acq_files = glob.glob("*.acq")
if not os.path.exists('data_processing_ecg'):
os.mkdir('data_processing_ecg')
if not os.path.exists('data_processing_ppg'):
os.mkdir('data_processing_ppg')
if not os.path.exists('data_processing_eda'):
os.mkdir('data_processing_eda')
if not os.path.exists('data_processing_e4'):
os.mkdir('data_processing_e4')
# Read acq data from Biopac system
acq_data = neurokit.read_acqknowledge(acq_files[0], path, index='range')
# Getting markers for every condition from the acq file
markers_rest = acq_data[acq_data.iloc[:, 6] == 10].index
markers_observe = [idx for idx, number in enumerate(acq_data.iloc[:, 6]) if (number in [21, 22, 23, 24])]
markers_increase = [idx for idx, number in enumerate(acq_data.iloc[:, 6]) if (number in [31, 32])]
markers_decrease = [idx for idx, number in enumerate(acq_data.iloc[:, 6]) if (number in [41, 42])]
### Cutting signals
# Biopac rest
# ecg_rest = acq_data.iloc[markers_rest[19]:markers_rest[20]]['ECG100C']
# ppg_rest = acq_data.iloc[markers_rest[19]:markers_rest[20]]['PPG100C']
# ecg_rest.to_csv("data_processing_ecg\\" + subj + '_rest_ecg.csv', index=False, header=False)
# ppg_rest.to_csv("data_processing_ppg\\" + subj + '_rest_ppg.csv', index=False, header=False)
# Biopac pre- postfeedback
ecg_prefeedback = acq_data.iloc[(markers_rest[19] + 600000):markers_rest[20]]['ECG100C'];
ecg_postfeedback = acq_data.iloc[markers_rest[49]:markers_rest[50]]['ECG100C'];
ppg_prefeedback = acq_data.iloc[(markers_rest[19] + 600000):markers_rest[20]]['PPG100C'];
ppg_postfeedback = acq_data.iloc[markers_rest[49]:markers_rest[50]]['PPG100C'];
ecg_prefeedback.to_csv("data_processing_ecg\\" + subj + '_ecg_prefeedback.csv', index=False, header=False)
ecg_postfeedback.to_csv("data_processing_ecg\\" + subj + '_ecg_postfeedback.csv', index=False, header=False)
ppg_prefeedback.to_csv("data_processing_ppg\\" + subj + '_ppg_prefeedback.csv', index=False, header=False)
ppg_postfeedback.to_csv("data_processing_ppg\\" + subj + '_ppg_postfeedback.csv', index=False, header=False)
# # Biopac observed
#
# ecg_observe1 = acq_data.iloc[markers_observe[0]:(markers_observe[math.ceil(len(markers_observe)/2)] + 15000)]['ECG100C']
# ecg_observe2 = acq_data.iloc[(markers_observe[math.ceil(len(markers_observe)/2)] + 15000):(markers_observe[len(markers_observe) - 1] + 15000)]['ECG100C']
#
# ppg_observe1 = acq_data.iloc[markers_observe[0]:(markers_observe[math.ceil(len(markers_observe)/2)] + 15000)]['PPG100C']
# ppg_observe2 = acq_data.iloc[(markers_observe[math.ceil(len(markers_observe)/2)] + 15000):(markers_observe[len(markers_observe) - 1] + 15000)]['PPG100C']
#
# ecg_observe1.to_csv("data_processing_ecg\\" + subj + '_ecg_observe1.csv', index=False, header=False)
# ecg_observe2.to_csv("data_processing_ecg\\" + subj + '_ecg_observe2.csv', index=False, header=False)
#
# ppg_observe1.to_csv("data_processing_ppg\\" + subj + '_ppg_observe1.csv', index=False, header=False)
# ppg_observe2.to_csv("data_processing_ppg\\" + subj + '_ppg_observe2.csv', index=False, header=False)
#
# # Biopac increased
#
# ecg_increase = acq_data.iloc[markers_increase[0]:(markers_increase[len(markers_increase) - 1] + 15000)]['ECG100C']
# ppg_increase = acq_data.iloc[markers_increase[0]:(markers_increase[len(markers_increase) - 1] + 15000)]['PPG100C']
#
# ecg_increase.to_csv("data_processing_ecg\\" + subj + '_ecg_increase.csv', index=False, header=False)
# ppg_increase.to_csv("data_processing_ppg\\" + subj + '_ppg_increase.csv', index=False, header=False)
#
# # Biopac decrease
#
# ecg_decrease = acq_data.iloc[markers_decrease[0]:(markers_decrease[len(markers_decrease) - 1] + 15000)]['ECG100C']
# ppg_decrease = acq_data.iloc[markers_decrease[0]:(markers_decrease[len(markers_decrease) - 1] + 15000)]['PPG100C']
#
# ecg_decrease.to_csv("data_processing_ecg\\" + subj + '_ecg_decrease.csv', index=False, header=False)
# ppg_decrease.to_csv("data_processing_ppg\\" + subj + '_ppg_decrease.csv', index=False, header=False)
#
# # Empatica rest
# Read csv files from empatica data
empatica_directory = 'empatica';
ppg_e4 = pd.read_csv(path + r"\\empatica\\BVP.csv", sep=" ", header=None)
eda_e4 = pd.read_csv(path + r"\\empatica\\EDA.csv", sep=" ", header=None)
timestamp_e4 = pd.read_csv(path + r"\\empatica\\tags.csv", sep=" ", header=None)
acc_e4 = pd.read_csv(path + r"\\empatica\\ACC.csv", sep=",", header=None)
timestamp_acq = acq_data[acq_data.iloc[:, 6] == 20].index[0]
seconds_before_stamp = timestamp_e4.iloc[0] - eda_e4.iloc[0];
print(seconds_before_stamp[0])
# rest_e4_eda_onset = int(round((seconds_before_stamp[0] * 4) + (markers_rest[19] - timestamp_acq) / 500))
# rest_e4_eda_offset = int(round((seconds_before_stamp[0] * 4) + (markers_rest[20] - timestamp_acq) / 500))
# e4_rest_eda = eda_e4.iloc[rest_e4_eda_onset:rest_e4_eda_offset].to_csv("data_processing_e4\\" + subj + '_rest_e4_eda.csv', index=False, header=False)
#
# rest_e4_ppg_onset = int(round((seconds_before_stamp[0]) * 64 + (markers_rest[19] - timestamp_acq) * 0.032))
# rest_e4_ppg_offset = int(round((seconds_before_stamp[0]) * 64 + (markers_rest[20] - timestamp_acq) * 0.032))
# ppg_e4[rest_e4_ppg_onset:rest_e4_ppg_offset].to_csv("data_processing_e4\\" + subj + '_rest_e4_ppg.csv', index=False, header=False)
#
# rest_e4_acc_onset = int(round((seconds_before_stamp[0]) * 32 + (markers_rest[19] - timestamp_acq) * 0.016))
# rest_e4_acc_offset = int(round((seconds_before_stamp[0]) * 32 + (markers_rest[20] - timestamp_acq) * 0.016))
# e4_rest_acc = acc_e4[rest_e4_acc_onset:rest_e4_acc_offset].to_csv("data_processing_e4\\" + subj + '_rest_e4_acc.csv', index=False, header=False)
# E4 pre- postfeedback
prefeedback_e4_eda_onset = int(round((seconds_before_stamp[0] * 4) + ((markers_rest[19] - timestamp_acq) + 600000) * 0.002))
prefeedback_e4_ede_offset = int(round((seconds_before_stamp[0] * 4) + (markers_rest[20] - timestamp_acq) * 0.002))
eda_e4[prefeedback_e4_eda_onset:prefeedback_e4_ede_offset].to_csv("data_processing_e4\\" + subj + '_prefeedback_e4_eda.csv', index=False, header=False)
prefeedback_e4_ppg_onset = int(round((seconds_before_stamp[0] * 64) + ((markers_rest[19] - timestamp_acq) + 600000) * 0.032))
prefeedback_e4_ppg_offset = int(round((seconds_before_stamp[0] * 64) + (markers_rest[20] - timestamp_acq) * 0.032))
ppg_e4[prefeedback_e4_ppg_onset:prefeedback_e4_ppg_offset].to_csv("data_processing_e4\\" + subj + '_prefeedback_e4_ppg.csv', index=False, header=False)
prefeedback_e4_acc_onset = int(round((seconds_before_stamp[0] * 32) + ((markers_rest[19] - timestamp_acq) + 600000) * 0.016))
prefeedback_e4_acc_offset = int(round((seconds_before_stamp[0] * 32) + (markers_rest[20] - timestamp_acq) * 0.016))
acc_e4[prefeedback_e4_acc_onset:prefeedback_e4_acc_offset].to_csv("data_processing_e4\\" + subj + '_prefeedback_e4_acc.csv', index=False, header=False)
# postfeedback_e4_eda_onset = int(round((seconds_before_stamp[0] * 4) + (markers_rest[49] - timestamp_acq) * 0.002))
# postfeedback_e4_ede_offset = int(round((seconds_before_stamp[0] * 4) + (markers_rest[50] - timestamp_acq) * 0.002))
# eda_e4[postfeedback_e4_eda_onset:postfeedback_e4_ede_offset].to_csv("data_processing_e4\\" + subj + '_postfeedback_e4_eda.csv', index=False, header=False)
#
#
# postfeedback_e4_ppg_onset = int(round((seconds_before_stamp[0] * 64) + (markers_rest[49] - timestamp_acq) * 0.032))
# postfeedback_e4_ppg_offset = int(round((seconds_before_stamp[0] * 64) + (markers_rest[50] - timestamp_acq) * 0.032))
# ppg_e4[postfeedback_e4_ppg_onset:postfeedback_e4_ppg_offset].to_csv("data_processing_e4\\" + subj + '_postfeedback_e4_ppg.csv', index=False, header=False)
#
#
# postfeedback_e4_acc_onset = int(round((seconds_before_stamp[0] * 32) + (markers_rest[49] - timestamp_acq) * 0.016))
# postfeedback_e4_acc_offset = int(round((seconds_before_stamp[0] * 32) + (markers_rest[50] - timestamp_acq) * 0.016))
# acc_e4[postfeedback_e4_acc_onset:postfeedback_e4_acc_offset].to_csv("data_processing_e4\\" + subj + '_postfeedback_e4_acc.csv', index=False, header=False)
#
#
# # E4 - observe 1 and 2
#
# observe1_e4_eda_onset = int(round((seconds_before_stamp[0] * 4) + (markers_observe[0] - timestamp_acq) * 0.002))
# observe1_e4_eda_offset = int(round((seconds_before_stamp[0] * 4) + (markers_observe[math.ceil(len(markers_observe)/2)] + 15000 - timestamp_acq) * 0.002))
#
# observe2_e4_eda_onset = int(round((seconds_before_stamp[0] * 4) + (markers_observe[math.ceil(len(markers_observe) / 2)] + 15000 - timestamp_acq) * 0.002))
# observe2_e4_eda_offset = int(round((seconds_before_stamp[0] * 4) + (markers_observe[len(markers_observe) - 1] + 15000) * 0.002))
#
# eda_e4[observe1_e4_eda_onset:observe1_e4_eda_offset].to_csv("data_processing_e4\\" + subj + '_observe1_e4_eda.csv', index=False, header=False)
# eda_e4[observe2_e4_eda_onset:observe2_e4_eda_offset].to_csv("data_processing_e4\\" + subj + '_observe2_e4_eda.csv', index=False, header=False)
#
#
# observe1_e4_ppg_onset = int(round((seconds_before_stamp[0] * 64) + (markers_observe[0] - timestamp_acq) * 0.032))
# observe1_e4_ppg_offset = int(round((seconds_before_stamp[0] * 64) + (markers_observe[math.ceil(len(markers_observe)/2)] + 15000 - timestamp_acq) * 0.032))
#
# observe2_e4_ppg_onset = int(round((seconds_before_stamp[0] * 64) + (markers_observe[math.ceil(len(markers_observe) / 2)] + 15000 - timestamp_acq) * 0.032))
# observe2_e4_ppg_offset = int(round((seconds_before_stamp[0] * 64) + (markers_observe[len(markers_observe) - 1] + 15000) * 0.032))
#
# ppg_e4[observe1_e4_ppg_onset:observe1_e4_ppg_offset].to_csv("data_processing_e4\\" + subj + '_observe1_e4_ppg.csv', index=False, header=False)
# ppg_e4[observe2_e4_ppg_onset:observe2_e4_ppg_offset].to_csv("data_processing_e4\\" + subj + '_observe2_e4_ppg.csv', index=False, header=False)
#
#
# observe1_e4_acc_onset = int(round((seconds_before_stamp[0] * 32) + (markers_observe[0] - timestamp_acq) * 0.016))
# observe1_e4_acc_offset = int(round((seconds_before_stamp[0] * 32) + (markers_observe[math.ceil(len(markers_observe)/2)] + 15000 - timestamp_acq) * 0.016))
#
# observe2_e4_acc_onset = int(round((seconds_before_stamp[0] * 32) + (markers_observe[math.ceil(len(markers_observe) / 2)] + 15000 - timestamp_acq) * 0.016))
# observe2_e4_acc_offset = int(round((seconds_before_stamp[0] * 32) + (markers_observe[len(markers_observe) - 1] + 15000) * 0.016))
#
# acc_e4[observe1_e4_acc_onset:observe1_e4_acc_offset].to_csv("data_processing_e4\\" + subj + '_observe1_e4_acc.csv', index=False, header=False)
# acc_e4[observe2_e4_acc_onset:observe2_e4_acc_offset].to_csv("data_processing_e4\\" + subj + '_observe2_e4_acc.csv', index=False, header=False)
#
# # E4 - increase
#
# increase_e4_eda_onset = int(round((seconds_before_stamp[0] * 4) + (markers_increase[0] - timestamp_acq) * 0.002))
# increase_e4_eda_offset = int(round((seconds_before_stamp[0] * 4) + (markers_increase[len(markers_increase) - 1] + 15000 - timestamp_acq) * 0.002))
# eda_e4[increase_e4_eda_onset:increase_e4_eda_offset].to_csv("data_processing_e4\\" + subj + '_increase_e4_eda.csv', index=False, header=False)
#
# increase_e4_ppg_onset = int(round((seconds_before_stamp[0] * 64) + (markers_increase[0] - timestamp_acq) * 0.032))
# increase_e4_ppg_offset = int(round((seconds_before_stamp[0] * 64) + (markers_increase[len(markers_increase) - 1] + 15000 - timestamp_acq) * 0.032))
# ppg_e4[increase_e4_ppg_onset:increase_e4_ppg_offset].to_csv("data_processing_e4\\" + subj + '_increase_e4_ppg.csv', index=False, header=False)
#
# increase_e4_acc_onset = int(round((seconds_before_stamp[0] * 32) + (markers_increase[0] - timestamp_acq) * 0.016))
# increase_e4_acc_offset = int(round((seconds_before_stamp[0] * 32) + (markers_increase[len(markers_increase) - 1] + 15000 - timestamp_acq) * 0.016))
# acc_e4[increase_e4_acc_onset:increase_e4_acc_offset].to_csv("data_processing_e4\\" + subj + '_increase_e4_acc.csv', index=False, header=False)
#
# # E4 - decrease
#
# decrease_e4_eda_onset = int(round((seconds_before_stamp[0] * 4) + (markers_decrease[0] - timestamp_acq) * 0.002))
# decrease_e4_eda_offset = int(round((seconds_before_stamp[0] * 4) + (markers_decrease[len(markers_decrease) - 1] + 15000 - timestamp_acq) * 0.002))
# eda_e4[decrease_e4_eda_onset:decrease_e4_eda_offset].to_csv("data_processing_e4\\" + subj + '_decrease_e4_eda.csv', index=False, header=False)
#
# decrease_e4_ppg_onset = int(round((seconds_before_stamp[0] * 64) + (markers_decrease[0] - timestamp_acq) * 0.032))
# decrease_e4_ppg_offset = int(round((seconds_before_stamp[0] * 64) + (markers_decrease[len(markers_decrease) - 1] + 15000 - timestamp_acq) * 0.032))
# ppg_e4[decrease_e4_ppg_onset:decrease_e4_ppg_offset].to_csv("data_processing_e4\\" + subj + '_decrease_e4_ppg.csv', index=False, header=False)
#
# decrease_e4_acc_onset = int(round((seconds_before_stamp[0] * 32) + (markers_decrease[0] - timestamp_acq) * 0.016))
# decrease_e4_acc_offset = int(round((seconds_before_stamp[0] * 32) + (markers_decrease[len(markers_decrease) - 1] + 15000 - timestamp_acq) * 0.016))
# acc_e4[decrease_e4_acc_onset:decrease_e4_acc_offset].to_csv("data_processing_e4\\" + subj + '_decrease_e4_acc.csv', index=False, header=False)