-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestbench.py
73 lines (56 loc) · 2.12 KB
/
testbench.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
# -*- coding: utf-8 -*-
"""
testbench for collect_gait
@author: Jussi ([email protected])
"""
# %% init
from collections import defaultdict
from collect_gait import utils
import datetime
import gaitutils
import itertools
import matplotlib.pyplot as plt
import numpy as np
# let's get all sessions under this dir...
rootdir = r"Z:\Userdata_Vicon_Server"
# ...newer than this date
date = datetime.datetime(2019, 3, 1)
# tags for dynamic trials
tags = ['E1', 'E2', 'E3', 'T1', 'T2', 'T3']
# strings that must be included in dir names
substrings = ['1_Diplegia', '1_Hemiplegia', '1_Eridiagnoosit', '1_Meningomyelecele']
dirs = utils.get_sessiondirs(rootdir, newer_than=date, substrings=substrings)
# %% scan the directory tree
alldirs = dict() # save dirs/files here
MAX_DIRS = 10 # XXX: let's limit the number of dirs for testing purposes
for i, d in enumerate(dirs):
print(f'reading from {d}')
c3ds = gaitutils.sessionutils.get_c3ds(d, tags=tags, trial_type='dynamic')
print(f'{len(c3ds)} tagged trials')
alldirs[d] = c3ds
if i == MAX_DIRS:
break
print('---')
print(f'{i} gait session dirs')
allfiles = list(itertools.chain.from_iterable(alldirs.values()))
print(f'{len(allfiles)} total c3d files')
# %% collect the data into numpy arrays
# model variables will be normalized into gait cycles (x axis 0..100%)
# and collected into data_all['model'];
# the corresponding gait cycles for each variable will be in cycles_all['model']
data_all, cycles_all = gaitutils.stats.collect_trial_data(
allfiles, collect_types=['model']
)
# %% plot some curves
knee_flex = data_all['model']['LKneeAnglesX'] # extract left sagittal knee angle
plt.figure()
plt.plot(knee_flex.T) # matplotlib plots columns by default, so transpose
# %% analyze curves
# we need to supply the toeoff frames for each curve, so that
# stance and swing phases can be separated
knee_toeoffs = [c.toeoffn for c in cycles_all['model']['LKneeAnglesX']]
res = gaitutils.stats.curve_extract_values(knee_flex, knee_toeoffs)
swing_peak_max = res['peaks']['swing']['max']
plt.figure()
plt.hist(swing_peak_max, bins=10)
plt.title('Peak knee flexion during swing phase')