-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparam_spt.py
165 lines (150 loc) · 7.1 KB
/
param_spt.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
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 05 15:11:03 2018
@author: AdminXPS
"""
import btk
import numpy as np
def param_spt(filename, side):
reader = btk.btkAcquisitionFileReader()
reader.SetFilename(filename)
reader.Update()
acq = reader.GetOutput()
if side.lower() == "left":
foot_marker = acq.GetPoint('LHEE').GetValues()
foot_marker_ct = acq.GetPoint('RHEE').GetValues()
side_cl = "right"
side_letter = "L"
elif side.lower() == "right":
foot_marker = acq.GetPoint('RHEE').GetValues()
foot_marker_ct = acq.GetPoint('LHEE').GetValues()
side_cl = "left"
side_letter = "R"
# Initialisation des lists contenant les evenements
FO = []
FO_CL = []
FS = []
FS_CL = []
for it in btk.Iterate(acq.GetEvents()):
if it.GetContext().lower() == side:
if it.GetLabel() == 'Foot Strike':
FS.append(it.GetFrame())
elif it.GetLabel() == 'Foot Off':
FO.append(it.GetFrame())
elif it.GetContext().lower() == side_cl:
if it.GetLabel() == 'Foot Strike':
FS_CL.append(it.GetFrame())
elif it.GetLabel() == 'Foot Off':
FO_CL.append(it.GetFrame())
# Les evenements ne sont pas forcement organisé dans le bon ordre
FO.sort()
FO_CL.sort()
FS.sort()
FS_CL.sort()
frq_point = float(acq.GetPointFrequency())
# On enleve tout les evenements qui sont avant le premier foot strike du coté étudié
first_event = FS[0]
first_frame = acq.GetFirstFrame()
last_frame = acq.GetLastFrame()
FS = [x - first_frame for x in FS if x >= first_event]
FS_CL = [x - first_frame for x in FS_CL if x >= first_event]
FO = [x - first_frame for x in FO if x >= first_event]
FO_CL = [x - first_frame for x in FO_CL if x >= first_event]
# Extraction de la longueur de jambe
md = acq.GetMetaData()
leg_lenght = md.FindChild("PROCESSING").value().FindChild(
side_letter + 'LegLength').value().GetInfo().ToDouble()[0] / 1000.0
gravity = 9.81
# définition de la direction de marche
point = acq.GetPoint('LPSI').GetValues()
direction_walk = point[last_frame - first_frame, :] - point[0, :]
direction_walk = np.argmax(np.abs(direction_walk))
point = acq.GetPoint('LPSI').GetValues() - acq.GetPoint('RPSI').GetValues()
direction_width = np.argmax(np.abs(point[0, :]))
param_spt = {"cycle_time": [],
"cadence": [],
"cadence_adm": [],
"length_cycle": [],
"length_cycle_adm": [],
"walking_speed": [],
"walking_speed_adm": [],
"step_length": [],
"step_length_adm": [],
"step_sec": [],
"step_width": [],
"step_width_adm": [],
"stance_phase_sec": [],
"stance_phase_perc": [],
"swing_phase_sec": [],
"swing_phase_perc": [],
"double_stance_sec": [],
"double_stance_perc": [],
"simple_stance_sec": [],
"simple_stance_perc": [],
"percentage_CTFO": [],
"percentage_CTFS": []}
for ind_cycle in range(len(FS) - 1):
nb_frame_cycle = float(FS[ind_cycle + 1] - FS[ind_cycle])
# Temps du cycle (s)
cycle_time = (FS[ind_cycle + 1] - FS[ind_cycle]) / frq_point
param_spt["cycle_time"].append(cycle_time)
# Cadence (step/mn)
cadence = 120.0 / cycle_time
param_spt["cadence"].append(cadence)
param_spt["cadence_adm"].append(cadence / np.sqrt(gravity / leg_lenght))
# Longueur du cycle (m)
length_cycle = np.abs(foot_marker[FS[ind_cycle + 1], direction_walk] -
foot_marker[FS[ind_cycle], direction_walk]) / 1000.0
param_spt["length_cycle"].append(length_cycle)
param_spt["length_cycle_adm"].append(length_cycle / leg_lenght)
# Vitesse de marche (m/s)
walking_speed = cadence * length_cycle / 120.0
param_spt["walking_speed"].append(walking_speed)
param_spt["walking_speed_adm"].append(walking_speed / np.sqrt(leg_lenght * gravity))
# Longueur du pas (m)
step_length = np.abs(foot_marker_ct[FO[ind_cycle], direction_walk] -
foot_marker[FS[ind_cycle], direction_walk]) / 1000.0
param_spt["step_length"].append(step_length)
param_spt["step_length_adm"].append(step_length / leg_lenght)
# Temps Pas (frame, sec)
step_frame = FS_CL[ind_cycle] - FS[ind_cycle]
step_sec = step_frame / frq_point
param_spt["step_sec"].append(step_sec)
# Largeur pas (m)
step_width = np.abs(foot_marker_ct[FO[ind_cycle], direction_width] -
foot_marker[FS[ind_cycle], direction_width]) / 1000.0
param_spt["step_width"].append(step_width)
param_spt["step_width_adm"].append(step_width / leg_lenght)
# Phase d'appui (frame, sec, pourcentage)
stance_phase_frame = FO[ind_cycle] - FS[ind_cycle]
stance_phase_sec = stance_phase_frame / frq_point
stance_phase_perc = stance_phase_frame / nb_frame_cycle * 100
param_spt["stance_phase_sec"].append(stance_phase_sec)
param_spt["stance_phase_perc"].append(stance_phase_perc)
# Phase oscillante (frame, sec, pourcentage)
swing_phase_frame = FS[ind_cycle + 1] - FO[ind_cycle]
swing_phase_sec = swing_phase_frame / frq_point
swing_phase_perc = swing_phase_frame / nb_frame_cycle * 100
param_spt["swing_phase_sec"].append(swing_phase_sec)
param_spt["swing_phase_perc"].append(swing_phase_perc)
# Double appui (frame, sec, pourcentage)
double_stance_frame = (FO_CL[ind_cycle] - FS[ind_cycle] +
FO[ind_cycle] - FS_CL[ind_cycle])
double_stance_sec = double_stance_frame / frq_point
double_stance_perc = double_stance_frame / nb_frame_cycle * 100
param_spt["double_stance_sec"].append(double_stance_sec)
param_spt["double_stance_perc"].append(double_stance_perc)
# Simple appui (frame, sec, pourcentage)
simple_stance_frame = FS_CL[ind_cycle] - FO_CL[ind_cycle]
simple_stance_sec = simple_stance_frame / frq_point
simple_stance_perc = simple_stance_frame / nb_frame_cycle * 100
param_spt["simple_stance_sec"].append(simple_stance_sec)
param_spt["simple_stance_perc"].append(simple_stance_perc)
# Calcul des evenements controlateral pour affichage cinématique
CTFS_frame = FS_CL[ind_cycle] - FS[ind_cycle]
CTFO_frame = FO_CL[ind_cycle] - FS[ind_cycle]
CTFS_perc = CTFS_frame / nb_frame_cycle * 100
CTFO_perc = CTFO_frame / nb_frame_cycle * 100
param_spt["percentage_CTFS"].append(CTFS_perc)
param_spt["percentage_CTFO"].append(CTFO_perc)
return param_spt