Temporal Parameter Estimation#

This example illustrates how temporal gait parameters can be calculated using the EarGait. The gait event detection method DiaoAdaptedEventDetection is used for estimating gait events.

Getting some example data#

For this we take some example data that contains regular walking movements.

import pandas as pd

from eargait import EarGait
from eargait.event_detection import DiaoAdaptedEventDetection
from eargait.preprocessing import align_gravity_and_convert_ear_to_ebf, convert_ear_to_ebf, load
from eargait.utils.example_data import get_mat_example_data_path

# data directory
data_path = get_mat_example_data_path()

Loading the data#

A data session refers to a recording by signia hearing aids. A session can consist of a single *.mat file or two *.mat file, for left and right ear, respectively. The session is loaded using the local path data_path` of the directory, in which the matlab file(s) are stored. For more options regardind loading the data see Load Data by Signia Hearing Aids. example_gait_event_detection

target_sample_rate = 50
session = load(data_path, target_sample_rate_hz=target_sample_rate, skip_calibration=True)
session.info
/home/docs/checkouts/readthedocs.org/user_builds/eargait/checkouts/latest/eargait/preprocessing/load_data_helpers.py:54: UserWarning: Calibration was skipped. Calibration is strongly recommended.
  warnings.warn("Calibration was skipped. Calibration is strongly recommended.")

<signialib.header._ProxyHeader object at 0x7ff645d09100>

Gravity alignment and data transformation into body frame#

Align session to gravity and transform coordinate system into body frame

ear_data = align_gravity_and_convert_ear_to_ebf(session)

# Alternatively, you can skip the gravity alignment by using the following function:  convert_ear_to_ebf
# ear_data = convert_ear_to_ebf(session)
/home/docs/checkouts/readthedocs.org/user_builds/eargait/checkouts/latest/eargait/preprocessing/rotations.py:170: UserWarning: No gravity alignment method provided. Using MeanTrimGravityAlignment.
  warnings.warn("No gravity alignment method provided. Using MeanTrimGravityAlignment.")

Extract walking interval#

Note: Here prior knowledge about walking sequence within the given data session are applied. load csv file containing walking bouts

rescale_factor = 200 / target_sample_rate
walking_bout_list = pd.read_csv(data_path.parent.joinpath("walking_bout_indices.csv"))
interval = (int(walking_bout_list["start"][0] / rescale_factor), int(walking_bout_list["stop"][0] / rescale_factor))

# alternative if walking bout indices are already known, e.g.
# interval = (14317, 17637)    --> indices need to be replaced based on data

ear_data_short = {}
for side in ear_data.keys():
    ear_data_short[side] = ear_data[side][interval[0] : interval[1]]

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 Gait Analysis Pipeline#

Recommended parameters: sampling_rate_hz needs to correspond to target_sample_rate_hz <br />

ear_gait = EarGait(target_sample_rate, event_detection_algorithm, None, True)

Detect gait events of gait sequence#

Get temporal gait parameters of gait sequence#

{'right_sensor':       stride_time  stance_time  swing_time  step_time           side
s_id
0             NaN          NaN         NaN        NaN  contralateral
1             NaN          NaN         NaN       0.50    ipsilateral
2            1.00         0.60        0.40       0.50  contralateral
3            1.00         0.58        0.42       0.50    ipsilateral
4            0.98         0.58        0.40       0.48  contralateral
5            0.96         0.56        0.40       0.48    ipsilateral
6            0.98         0.56        0.42       0.50  contralateral
7            0.98         0.56        0.42       0.48    ipsilateral
8            0.96         0.56        0.40       0.48  contralateral
9            0.98         0.56        0.42       0.50    ipsilateral
10           1.00         0.58        0.42       0.50  contralateral
11           0.98         0.80        0.18       0.48    ipsilateral
12           0.88         0.60        0.28       0.40  contralateral
13           0.88         0.52        0.36       0.48    ipsilateral
14           0.98         0.54        0.44       0.50  contralateral
15           1.00         0.58        0.42       0.50    ipsilateral
16           0.98         0.58        0.40       0.48  contralateral
17           0.98         0.56        0.42       0.50    ipsilateral
18           0.98         0.56        0.42       0.48  contralateral
19           0.98         0.58        0.40       0.50    ipsilateral
20           1.00         0.58        0.42       0.50  contralateral
21           0.98         0.58        0.40       0.48    ipsilateral
22           0.98         0.56        0.42       0.50  contralateral, 'left_sensor':       stride_time  stance_time  swing_time  step_time           side
s_id
0             NaN          NaN         NaN        NaN    ipsilateral
1             NaN          NaN         NaN       0.50  contralateral
2            1.00         0.60        0.40       0.50    ipsilateral
3            1.00         0.58        0.42       0.50  contralateral
4            0.98         0.56        0.42       0.48    ipsilateral
5            0.96         0.56        0.40       0.48  contralateral
6            0.96         0.56        0.40       0.48    ipsilateral
7            0.98         0.56        0.42       0.50  contralateral
8            0.98         0.58        0.40       0.48    ipsilateral
9            0.96         0.56        0.40       0.48  contralateral
10            NaN          NaN         NaN        NaN    ipsilateral
11            NaN          NaN         NaN        NaN    ipsilateral
12           1.88          NaN         NaN        NaN  contralateral
13            NaN          NaN        0.44       0.50    ipsilateral
14           0.98         0.58        0.40       0.48  contralateral
15           0.98         0.56        0.42       0.50    ipsilateral
16           0.98         0.56        0.42       0.48  contralateral
17           0.98         0.56        0.42       0.50    ipsilateral
18           0.98         0.58        0.40       0.48  contralateral
19           0.98         0.56        0.42       0.50    ipsilateral
20           1.00         0.60        0.40       0.50  contralateral
21           1.00         0.56        0.44       0.50    ipsilateral}

Get average temporal gait parameters#

{'right_sensor':       stride_time  stance_time  swing_time  step_time
mean     0.973333     0.580000    0.393333   0.487273
std      0.033066     0.053666    0.058765   0.021861, 'left_sensor':       stride_time  stance_time  swing_time  step_time
mean     1.034118     0.570000    0.412941   0.491111
std      0.218376     0.014606    0.014038   0.010226}

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

Estimated memory usage: 12 MB

Gallery generated by Sphinx-Gallery