forked from Prattbuw/Treadmill_Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep_amplitude_by_frames.py
More file actions
63 lines (52 loc) · 2.22 KB
/
step_amplitude_by_frames.py
File metadata and controls
63 lines (52 loc) · 2.22 KB
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
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import h5py
import os
import math
#matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import pandas as pd
import seaborn as sea
import scipy.signal
from scipy import signal
#update to sum movement over frames of step period
# step_period = stance_start: stance_start-1
# calculate dx and dy over each frame to the end of step
# calculate amplitude for each frame to the end of step
# sum total for step length (more accurate, incorporates more of curve)
def step_amplitude_by_frames(stance_start, stance_end, time_align_x_pos, time_align_y_pos):
step_amp_store=[]
step_time_store=[] # frame number of when stance is entered
for leg in range(0,len(stance_start)):
# use each stance start as a point of reference and find the next stance end point
step_amp=[]
step_frame = []
for stance in range(0,len(stance_start[leg])):
sum_amp = []
itr=0
# go until the next stance is found
end_idx=0
while stance_end[leg][itr] < stance_start [leg][stance]:
itr=itr+1 # iterate through to find next end
if itr > len(stance_end[leg])-1: # deals with boundary condition
break
if itr > len(stance_end[leg])-1:
# if step (i.e. stance) is not completed then ignore the last stance initiation
pass
else:
# compute step length
step_frame.append(stance_start [leg][stance])
step_range = [i for i in range(stance_start[leg][stance],stance_end[leg][itr]+1)]
dx = np.diff(time_align_x_pos[0][0][step_range])
dy = np.diff(time_align_y_pos[0][0][step_range])
for dx_idx in range(0, len(dx)):
amplitude = np.sqrt(math.pow(dx[dx_idx],2) + math.pow(dy[dx_idx],2))
sum_amp.append(amplitude)
single_step_amp = np.sum(sum_amp)
step_amp.append(single_step_amp)
step_amp_store.append(np.array(step_amp))
step_time_store.append(np.array(step_frame))
return(step_amp_store, step_time_store)