/
angle_velocity_acceleration.py
405 lines (387 loc) · 14.9 KB
/
angle_velocity_acceleration.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 15 16:30:00 2018
@author: monakhov
"""
import numpy as np
import matplotlib.pyplot as plt
from savitzky_golay import savitzky_golay
arr_test_subjects = ['Lasse', 'Ramin', 'Jani', 'Antti', 'xingyang ni','Nahid', 'Vida', 'Ling yu',
'Jari', 'Pouria','Sujeet','emre', 'Adriana', 'kashyap', 'You yu', 'Peter',
'Kimmo', 'Yuri', 'Kalle', 'Toni']
# =============================================================================
# clip='armor'
# cuts = [8, 26.026, 38.672, 50.684]
# clip_length_sec = 66
# =============================================================================
# =============================================================================
# clip='martial'
# cuts = [12.56, 21.76, 44.76, 54.76]
# clip_length_sec = 62
# arr_test_subjects = ['Lasse', 'Ramin', 'Jani', 'Antti', 'xingyang ni','Nahid', 'Vida', 'Ling yu',
# 'Jari', 'Sujeet', 'Adriana', 'kashyap', 'You yu', 'Peter',
# 'Kimmo', 'Yuri', 'Kalle', 'Toni']
# =============================================================================
clip='lion'
cuts = [11.011, 32.866, 55.122, 67.034]
clip_length_sec = 76
cuts_small = np.array([int(x*1000/50) for x in cuts])
res = {}
#%%
seg_length = 250
w = seg_length/1000
folder_name = 'yaw_diff_max/'+str(seg_length)+'/'
######################################################################
seconds_arr = np.arange(0,clip_length_sec,w)*1000
#####################################################
seconds_cuts = []
for cut in cuts:
seconds_cuts.append(np.argmin(np.abs(seconds_arr-cut*1000)))#array of indeces for cuts
#print(second)
tmp_indexes = []
jjj=0
for (ind,ttt) in enumerate(data['Vida'][clip]['time']):
if ttt/1000>seconds_cuts[jjj]:
tmp_indexes.append(ind)
jjj += 1
if jjj >= len(seconds_cuts):
break
#%%
#seconds_cuts = [19,39,59,79,99,119,139]
res = np.zeros((len(arr_test_subjects),len(seconds_arr)))
for cur_iter,user in enumerate(arr_test_subjects):
tmp_clip = []
tmp_arr = []
current_sec_barrier = 0
i = 0
#current_trajectory = savitzky_golay(np.array(data[user][clip]['yaw']), window_size=11, order=3,deriv=0)
current_trajectory = np.array(data[user][clip]['yaw'])
while (i < len(data[user][clip]['time']) and current_sec_barrier < len(seconds_arr) ):
if (data[user][clip]['time'][i] >= seconds_arr[current_sec_barrier] and tmp_clip != []):
# abs_diff = np.abs([s-tmp_clip[0] for s in tmp_clip])
# shortest_abs_diff = np.minimum(abs_diff,360-abs_diff)
# shortest_abs_diff = abs_diff
shortest_abs_diff = np.max(tmp_clip) - np.min(tmp_clip)
#shortest_abs_diff = tmp_clip[-1] - tmp_clip[0]
tmp_arr.append(np.max(shortest_abs_diff))
current_sec_barrier += 1
tmp_clip = []
# if seconds_arr[current_sec_barrier] >= 159*1000:
# break
tmp_clip.append(current_trajectory[i])
i += 1
#if (len(tmp_clip) != 0):
# abs_diff = np.abs([s-tmp_clip[0] for s in tmp_clip])
# shortest_abs_diff = np.minimum(abs_diff,360-abs_diff)
# tmp_arr.append(np.max(shortest_abs_diff))
# tmp_clip = []
#tmp_arr = tmp_arr/np.max(tmp_arr)
res[cur_iter,:] = tmp_arr
#%%
#folder_name='range/martial/'
#plt.ioff()
for cur_iter,user in enumerate(arr_test_subjects):
plt.figure()
plt.bar(seconds_arr/1000,res[cur_iter,:],width=(-1)*w,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,res[cur_iter,seconds_cuts],width=(-1)*w,align='edge')
plt.title('exploration range: '+user)
plt.xlabel('time, sec')
plt.ylabel('exploration range, degrees')
#plt.ylim( (0, 100) )
# plt.savefig(folder_name+user+'.png',dpi=200)
# plt.close()
#plt.ion()
#%%
#plt.ioff()
plt.figure()
meanRange = np.mean(res,axis=0)
plt.bar(seconds_arr/1000,meanRange,width=(-1)*w,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,meanRange[seconds_cuts],width=(-1)*w,align='edge', label='scene cut')
#plt.title('Average exploration range over users:')
plt.xlabel('Time (s)', fontsize=16)
plt.ylabel('Exploration range (degrees)', fontsize=16)
plt.legend()
plt.ylim( (0, 20) )
#plt.savefig(folder_name+'1average.png',dpi=200)
#plt.close()
#plt.ion()
#plt.savefig('SRM_Lions.jpg',dpi=600)
#%%
####################################
#Velocity values
##########################################
#clip='helsinki_na'
#cuts = []
#clip_length_sec = data['Vida'][clip]['time'][-1]/1000
seg_length = 250
w = seg_length/1000
folder_name = 'velocity/'+str(seg_length)+'/'
######################################################################
seconds_arr = np.arange(0,clip_length_sec,w)*1000
#####################################################
seconds_cuts = []
for cut in cuts:
seconds_cuts.append(np.argmin(np.abs(seconds_arr-cut*1000)))
#print(second)
#%%
res2 = np.zeros((len(arr_test_subjects),len(seconds_arr)))
tmp_velocities = []
for cur_iter,user in enumerate(arr_test_subjects):
tmp_clip = []
tmp_arr = []
current_sec_barrier = 0
i = 0
current_trajectory = savitzky_golay(np.array(data[user][clip]['yaw']), window_size=11, order=3,deriv=0)
velocity = np.gradient(current_trajectory, data[user][clip]['time'])*1000
tmp_velocities.append(velocity)
while (i < len(data[user][clip]['time']) and current_sec_barrier < len(seconds_arr) ):
if (data[user][clip]['time'][i] >= seconds_arr[current_sec_barrier] and tmp_clip != []):
tmp_arr.append(np.mean(np.abs(tmp_clip)))
current_sec_barrier += 1
tmp_clip = []
# if current_sec_barrier >= 159:
# break
tmp_clip.append(velocity[i])
if current_sec_barrier == 0:
tmp_clip[-1] = 0
i += 1
#if (len(tmp_clip) != 0):
# abs_diff = np.abs([s-tmp_clip[0] for s in tmp_clip])
# shortest_abs_diff = np.minimum(abs_diff,360-abs_diff)
# tmp_arr.append(np.max(shortest_abs_diff))
# tmp_clip = []
res2[cur_iter,:] = tmp_arr
#%%
folder_name='velocity/martial/'
plt.ioff()
for cur_iter,user in enumerate(arr_test_subjects):
plt.figure()
plt.bar(seconds_arr/1000,res2[cur_iter,:],width=-w,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,res2[cur_iter,seconds_cuts],width=-w,align='edge')
plt.title('Angular speed: '+user)
plt.xlabel('time, sec')
plt.ylabel('angular speed, degrees/sec')
plt.ylim( (0, 250) )
plt.savefig(folder_name+user+'.png',dpi=200)
plt.close()
plt.ion()
#%%
#plt.ioff()
meanRange = np.mean(res2,axis=0)
plt.bar(seconds_arr/1000,meanRange,width=-w,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,meanRange[seconds_cuts],width=-w,align='edge', label='scene cut')
#plt.title('Angular speed average: Lions')
#plt.xlabel('time, sec')
#plt.ylabel('angular speed, degrees/sec')
plt.ylim( (0, 70) )
plt.xlabel('Time (s)', fontsize=16)
plt.legend()
plt.ylabel('Angular speed (degrees per sec)', fontsize=16)
#plt.savefig(folder_name+'1average'+'.png',dpi=200)
#plt.close()
#plt.ion()
#%%
tmp_velocities = np.abs(np.array(tmp_velocities))
plt.plot(np.arange(tmp_velocities.shape[1])*50/1000,np.mean(tmp_velocities,axis=0))
plt.vlines(cuts_small*50/1000,ymin=0,ymax=60,color='orange', label='scene cut')
plt.xlabel('time, sec',fontsize=14)
plt.ylabel('angular speed, degrees/sec',fontsize=14)
plt.legend(fontsize=14)
####################################
#Acceleration values
##########################################
#%%
seg_length = 250
w = seg_length/1000
folder_name = 'acceleration/'+str(seg_length)+'_mean/'
######################################################################
seconds_arr = np.arange(0,clip_length_sec,w)*1000
#####################################################
seconds_cuts = []
for cut in cuts:
seconds_cuts.append(np.argmin(np.abs(seconds_arr-cut*1000)))
#print(second)
#%%
res3 = np.zeros((len(arr_test_subjects),len(seconds_arr)))
for cur_iter,user in enumerate(arr_test_subjects):
tmp_clip = []
tmp_arr = []
current_sec_barrier = 0
i = 0
current_trajectory = savitzky_golay(np.array(data[user][clip]['yaw']), window_size=11, order=3,deriv=0)
velocity = np.gradient(current_trajectory, data[user][clip]['time'])*1000
acceleration = np.gradient(velocity, data[user][clip]['time'])*1000
while (i < len(data[user][clip]['time']) and current_sec_barrier < len(seconds_arr) ):
if (data[user][clip]['time'][i] >= seconds_arr[current_sec_barrier] and tmp_clip != []):
tmp_arr.append(np.median(np.abs(tmp_clip)))
# upper_quartile = np.percentile(np.abs(tmp_clip), 95,interpolation='nearest')
# lower_quartile = np.percentile(np.abs(tmp_clip), 5,interpolation='nearest')
# tmp_arr.append(upper_quartile)
# tmp_arr.append(lower_quartile)
current_sec_barrier += 1
tmp_clip = []
# if current_sec_barrier >= 159:
# break
tmp_clip.append(acceleration[i])
if current_sec_barrier == 0:
tmp_clip[-1] = 0
i += 1
res3[cur_iter,:] = tmp_arr#/np.max(tmp_arr)
#%%
folder_name='acceleration/martial/'
plt.ioff()
for cur_iter,user in enumerate(arr_test_subjects):
plt.bar(seconds_arr/1000,res3[cur_iter,:],width=-w,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,res3[cur_iter,seconds_cuts],width=-w,align='edge')
plt.title('Angular acceleration: '+user)
plt.xlabel('time, sec')
plt.ylabel('angular acceleration, degrees/sec^2')
plt.ylim( (0, np.max(res3) ))
plt.savefig(folder_name+user+'.png',dpi=200)
plt.close()
plt.ion()
#%%
#plt.ioff()
meanRange = np.mean(res3,axis=0)
plt.bar(seconds_arr/1000,meanRange,width=-w,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,meanRange[seconds_cuts],width=-w,align='edge', label='scene cut')
#plt.title('Angular acceleration mean: Martial training')
#plt.xlabel('time, sec')
#plt.ylabel('angular acceleration, degrees/sec^2')
plt.ylim( (0, 280) )
plt.xlabel('Time (s)', fontsize=16)
plt.ylabel('Angular acceleration (degrees per $sec^2$)', fontsize=16)
plt.legend()
#plt.savefig(folder_name+'1average'+'.png',dpi=200)
#plt.close()
#plt.ion()
###############################################
#computing number of head turns
#%%
seg_length = 2000
folder_name = 'num_of_turns/1000/'
######################################################################
seconds_arr = np.arange(2,160,2)*1000
#####################################################
seconds_cuts = []
for cur_iter,second in enumerate(seconds_arr):
if second%20000 == 0:
seconds_cuts.append(cur_iter)
#%%
#seconds_cuts = [19,39,59,79,99,119,139]
res4 = np.zeros((len(arr_test_subjects),len(seconds_arr)))
for cur_iter,user in enumerate(arr_test_subjects):
tmp_clip = []
tmp_arr = []
current_sec_barrier = 0
i = 0
turns_buffer = [0,0,0,0,0,0,0,0,0,0]
prev_value = 0
num_of_turns = 0
while (i < len(data[user][clip]['time']) and current_sec_barrier < len(seconds_arr) ):
if (data[user][clip]['time'][i] >= seconds_arr[current_sec_barrier]):
tmp_arr.append(num_of_turns)
current_sec_barrier += 1
num_of_turns = 0
# if seconds_arr[current_sec_barrier] >= 159*1000:
# break
if data[user][clip]['yaw'][i] > prev_value:
turns_buffer.pop(0)
turns_buffer.append(1)
else:
turns_buffer.pop(0)
turns_buffer.append(-1)
prev_value = data[user][clip]['yaw'][i]
i += 1
if (sum(turns_buffer[:5])== 5 and sum(turns_buffer[5:]) == -5) or (sum(turns_buffer[:5])== -5 and sum(turns_buffer[5:]) == 5):
num_of_turns+=1
res4[cur_iter,:] = tmp_arr
#%%
for cur_iter,user in enumerate(arr_test_subjects):
plt.figure()
plt.bar(seconds_arr/1000,res4[cur_iter,:],width=-1,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,res4[cur_iter,seconds_cuts],width=-1,align='edge')
plt.title('number of turns: '+user)
# plt.ylim( (0, 600) )
#%%
meanRange = np.median(res4,axis=0)
plt.bar(seconds_arr/1000,meanRange,width=-1,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,meanRange[seconds_cuts],width=-1,align='edge')
plt.title('mean number of turns')
#%%
#%%
#############################
##############################
#correlation
##############################
###############################
seg_length = 500
w = seg_length/1000
folder_name = 'correlation/'+str(seg_length)+'/'
######################################################################
seconds_arr = np.arange(0,160,w)*1000
#####################################################
seconds_cuts = []
for cur_iter,second in enumerate(seconds_arr):
if second%20000 == 0:
seconds_cuts.append(cur_iter)
#%%
#seconds_cuts = [19,39,59,79,99,119,139]
res = np.zeros((len(arr_test_subjects),len(seconds_arr)))
for cur_iter,user in enumerate(arr_test_subjects):
tmp_clip = []
tmp_arr = []
current_sec_barrier = 0
i = 0
current_trajectory = savitzky_golay(np.array(data[user][clip]['yaw']), window_size=11, order=3,deriv=0)
while (i < len(data[user][clip]['time']) and current_sec_barrier < len(seconds_arr) ):
if (data[user][clip]['time'][i] >= seconds_arr[current_sec_barrier] and tmp_clip != []):
# abs_diff = np.abs([s-tmp_clip[0] for s in tmp_clip])
# shortest_abs_diff = np.minimum(abs_diff,360-abs_diff)
# shortest_abs_diff = abs_diff
shortest_abs_diff = np.max(tmp_clip) - np.min(tmp_clip)
tmp_arr.append(np.max(shortest_abs_diff))
current_sec_barrier += 1
tmp_clip = []
# if seconds_arr[current_sec_barrier] >= 159*1000:
# break
tmp_clip.append(current_trajectory[i])
i += 1
#if (len(tmp_clip) != 0):
# abs_diff = np.abs([s-tmp_clip[0] for s in tmp_clip])
# shortest_abs_diff = np.minimum(abs_diff,360-abs_diff)
# tmp_arr.append(np.max(shortest_abs_diff))
# tmp_clip = []
res[cur_iter,:] = tmp_arr
#%%
plt.ioff()
for cur_iter,user in enumerate(arr_test_subjects):
plt.figure()
tmp = res[cur_iter,:]
tmp = tmp - np.mean(tmp)
norm = np.sum(tmp ** 2)
cur_corr = (np.correlate(tmp, tmp, mode='full')/norm)[len(tmp)-1:]
plt.bar(seconds_arr/1000,cur_corr,width=(-1)*w,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,cur_corr[seconds_cuts],width=(-1)*w,align='edge')
plt.title('correlation: '+user)
plt.xlabel('shift, sec')
plt.ylabel('correlation value')
plt.savefig(folder_name+user+'.png',dpi=200)
plt.close()
plt.ion()
#%%
plt.ioff()
#plt.figure()
meanRange = np.mean(res,axis=0)
tmp = meanRange - np.mean(meanRange)
norm = np.sum(tmp ** 2)
cur_corr = (np.correlate(tmp, tmp, mode='full')/norm)[len(tmp)-1:]
plt.bar(seconds_arr/1000,cur_corr,width=(-1)*w,align='edge')
plt.bar(seconds_arr[seconds_cuts]/1000,cur_corr[seconds_cuts],width=(-1)*w,align='edge')
plt.title('average correlation')
plt.xlabel('shift, sec')
plt.ylabel('correlation value')
plt.savefig(folder_name+'1average.png',dpi=200)
plt.close()
plt.ion()
#%%