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 SpatialParamsExample

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 = SpatialParamsExample(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#

Get all gait parameters#

gait_params = ear_gait.get_gait_parameters()
gait_params
/home/docs/checkouts/readthedocs.org/user_builds/eargait/checkouts/stable/eargait/spatial_params/spatial_params_example_class.py:29: UserWarning: Example class for spatial parameter estimation is used. No spatial parameters are calculated, step length and stride length are set to NaN.
  warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/eargait/checkouts/stable/eargait/spatial_params/spatial_params_example_class.py:29: UserWarning: Example class for spatial parameter estimation is used. No spatial parameters are calculated, step length and stride length are set to NaN.
  warnings.warn(

{'left_sensor': stride_time                         1.176000
stance_time                         0.677895
swing_time                          0.429000
step_length                              NaN
stride_length                            NaN
stride_time_asymmetry               0.130101
stance_time_asymmetry               0.008667
swing_time_asymmetry                0.006000
step_length_asymmetry                    NaN
stride_length_asymmetry                  NaN
stride_time_asymmetry_percent       0.110630
stance_time_asymmetry_percent       0.012785
swing_time_asymmetry_percent        0.013986
step_length_asymmetry_percent            NaN
stride_length_asymmetry_percent          NaN
stride_time_si                     11.124547
stance_time_si                      1.278898
swing_time_si                       1.398601
step_length_si                           NaN
stride_length_si                         NaN
stride_time_std                     0.312450
stance_time_std                     0.024850
swing_time_std                      0.010208
step_length_std                          NaN
stride_length_std                        NaN
stride_time_cv                      0.265689
stance_time_cv                      0.036658
swing_time_cv                       0.023796
step_length_cv                           NaN
stride_length_cv                         NaN
number_of_steps                    25.000000
cadence                             1.765537
cadence_dom_freq                    1.851852
gait_velocity                            NaN
gait_velocity_dom_freq                   NaN
dtype: float64, 'right_sensor': stride_time                         1.175000
stance_time                         0.676842
swing_time                          0.429000
step_length                              NaN
stride_length                            NaN
stride_time_asymmetry               0.128283
stance_time_asymmetry               0.010889
swing_time_asymmetry                0.010000
step_length_asymmetry                    NaN
stride_length_asymmetry                  NaN
stride_time_asymmetry_percent       0.109177
stance_time_asymmetry_percent       0.016088
swing_time_asymmetry_percent        0.023310
step_length_asymmetry_percent            NaN
stride_length_asymmetry_percent          NaN
stride_time_si                     10.977613
stance_time_si                      1.609460
swing_time_si                       2.331002
step_length_si                           NaN
stride_length_si                         NaN
stride_time_std                     0.312873
stance_time_std                     0.026885
swing_time_std                      0.012096
step_length_std                          NaN
stride_length_std                        NaN
stride_time_cv                      0.266275
stance_time_cv                      0.039721
swing_time_cv                       0.028196
step_length_cv                           NaN
stride_length_cv                         NaN
number_of_steps                    25.000000
cadence                             1.768034
cadence_dom_freq                    1.851852
gait_velocity                            NaN
gait_velocity_dom_freq                   NaN
dtype: float64}

Get temporal gait parameters of gait sequence#

{'left_sensor':       stride_time  stance_time  swing_time           side
s_id
0            1.16         0.72        0.44    ipsilateral
1            1.14         0.72        0.42  contralateral
2            1.12         0.70        0.42    ipsilateral
3            1.12         0.70        0.42  contralateral
4            1.10         0.68        0.42    ipsilateral
5            1.10         0.66        0.44  contralateral
6            1.10         0.66        0.44    ipsilateral
7            1.08         0.66        0.42  contralateral
8            1.10         0.66        0.44    ipsilateral
9            1.12         0.70        0.42  contralateral
10            NaN          NaN         NaN    ipsilateral
11           2.50          NaN         NaN  contralateral
12            NaN          NaN         NaN    ipsilateral
13            NaN          NaN        0.44    ipsilateral
14           1.14         0.72        0.42  contralateral
15           1.10         0.68        0.42    ipsilateral
16           1.08         0.66        0.42  contralateral
17           1.08         0.66        0.42    ipsilateral
18           1.08         0.66        0.42  contralateral
19           1.08         0.64        0.44    ipsilateral
20           1.10         0.66        0.44  contralateral
21           1.10         0.66        0.44    ipsilateral
22           1.12         0.68        0.44  contralateral
23            NaN          NaN         NaN    ipsilateral
24            NaN          NaN         NaN  contralateral, 'right_sensor':       stride_time  stance_time  swing_time           side
s_id
0            1.16         0.74        0.42  contralateral
1            1.16         0.72        0.44    ipsilateral
2            1.14         0.70        0.44  contralateral
3            1.10         0.68        0.42    ipsilateral
4            1.10         0.66        0.44  contralateral
5            1.10         0.68        0.42    ipsilateral
6            1.08         0.66        0.42  contralateral
7            1.10         0.66        0.44    ipsilateral
8            1.10         0.66        0.44  contralateral
9            1.10         0.68        0.42    ipsilateral
10            NaN          NaN         NaN  contralateral
11           2.50          NaN         NaN    ipsilateral
12            NaN          NaN         NaN  contralateral
13            NaN          NaN        0.44  contralateral
14           1.14         0.72        0.42    ipsilateral
15           1.10         0.68        0.42  contralateral
16           1.08         0.66        0.42    ipsilateral
17           1.08         0.66        0.42  contralateral
18           1.10         0.68        0.42    ipsilateral
19           1.10         0.64        0.46  contralateral
20           1.08         0.66        0.42    ipsilateral
21           1.08         0.64        0.44  contralateral
22           1.10         0.68        0.42    ipsilateral
23            NaN          NaN         NaN  contralateral
24            NaN          NaN         NaN    ipsilateral}

Get average temporal gait parameters#

{'left_sensor':       stride_time  stance_time  swing_time
mean      1.17600     0.677895    0.429000
std       0.31245     0.024850    0.010208, 'right_sensor':       stride_time  stance_time  swing_time
mean     1.175000     0.676842    0.429000
std      0.312873     0.026885    0.012096}

Get spatial parameter for walking bout#

{'left_sensor':       step_length  stride_length           side
s_id
0             NaN            NaN    ipsilateral
1             NaN            NaN  contralateral
2             NaN            NaN    ipsilateral
3             NaN            NaN  contralateral
4             NaN            NaN    ipsilateral
5             NaN            NaN  contralateral
6             NaN            NaN    ipsilateral
7             NaN            NaN  contralateral
8             NaN            NaN    ipsilateral
9             NaN            NaN  contralateral
10            NaN            NaN    ipsilateral
11            NaN            NaN  contralateral
12            NaN            NaN    ipsilateral
13            NaN            NaN    ipsilateral
14            NaN            NaN  contralateral
15            NaN            NaN    ipsilateral
16            NaN            NaN  contralateral
17            NaN            NaN    ipsilateral
18            NaN            NaN  contralateral
19            NaN            NaN    ipsilateral
20            NaN            NaN  contralateral
21            NaN            NaN    ipsilateral
22            NaN            NaN  contralateral
23            NaN            NaN    ipsilateral
24            NaN            NaN  contralateral, 'right_sensor':       step_length  stride_length           side
s_id
0             NaN            NaN  contralateral
1             NaN            NaN    ipsilateral
2             NaN            NaN  contralateral
3             NaN            NaN    ipsilateral
4             NaN            NaN  contralateral
5             NaN            NaN    ipsilateral
6             NaN            NaN  contralateral
7             NaN            NaN    ipsilateral
8             NaN            NaN  contralateral
9             NaN            NaN    ipsilateral
10            NaN            NaN  contralateral
11            NaN            NaN    ipsilateral
12            NaN            NaN  contralateral
13            NaN            NaN  contralateral
14            NaN            NaN    ipsilateral
15            NaN            NaN  contralateral
16            NaN            NaN    ipsilateral
17            NaN            NaN  contralateral
18            NaN            NaN    ipsilateral
19            NaN            NaN  contralateral
20            NaN            NaN    ipsilateral
21            NaN            NaN  contralateral
22            NaN            NaN    ipsilateral
23            NaN            NaN  contralateral
24            NaN            NaN    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
mean          NaN            NaN
std           NaN            NaN, 'right_sensor':       step_length  stride_length
mean          NaN            NaN
std           NaN            NaN}

Get cadence (num steps/duration)#

cadence = ear_gait.cadence
cadence
{'left_sensor': 1.7655367231638417, 'right_sensor': 1.768033946251768}

Get cadence based on the dominant frequency#

{'left_sensor': 1.8518518518518516, 'right_sensor': 1.8518518518518516}

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_length_si            NaN
stride_length_si          NaN
dtype: float64, 'right_sensor': stride_time_si      10.977613
stance_time_si       1.609460
swing_time_si        2.331002
step_length_si            NaN
stride_length_si          NaN
dtype: float64}

Plotting gait events#

ear_gait.plot()
k = 1
  • left_sensor
  • right_sensor

Total running time of the script: ( 0 minutes 9.690 seconds)

Estimated memory usage: 59 MB

Gallery generated by Sphinx-Gallery