-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo1.py
273 lines (192 loc) · 12.3 KB
/
demo1.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import numpy as np
import scipy.signal
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import copy
a = np.load('./data/key_data/1-11/detect_dyj2022-01-11_16-34-39.npy')
rawMomentData, rawAngleData = a[:, 0:4], a[:, -1]
assert(len(rawAngleData) == len(rawMomentData))
rawAngleData = rawAngleData.reshape(rawAngleData.shape[0], 1)
combinedData = np.hstack((rawMomentData, rawAngleData))
print(combinedData[:400, -1].argsort())
combinedData = combinedData[combinedData[:, -1].argsort()]
print(combinedData.shape)
lastValue = combinedData[0, -1]
sumValue = combinedData[0, 0:4].reshape(1,4)
avarageSafetyMoment = []
for i in range(1, combinedData.shape[0]):
if abs(combinedData[i, -1] - lastValue) < 0.01:
sumValue = np.vstack((sumValue, combinedData[i, 0:4]))
else:
avarag = np.mean(sumValue, axis=0)
var = np.std(sumValue, axis=0)
avarageSafetyMoment.append(np.hstack((avarag, var, lastValue)))
lastValue = combinedData[i, -1]
sumValue = combinedData[i, 0:4].reshape(1,4)
combinedData = np.array(avarageSafetyMoment)
print(combinedData.shape)
# for i in range(1, combinedData.shape[0]):
# for j in range(4):
# if combinedData[i, 4+j] < 4:
# # combinedData[i, 4+j] = combinedData[i - 1, 4+j]
# combinedData[i, 4+j] = 4
# for i in range(8):
# combinedData[:, i] = scipy.signal.savgol_filter(combinedData[:, i], 51, 3)
color = cm.viridis(0.7)
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2,2)
key_item = 1
combinedData[:, key_item] = scipy.signal.savgol_filter(combinedData[:, key_item], 51, 3)
combinedData[:, key_item + 4] = scipy.signal.savgol_filter(combinedData[:, key_item + 4], 51, 3)
ax1.plot(range(len(combinedData[:, key_item])), combinedData[:, key_item], color=color)
r1 = list(map(lambda x: x[0]-3 * x[1], zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
r2 = list(map(lambda x: x[0]+2 * x[1], zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
ax1.fill_between(range(len(combinedData[:, key_item])), r1, r2, color=color, alpha=0.2)
plt.ylabel('Torque (N·m)')
# ax1.title('Patient Torque')
key_item = 3
# temp = list(combinedData[:, key_item])
# temp.shift(len(combinedData) // 2)
# combinedData[:, key_item] = np.array(temp)
temp = copy.copy(combinedData[:len(combinedData) // 2, key_item ])
combinedData[:len(combinedData) // 2, key_item ] = combinedData[len(combinedData) // 2:, key_item ]
combinedData[len(combinedData) // 2:, key_item ] = temp
temp = copy.copy(combinedData[:len(combinedData) // 2, key_item + 4])
combinedData[:len(combinedData) // 2, key_item + 4 ] = combinedData[len(combinedData) // 2:, key_item + 4]
combinedData[len(combinedData) // 2:, key_item + 4] = temp
combinedData[:, key_item] = scipy.signal.savgol_filter(combinedData[:, key_item], 51, 3)
combinedData[:, key_item + 4] = scipy.signal.savgol_filter(combinedData[:, key_item + 4], 51, 3)
# combinedData[len(combinedData) // 2:, key_item ], combinedData[:len(combinedData) // 2, key_item ] = combinedData[:len(combinedData) // 2, key_item ] ,combinedData[len(combinedData) // 2:, key_item ]
# combinedData[len(combinedData) // 2:, key_item + 4], combinedData[:len(combinedData) // 2, key_item + 4] = combinedData[:len(combinedData) // 2, key_item + 4] ,combinedData[len(combinedData) // 2:, key_item + 4]
# plt.plot(combinedData[:, key_item], color=color)
ax1.plot(range(len(combinedData[:, key_item])), -1 * combinedData[:, key_item], color=cm.viridis(0.4))
r1 = list(map(lambda x: -1 * (x[0]-3 * x[1]), zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
r2 = list(map(lambda x: -1 * (x[0]+2 * x[1]), zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
ax1.fill_between(range(len(combinedData[:, key_item])), r1, r2, color=cm.viridis(0.4), alpha=0.2)
ax1.legend(['Right Hip', 'Left Hip'])
ax1.set_ylabel('Torque (N·m)')
ax1.set_title('Patient Torque')
key_item = 0
combinedData[:, key_item] = scipy.signal.savgol_filter(combinedData[:, key_item], 51, 3)
combinedData[:, key_item + 4] = scipy.signal.savgol_filter(combinedData[:, key_item + 4], 51, 3)
ax3.plot(range(len(combinedData[:, key_item])), combinedData[:, key_item], color=color)
r1 = list(map(lambda x: x[0]-3 * x[1], zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
r2 = list(map(lambda x: x[0]+2 * x[1], zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
ax3.fill_between(range(len(combinedData[:, key_item])), r1, r2, color=color, alpha=0.2)
plt.ylabel('Torque (N·m)')
key_item = 2
# temp = list(combinedData[:, key_item])
# temp.shift(len(combinedData) // 2)
# combinedData[:, key_item] = np.array(temp)
temp = copy.copy(combinedData[:len(combinedData) // 2, key_item ])
combinedData[:len(combinedData) // 2, key_item ] = combinedData[len(combinedData) // 2:, key_item ]
combinedData[len(combinedData) // 2:, key_item ] = temp
temp = copy.copy(combinedData[:len(combinedData) // 2, key_item + 4])
combinedData[:len(combinedData) // 2, key_item + 4 ] = combinedData[len(combinedData) // 2:, key_item + 4]
combinedData[len(combinedData) // 2:, key_item + 4] = temp
combinedData[:, key_item] = scipy.signal.savgol_filter(combinedData[:, key_item], 51, 3)
combinedData[:, key_item + 4] = scipy.signal.savgol_filter(combinedData[:, key_item + 4], 51, 3)
# combinedData[len(combinedData) // 2:, key_item ], combinedData[:len(combinedData) // 2, key_item ] = combinedData[:len(combinedData) // 2, key_item ] ,combinedData[len(combinedData) // 2:, key_item ]
# combinedData[len(combinedData) // 2:, key_item + 4], combinedData[:len(combinedData) // 2, key_item + 4] = combinedData[:len(combinedData) // 2, key_item + 4] ,combinedData[len(combinedData) // 2:, key_item + 4]
# plt.plot(combinedData[:, key_item], color=color)
ax3.plot(range(len(combinedData[:, key_item])), -1 * combinedData[:, key_item], color=cm.viridis(0.4))
r1 = list(map(lambda x: -1 * (x[0]-3 * x[1]), zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
r2 = list(map(lambda x: -1 * (x[0]+2 * x[1]), zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
ax3.fill_between(range(len(combinedData[:, key_item])), r1, r2, color=cm.viridis(0.4), alpha=0.2)
ax3.legend(['Right Knee', 'Left Knee'])
ax3.set_ylabel('Torque (N·m)')
a = np.load('./data/key_data/1-12/detect_hkb2022-01-12_16-56-02.npy')
a = a[:,:2500]
rawMomentData, rawAngleData = a[:, 0:4], a[:, -1]
assert(len(rawAngleData) == len(rawMomentData))
rawAngleData = rawAngleData.reshape(rawAngleData.shape[0], 1)
combinedData = np.hstack((rawMomentData, rawAngleData))
print(combinedData[:400, -1].argsort())
combinedData = combinedData[combinedData[:, -1].argsort()]
print(combinedData.shape)
lastValue = combinedData[0, -1]
sumValue = combinedData[0, 0:4].reshape(1,4)
avarageSafetyMoment = []
for i in range(1, combinedData.shape[0]):
if abs(combinedData[i, -1] - lastValue) < 0.01:
sumValue = np.vstack((sumValue, combinedData[i, 0:4]))
else:
avarag = np.mean(sumValue, axis=0)
var = np.std(sumValue, axis=0)
avarageSafetyMoment.append(np.hstack((avarag, var, lastValue)))
lastValue = combinedData[i, -1]
sumValue = combinedData[i, 0:4].reshape(1,4)
combinedData = np.array(avarageSafetyMoment)
print(combinedData.shape)
# for i in range(1, combinedData.shape[0]):
# for j in range(4):
# if combinedData[i, 4+j] < 4:
# # combinedData[i, 4+j] = combinedData[i - 1, 4+j]
# combinedData[i, 4+j] = 4
# for i in range(8):
# combinedData[:, i] = scipy.signal.savgol_filter(combinedData[:, i], 51, 3)
color = cm.viridis(0.7)
key_item = 1
combinedData[:, key_item] = scipy.signal.savgol_filter(combinedData[:, key_item], 51, 3)
combinedData[:, key_item + 4] = scipy.signal.savgol_filter(combinedData[:, key_item + 4], 51, 3)
ax2.plot(range(len(combinedData[:, key_item])), combinedData[:, key_item], color=color)
r1 = list(map(lambda x: x[0]-3 * x[1], zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
r2 = list(map(lambda x: x[0]+2 * x[1], zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
ax2.fill_between(range(len(combinedData[:, key_item])), r1, r2, color=color, alpha=0.2)
plt.ylabel('Torque (N·m)')
# ax1.title('Patient Torque')
key_item = 3
# temp = list(combinedData[:, key_item])
# temp.shift(len(combinedData) // 2)
# combinedData[:, key_item] = np.array(temp)
temp1 = copy.copy(combinedData[:len(combinedData) // 2, key_item ])
temp2 = copy.copy(combinedData[len(combinedData) // 2:, key_item ])
combinedData[:, key_item] = np.hstack((temp2, temp1))
temp1 = copy.copy(combinedData[:len(combinedData) // 2, key_item + 4 ])
temp2 = copy.copy(combinedData[len(combinedData) // 2:, key_item + 4 ])
combinedData[:, key_item + 4] = np.hstack((temp2, temp1))
combinedData[:, key_item] = scipy.signal.savgol_filter(combinedData[:, key_item], 51, 3)
combinedData[:, key_item + 4] = scipy.signal.savgol_filter(combinedData[:, key_item + 4], 51, 3)
# temp = copy.copy(combinedData[:len(combinedData) // 2, key_item + 4])
# combinedData[:len(combinedData) // 2, key_item + 4 ] = combinedData[len(combinedData) // 2:, key_item + 4]
# combinedData[len(combinedData) // 2:, key_item + 4] = temp
# combinedData[len(combinedData) // 2:, key_item ], combinedData[:len(combinedData) // 2, key_item ] = combinedData[:len(combinedData) // 2, key_item ] ,combinedData[len(combinedData) // 2:, key_item ]
# combinedData[len(combinedData) // 2:, key_item + 4], combinedData[:len(combinedData) // 2, key_item + 4] = combinedData[:len(combinedData) // 2, key_item + 4] ,combinedData[len(combinedData) // 2:, key_item + 4]
# plt.plot(combinedData[:, key_item], color=color)
ax2.plot(range(len(combinedData[:, key_item])), -1 * combinedData[:, key_item], color=cm.viridis(0.4))
r1 = list(map(lambda x: -1 * (x[0]-3 * x[1]), zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
r2 = list(map(lambda x: -1 * (x[0]+2 * x[1]), zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
ax2.fill_between(range(len(combinedData[:, key_item])), r1, r2, color=cm.viridis(0.4), alpha=0.2)
ax2.legend(['Right Hip', 'Left Hip'])
ax2.set_ylabel('Torque (N·m)')
ax2.set_title('Healthy People Torque')
key_item = 0
combinedData[:, key_item] = scipy.signal.savgol_filter(combinedData[:, key_item], 51, 3)
combinedData[:, key_item + 4] = scipy.signal.savgol_filter(combinedData[:, key_item + 4], 51, 3)
ax4.plot(range(len(combinedData[:, key_item])), combinedData[:, key_item], color=color)
r1 = list(map(lambda x: x[0]-3 * x[1], zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
r2 = list(map(lambda x: x[0]+2 * x[1], zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
ax4.fill_between(range(len(combinedData[:, key_item])), r1, r2, color=color, alpha=0.2)
plt.ylabel('Torque (N·m)')
key_item = 2
# temp = list(combinedData[:, key_item])
# temp.shift(len(combinedData) // 2)
# combinedData[:, key_item] = np.array(temp)
temp1 = copy.copy(combinedData[:len(combinedData) // 2, key_item ])
temp2 = copy.copy(combinedData[len(combinedData) // 2:, key_item ])
combinedData[:, key_item] = np.hstack((temp2, temp1))
temp1 = copy.copy(combinedData[:len(combinedData) // 2, key_item + 4 ])
temp2 = copy.copy(combinedData[len(combinedData) // 2:, key_item + 4 ])
combinedData[:, key_item + 4] = np.hstack((temp2, temp1))
combinedData[:, key_item] = scipy.signal.savgol_filter(combinedData[:, key_item], 51, 3)
combinedData[:, key_item + 4] = scipy.signal.savgol_filter(combinedData[:, key_item + 4], 51, 3)
# combinedData[len(combinedData) // 2:, key_item ], combinedData[:len(combinedData) // 2, key_item ] = combinedData[:len(combinedData) // 2, key_item ] ,combinedData[len(combinedData) // 2:, key_item ]
# combinedData[len(combinedData) // 2:, key_item + 4], combinedData[:len(combinedData) // 2, key_item + 4] = combinedData[:len(combinedData) // 2, key_item + 4] ,combinedData[len(combinedData) // 2:, key_item + 4]
# plt.plot(combinedData[:, key_item], color=color)
ax4.plot(range(len(combinedData[:, key_item])), -1 * combinedData[:, key_item], color=cm.viridis(0.4))
r1 = list(map(lambda x: -1 * (x[0]-3 * x[1]), zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
r2 = list(map(lambda x: -1 * (x[0]+2 * x[1]), zip(combinedData[:, key_item], combinedData[:, key_item + 4])))
ax4.fill_between(range(len(combinedData[:, key_item])), r1, r2, color=cm.viridis(0.4), alpha=0.2)
ax4.legend(['Right Knee', 'Left Knee'])
ax4.set_ylabel('Torque (N·m)')
plt.show()