Note
Click here to download the full example code
Gait Analysis Pipeline for Signia Hearing Aid Data#
This example illustrates how the gait analysis pipeline by the EarGait
can be applied to data recorded with Signia Hearing Aids.
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.
import pandas as pd
from eargait import EarGait
from eargait.event_detection import DiaoAdaptedEventDetection
from eargait.preprocessing import aling_gravity_and_convert_ear_to_ebf, load
from eargait.spatial_params import SpatialParamsExample
from eargait.utils.example_data import get_mat_example_data_path
# path to data file (.txt or .mat) or data directory (only for .mat)
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 ‘.txt’ or `.mat` file, or two *.mat files, for left and right ear, respectively.
The session is loaded using the local path data_path` of the directory, in which the matlab/txt file(s) are stored.
For more options regarding loading the data see Load Data by Signia Hearing Aids.
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/stable/eargait/preprocessing/load_data_helpers.py:47: UserWarning: Calibration was skipped. Calibration is strongly recommended.
warnings.warn("Calibration was skipped. Calibration is strongly recommended.")
<signialib.header._ProxyHeader object at 0x7f09a0594bb0>
Gravity alignment and data transformation into body frame#
Align session to gravity and transform coordinate system into body frame
ear_data = aling_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)
D11, default
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 spatial parameter estimation method#
Note: SpatialParamsExample is an 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#
ear_gait.detect(ear_data_short)
gait_events = ear_gait.event_list
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(
{'right_sensor': stride_time 1.173333
stance_time 0.677000
swing_time 0.430476
step_length NaN
stride_length NaN
stride_time_asymmetry 0.124727
stance_time_asymmetry 0.010000
swing_time_asymmetry 0.012364
step_length_asymmetry NaN
stride_length_asymmetry NaN
stride_time_asymmetry_percent 0.106302
stance_time_asymmetry_percent 0.014771
swing_time_asymmetry_percent 0.028721
step_length_asymmetry_percent NaN
stride_length_asymmetry_percent NaN
stride_time_si 10.657138
stance_time_si 1.477105
swing_time_si 2.874049
step_length_si NaN
stride_length_si NaN
stride_time_std 0.305046
stance_time_std 0.024516
swing_time_std 0.013593
step_length_std NaN
stride_length_std NaN
stride_time_cv 0.259983
stance_time_cv 0.036213
swing_time_cv 0.031576
step_length_cv NaN
stride_length_cv NaN
number_of_steps 26.000000
cadence 1.766304
cadence_dom_freq 1.851852
gait_velocity NaN
gait_velocity_dom_freq NaN
dtype: float64, 'left_sensor': stride_time 1.173333
stance_time 0.679000
swing_time 0.428571
step_length NaN
stride_length NaN
stride_time_asymmetry 0.124727
stance_time_asymmetry 0.006000
swing_time_asymmetry 0.008727
step_length_asymmetry NaN
stride_length_asymmetry NaN
stride_time_asymmetry_percent 0.106302
stance_time_asymmetry_percent 0.008837
swing_time_asymmetry_percent 0.020364
step_length_asymmetry_percent NaN
stride_length_asymmetry_percent NaN
stride_time_si 10.657138
stance_time_si 0.883652
swing_time_si 2.037351
step_length_si NaN
stride_length_si NaN
stride_time_std 0.304850
stance_time_std 0.024688
swing_time_std 0.010142
step_length_std NaN
stride_length_std NaN
stride_time_cv 0.259815
stance_time_cv 0.036359
swing_time_cv 0.023664
step_length_cv NaN
stride_length_cv NaN
number_of_steps 26.000000
cadence 1.766304
cadence_dom_freq 1.851852
gait_velocity NaN
gait_velocity_dom_freq NaN
dtype: float64}
Get temporal gait parameters of gait sequence#
temporal_params = ear_gait.temporal_params
temporal_params
{'right_sensor': stride_time stance_time swing_time side
s_id
0 1.14 0.72 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 1.16 0.70 0.46 contralateral
24 NaN NaN NaN ipsilateral
25 NaN NaN NaN contralateral, '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.10 0.68 0.42 contralateral
23 1.14 0.70 0.44 ipsilateral
24 NaN NaN NaN contralateral
25 NaN NaN NaN ipsilateral}
Get average temporal gait parameters#
{'right_sensor': stride_time stance_time swing_time
mean 1.173333 0.677000 0.430476
std 0.305046 0.024516 0.013593, 'left_sensor': stride_time stance_time swing_time
mean 1.173333 0.679000 0.428571
std 0.304850 0.024688 0.010142}
Get spatial parameter for walking bout#
spatial_params = ear_gait.spatial_params
spatial_params
{'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
25 NaN NaN contralateral, '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
25 NaN NaN ipsilateral}
Get average spatial parameter over walking bout#
spatial_params_average = ear_gait.average_spatial_params
spatial_params_average
{'right_sensor': step_length stride_length
mean NaN NaN
std NaN NaN, 'left_sensor': step_length stride_length
mean NaN NaN
std NaN NaN}
Get cadence (num steps/duration)#
{'right_sensor': 1.766304347826087, 'left_sensor': 1.766304347826087}
Get cadence based on the dominant frequency#
{'right_sensor': 1.8518518518518516, 'left_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()
{'right_sensor': stride_time_si 10.657138
stance_time_si 1.477105
swing_time_si 2.874049
step_length_si NaN
stride_length_si NaN
dtype: float64, 'left_sensor': stride_time_si 10.657138
stance_time_si 0.883652
swing_time_si 2.037351
step_length_si NaN
stride_length_si NaN
dtype: float64}
Plotting gait events#
ear_gait.plot()
k = 1
Total running time of the script: ( 0 minutes 13.202 seconds)
Estimated memory usage: 48 MB

