Note
Click here to download the full example code
Gait Analysis Pipeline#
This example illustrates how the gait analysis pipeline by the EarGait
can be applied to ear-worn accerlation data.
The used gait event detection method is based on the work of Diao et al. [1] with a few adaptations as described in DiaoAdaptedEventDetection
Getting some example data#
For this we take some example data that contains regular walking movements.
from eargait import EarGait
from eargait.event_detection import DiaoAdaptedEventDetection
from eargait.spatial_params import SpatialParamsRandomForest
Loading the data#
Calibrated + aligned to gravity + body frame
from eargait.utils.example_data import get_example_data
data, target_sample_rate = get_example_data()
data
{'left_sensor': acc_pa acc_ml acc_si gyr_pa gyr_ml gyr_si
n_samples
3588 0.062110 -0.560160 -9.902774 -0.524762 0.910834 -0.250719
3589 0.054049 -0.541775 -9.891725 -1.643633 0.590841 -0.469453
3590 0.020290 -0.521113 -9.830480 -1.772921 -0.687454 -0.555743
3591 0.035146 -0.504830 -9.696257 -0.863035 -1.820974 -1.032123
3592 0.094157 -0.485468 -9.934264 -0.118817 -1.412612 -0.554654
... ... ... ... ... ... ...
4385 -1.291555 0.638652 -10.180196 1.278888 3.291048 -50.932310
4386 -1.141385 0.851419 -9.837720 0.324699 4.242024 -45.653053
4387 -1.084186 1.003016 -9.705787 -0.146751 6.534404 -39.831984
4388 -1.244444 1.031254 -9.520316 -1.176098 7.666734 -34.136159
4389 -1.320403 1.099410 -9.590169 -0.213508 7.253635 -30.441111
[802 rows x 6 columns], 'right_sensor': acc_pa acc_ml acc_si gyr_pa gyr_ml gyr_si
n_samples
3588 0.109796 0.514149 -9.853317 1.460804 0.476808 0.056860
3589 0.057601 0.472815 -9.724967 0.686210 -1.145863 0.370734
3590 0.108112 0.461451 -9.820133 0.446589 -1.240347 0.582822
3591 -0.008284 0.455469 -9.790361 0.057984 -0.906538 0.635999
3592 0.117946 0.414403 -9.746449 0.069601 -0.950669 0.239099
... ... ... ... ... ... ...
4385 -1.979446 -0.776602 -9.482163 1.124168 5.551943 39.798419
4386 -2.016508 -0.807854 -9.386433 2.282151 7.007394 34.884770
4387 -1.928316 -0.828154 -9.623480 2.228703 7.231336 31.170216
4388 -2.001359 -0.935844 -9.428640 1.708899 6.963127 27.820772
4389 -2.093137 -0.987707 -9.495858 2.090396 7.229204 24.002879
[802 rows x 6 columns]}
50
Initializing event detection algorithm#
Recommended parameters: apply filter = True <br /> sampling_rate_hz needs to correspond to target_sample_rate_hz <br /> window_length should be equal to sampling_rate_hz
event_detection_algorithm = DiaoAdaptedEventDetection(
sample_rate_hz=target_sample_rate, window_length=target_sample_rate
)
Initializing spatial parameter estimation method#
Note: SpatialParamsExample is a placeholder class. Needs to be implemented by user if spatial parameters want to be estimated.
spatial_method = SpatialParamsRandomForest(target_sample_rate)
Initializing Gait Analysis Pipeline#
Recommended parameters: sampling_rate_hz needs to correspond to target_sample_rate_hz
ear_gait = EarGait(
sample_rate_hz=target_sample_rate,
event_detection_method=event_detection_algorithm,
spatial_params_method=spatial_method,
bool_use_event_list_consistent=True,
)
Detect gait events of gait sequence#
ear_gait.detect(data)
gait_events = ear_gait.event_list
Get all gait parameters#
gait_params = ear_gait.get_gait_parameters()
gait_params
{'left_sensor': stride_time 1.176000
stance_time 0.677895
swing_time 0.429000
step_time 0.555238
step_length 0.726159
stride_length 1.459110
gait_velocity 1.309616
number_of_steps 25.000000
cadence 101.694915
cadence_dom_freq 111.111111
stride_time_asymmetry 0.130101
stance_time_asymmetry 0.008667
swing_time_asymmetry 0.006000
step_time_asymmetry 0.006182
step_length_asymmetry 0.002211
stride_length_asymmetry 0.018216
gait_velocity_asymmetry 0.010244
stride_time_asymmetry_percent 0.110630
stance_time_asymmetry_percent 0.012785
swing_time_asymmetry_percent 0.013986
step_time_asymmetry_percent 0.011134
step_length_asymmetry_percent 0.003044
stride_length_asymmetry_percent 0.012485
gait_velocity_asymmetry_percent 0.007822
stride_time_si 11.124547
stance_time_si 1.278898
swing_time_si 1.398601
step_time_si 1.113659
step_length_si 0.304452
stride_length_si 1.248461
gait_velocity_si 0.782104
stride_time_std 0.312450
stance_time_std 0.024850
swing_time_std 0.010208
step_time_std 0.015368
step_length_std 0.030452
stride_length_std 0.053709
gait_velocity_std 0.080155
stride_time_cv 0.265689
stance_time_cv 0.036658
swing_time_cv 0.023796
step_time_cv 0.027679
step_length_cv 0.041936
stride_length_cv 0.036810
gait_velocity_cv 0.061205
dtype: float64, 'right_sensor': stride_time 1.175000
stance_time 0.676842
swing_time 0.429000
step_time 0.554286
step_length 0.718458
stride_length 1.442249
gait_velocity 1.297989
number_of_steps 25.000000
cadence 101.838755
cadence_dom_freq 111.111111
stride_time_asymmetry 0.128283
stance_time_asymmetry 0.010889
swing_time_asymmetry 0.010000
step_time_asymmetry 0.004364
step_length_asymmetry 0.001946
stride_length_asymmetry 0.014742
gait_velocity_asymmetry 0.006589
stride_time_asymmetry_percent 0.109177
stance_time_asymmetry_percent 0.016088
swing_time_asymmetry_percent 0.023310
step_time_asymmetry_percent 0.007873
step_length_asymmetry_percent 0.002708
stride_length_asymmetry_percent 0.010221
gait_velocity_asymmetry_percent 0.005076
stride_time_si 10.977613
stance_time_si 1.609460
swing_time_si 2.331002
step_time_si 0.787402
step_length_si 0.270835
stride_length_si 1.022125
gait_velocity_si 0.507555
stride_time_std 0.312873
stance_time_std 0.026885
swing_time_std 0.012096
step_time_std 0.015675
step_length_std 0.030918
stride_length_std 0.058279
gait_velocity_std 0.080912
stride_time_cv 0.266275
stance_time_cv 0.039721
swing_time_cv 0.028196
step_time_cv 0.028280
step_length_cv 0.043034
stride_length_cv 0.040408
gait_velocity_cv 0.062337
dtype: float64}
Get temporal gait parameters of gait sequence#
temporal_params = ear_gait.temporal_params
temporal_params
{'left_sensor': stride_time stance_time swing_time step_time side
s_id
0 NaN NaN NaN NaN ipsilateral
1 NaN NaN NaN 0.58 contralateral
2 1.16 0.72 0.44 0.58 ipsilateral
3 1.14 0.72 0.42 0.56 contralateral
4 1.12 0.70 0.42 0.56 ipsilateral
5 1.12 0.70 0.42 0.56 contralateral
6 1.10 0.68 0.42 0.54 ipsilateral
7 1.10 0.66 0.44 0.56 contralateral
8 1.10 0.66 0.44 0.54 ipsilateral
9 1.08 0.66 0.42 0.54 contralateral
10 1.10 0.66 0.44 0.56 ipsilateral
11 1.12 0.70 0.42 0.56 contralateral
12 NaN NaN NaN NaN ipsilateral
13 NaN NaN NaN NaN ipsilateral
14 2.50 NaN NaN NaN contralateral
15 NaN NaN 0.44 0.58 ipsilateral
16 1.14 0.72 0.42 0.56 contralateral
17 1.10 0.68 0.42 0.54 ipsilateral
18 1.08 0.66 0.42 0.54 contralateral
19 1.08 0.66 0.42 0.54 ipsilateral
20 1.08 0.66 0.42 0.54 contralateral
21 1.08 0.64 0.44 0.54 ipsilateral
22 1.10 0.66 0.44 0.56 contralateral
23 1.10 0.66 0.44 0.54 ipsilateral
24 1.12 0.68 0.44 0.58 contralateral, 'right_sensor': stride_time stance_time swing_time step_time side
s_id
0 NaN NaN NaN NaN contralateral
1 NaN NaN NaN 0.58 ipsilateral
2 1.16 0.74 0.42 0.58 contralateral
3 1.16 0.72 0.44 0.58 ipsilateral
4 1.14 0.70 0.44 0.56 contralateral
5 1.10 0.68 0.42 0.54 ipsilateral
6 1.10 0.66 0.44 0.56 contralateral
7 1.10 0.68 0.42 0.54 ipsilateral
8 1.08 0.66 0.42 0.54 contralateral
9 1.10 0.66 0.44 0.56 ipsilateral
10 1.10 0.66 0.44 0.54 contralateral
11 1.10 0.68 0.42 0.56 ipsilateral
12 NaN NaN NaN NaN contralateral
13 NaN NaN NaN NaN contralateral
14 2.50 NaN NaN NaN ipsilateral
15 NaN NaN 0.44 0.58 contralateral
16 1.14 0.72 0.42 0.56 ipsilateral
17 1.10 0.68 0.42 0.54 contralateral
18 1.08 0.66 0.42 0.54 ipsilateral
19 1.08 0.66 0.42 0.54 contralateral
20 1.10 0.68 0.42 0.56 ipsilateral
21 1.10 0.64 0.46 0.54 contralateral
22 1.08 0.66 0.42 0.54 ipsilateral
23 1.08 0.64 0.44 0.54 contralateral
24 1.10 0.68 0.42 0.56 ipsilateral}
Get average temporal gait parameters#
{'left_sensor': stride_time stance_time swing_time step_time
mean 1.17600 0.677895 0.429000 0.555238
std 0.31245 0.024850 0.010208 0.015368, 'right_sensor': stride_time stance_time swing_time step_time
mean 1.175000 0.676842 0.429000 0.554286
std 0.312873 0.026885 0.012096 0.015675}
Get spatial parameter for walking bout#
spatial_params = ear_gait.spatial_params
spatial_params
{'left_sensor': step_length stride_length gait_velocity side
s_id
0 NaN NaN NaN ipsilateral
1 0.660593 1.321186 1.138954 contralateral
2 0.702032 1.404064 1.210400 ipsilateral
3 0.711441 1.422881 1.270430 contralateral
4 0.728346 1.456692 1.300618 ipsilateral
5 0.766897 1.533795 1.369460 contralateral
6 0.739818 1.479636 1.370033 ipsilateral
7 0.752164 1.504329 1.343151 contralateral
8 0.729987 1.459973 1.351827 ipsilateral
9 0.728532 1.457063 1.349133 contralateral
10 0.725189 1.450378 1.294980 ipsilateral
11 0.695652 1.391303 1.242235 contralateral
12 NaN NaN NaN ipsilateral
13 NaN NaN NaN ipsilateral
14 NaN NaN NaN contralateral
15 0.707291 1.414581 1.219466 ipsilateral
16 0.754621 1.509243 1.347538 contralateral
17 0.750161 1.500322 1.389187 ipsilateral
18 0.755835 1.511670 1.399694 contralateral
19 0.737516 1.475032 1.365770 ipsilateral
20 0.765614 1.531228 1.417804 contralateral
21 0.725673 1.451347 1.343840 ipsilateral
22 0.749742 1.499484 1.338825 contralateral
23 0.703997 1.407994 1.303698 ipsilateral
24 0.658236 NaN 1.134890 contralateral, 'right_sensor': step_length stride_length gait_velocity side
s_id
0 NaN NaN NaN contralateral
1 0.651899 1.303799 1.123964 ipsilateral
2 0.668604 1.337208 1.152766 contralateral
3 0.709593 1.419186 1.223436 ipsilateral
4 0.715345 1.430690 1.277402 contralateral
5 0.743997 1.487995 1.377773 ipsilateral
6 0.734369 1.468738 1.311373 contralateral
7 0.735627 1.471254 1.362272 ipsilateral
8 0.725854 1.451709 1.344175 contralateral
9 0.722053 1.444106 1.289381 ipsilateral
10 0.706252 1.412503 1.307873 contralateral
11 0.683116 1.366232 1.219850 ipsilateral
12 NaN NaN NaN contralateral
13 NaN NaN NaN contralateral
14 NaN NaN NaN ipsilateral
15 0.706513 1.413027 1.218127 contralateral
16 0.749497 1.498993 1.338387 ipsilateral
17 0.753428 1.506856 1.395237 contralateral
18 0.756663 1.513325 1.401227 ipsilateral
19 0.740812 1.481623 1.371873 contralateral
20 0.761865 1.523729 1.360472 ipsilateral
21 0.718833 1.437665 1.331171 contralateral
22 0.733789 1.467578 1.358868 ipsilateral
23 0.704380 1.408761 1.304408 contralateral
24 0.665134 NaN 1.187739 ipsilateral}
Get average spatial parameter over walking bout#
spatial_params_average = ear_gait.average_spatial_params
spatial_params_average
{'left_sensor': step_length stride_length gait_velocity
mean 0.726159 1.459110 1.309616
std 0.030452 0.053709 0.080155, 'right_sensor': step_length stride_length gait_velocity
mean 0.718458 1.442249 1.297989
std 0.030918 0.058279 0.080912}
Get cadence (num steps/duration)#
{'left_sensor': 101.69491525423729, 'right_sensor': 101.83875530410184}
Get cadence based on the dominant frequency#
{'left_sensor': 111.1111111111111, 'right_sensor': 111.1111111111111}
Get asymmetry, symetry index or variability#
symmetry_index = ear_gait.get_symmetry_index()
symmetry_index
# same for ear_gait.get_variability(), ear_gait.get_asymmetry()
{'left_sensor': stride_time_si 11.124547
stance_time_si 1.278898
swing_time_si 1.398601
step_time_si 1.113659
step_length_si 0.304452
stride_length_si 1.248461
gait_velocity_si 0.782104
dtype: float64, 'right_sensor': stride_time_si 10.977613
stance_time_si 1.609460
swing_time_si 2.331002
step_time_si 0.787402
step_length_si 0.270835
stride_length_si 1.022125
gait_velocity_si 0.507555
dtype: float64}
Plotting gait events#
ear_gait.plot()
k = 1
Total running time of the script: ( 0 minutes 12.261 seconds)
Estimated memory usage: 87 MB

