-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_data_set.py
135 lines (119 loc) · 6.81 KB
/
generate_data_set.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
import matplotlib.pyplot as plt
from GaitAnaylsisToolkit.LearningTools.Trainer import TPGMMTrainer, GMMTrainer, TPGMMTrainer_old
from GaitAnaylsisToolkit.LearningTools.Runner import GMMRunner, TPGMMRunner_old
from GaitAnaylsisToolkit.LearningTools.Runner import TPGMMRunner
from scipy import signal
import numpy as np
from GaitAnaylsisToolkit.Session import ViconGaitingTrial
def get_joint_angles(files, indecies, sides):
"""
:param files:
:param indecies:
:param sides:
:param lables:
:return:
"""
angles = {}
angles["hip"] = []
angles["knee"] = []
angles["ankle"] = []
angles2 = {}
angles2["Rhip"] = []
angles2["Rknee"] = []
angles2["Rankle"] = []
angles2["Lhip"] = []
angles2["Lknee"] = []
angles2["Lankle"] = []
samples = []
for file, i, side in zip(files, indecies, sides):
trial = ViconGaitingTrial.ViconGaitingTrial(vicon_file=file)
trial.create_index_seperators()
body = trial.get_joint_trajectories()
if side == "L":
hip_angle = body.left.hip[i].angle.x.data
knee_angle = body.left.knee[i].angle.x.data
ankle_angle = body.left.ankle[i].angle.x.data
else:
hip_angle = body.right.hip[i].angle.x.data
knee_angle = body.right.knee[i].angle.x.data
ankle_angle = body.right.ankle[i].angle.x.data
angles["hip"].append(hip_angle)
angles["knee"].append(knee_angle)
angles["ankle"].append(ankle_angle)
samples.append(len(hip_angle))
sample_size = min(samples)
# for i in range(len(files)):
# angles2["hip"].append(signal.resample(angles["hip"][i], sample_size))
# angles2["knee"].append(signal.resample(angles["knee"][i], sample_size))
# angles2["ankle"].append(signal.resample(angles["ankle"][i], sample_size))
for i in range(len(files)):
angles2["Lhip"].append(np.deg2rad(angles["hip"][i]))
angles2["Lknee"].append( np.deg2rad(angles["knee"][i]))
angles2["Lankle"].append( -(np.deg2rad(angles["ankle"][i])) )
angles2["Rhip"].append( np.deg2rad(np.flip(angles["hip"][i])))
angles2["Rknee"].append( np.deg2rad(np.flip(angles["knee"][i])))
angles2["Rankle"].append(np.deg2rad(np.flip(angles["ankle"][i])))
return angles2
def get_data():
angles = get_joint_angles(["/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_00/subject_00 walk_00.csv",
"/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_01/subject_01_walk_00.csv",
"/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_02/subject_02_walk_00.csv",
"/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_03/subject_03_walk_00.csv",
"/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_04/subject_04_walk_00.csv",
"/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_05/subject_05_walk_00.csv",
"/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_06/subject_06 walk_00.csv",
"/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_07/subject_07 walk_01.csv",
"/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_08/subject_08_walking_01.csv",
"/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_10/subject_10 walk_02.csv"],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 2],
["R", "R", "R", "R", "R", "R", "R", "R", "R", "R"])
return angles
#if __name__ == "__main__":
# # angles = plot_joint_angles(["/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_02/subject_02_walk_00.csv",
# # "/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_03/subject_03_walk_00.csv",
# # "/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_04/subject_04_walk_00.csv",
# # "/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_05/subject_05_walk_00.csv",
# # "/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_06/subject_06 walk_00.csv",
# # "/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_07/subject_07 walk_01.csv",
# # "/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_08/subject_08_walking_01.csv",
# # "/home/nathaniel/AIM_GaitData/Gaiting_stairs/subject_10/subject_10 walk_02.csv",
# # ],
# # [1, 0, 0, 0, 0, 0, 0, 2],
# # ["R", "R", "R", "R", "R", "R", "R", "R", "R", "R"],
# # ["Subject00", "Subject01", "Subject02", 'Subject03', "subject04", "Subject05",
# # "Subject06", "Subject07", "Subject08", "Subject10"])
#
# angles = get_joint_angles(["/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_00/subject_00 walk_00.csv",
# "/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_01/subject_01_walk_00.csv",
# "/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_02/subject_02_walk_00.csv",
# "/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_03/subject_03_walk_00.csv",
# "/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_04/subject_04_walk_00.csv",
# "/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_05/subject_05_walk_00.csv",
# "/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_06/subject_06 walk_00.csv",
# "/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_07/subject_07 walk_01.csv",
# "/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_08/subject_08_walking_01.csv",
# "/home/nathanielgoldfarb/AIM_GaitData/Gaiting_stairs/subject_10/subject_10 walk_02.csv"],
# [0, 0, 1, 0, 0, 0, 0, 0, 0, 2],
# ["R", "R", "R", "R", "R", "R", "R", "R", "R", "R"])
#
# traj = [angles["hip"], angles["knee"], angles["ankle"]]
#
#
# trainer = TPGMMTrainer.TPGMMTrainer(demo=traj, file_name="leg", n_rf=15, dt=0.01, reg=[1e-5, 1e-7, 1e-7], poly_degree=[20, 20, 20])
# trainer.train()
# runner = TPGMMRunner.TPGMMRunner("walk2.pickle")
# path = np.array(runner.run())
#
# fig, (ax1, ax2, ax3) = plt.subplots(3, 1)
#
# for p in angles["hip"]:
# ax1.plot(p)
# for p in angles["knee"]:
# ax2.plot(p)
# for p in angles["ankle"]:
# ax3.plot(p)
#
# ax1.plot(path[:, 0], linewidth=4)
# ax2.plot(path[:, 1], linewidth=4)
# ax3.plot(path[:, 2], linewidth=4)
# plt.show()