skdh.gait_old.Gait#

class skdh.gait_old.Gait(correct_accel_orient=True, use_cwt_scale_relation=True, wavelet_scale='default', min_bout_time=8.0, max_bout_separation_time=0.5, max_stride_time=2.25, loading_factor=0.2, height_factor=0.53, prov_leg_length=False, filter_order=4, filter_cutoff=20.0, downsample_aa_filter=True, day_window=(0, 24))#

Process IMU data to extract endpoints of gait. Detect gait, extract gait events (heel-strikes, toe-offs), and compute gait endpoints from inertial data collected from a lumbar mounted wearable inertial measurement unit. If angular velocity data is provided, turns are detected, and steps during turns are noted.

Deprecated since version 0.13.0: skdh.gait.Gait has been superseded by skdh.gaitv3.LumbarGait

Parameters:
correct_accel_orientbool, optional

Correct the acceleration orientation using the method from [7]. This should only be ‘ applied if the accelerometer axes are already approximately aligned with the anatomical axes. The correction is applied on a per-gait-bout basis. Default is True.

use_cwt_scale_relationbool, optional

Use the optimal scale/frequency relationship (see Notes). This changes which scale is used for the smoothing/differentiation operation performed with the continuous wavelet transform. Default is True. See Notes for a caveat of the relationship.

wavelet_scale{“default”, float, int}, optional

The wavelet scale to use. If use_cwt_scale_relation=True, then this is only used initially to determine the optimal scale. If False, then is used as the scale for the initial and final contact event detection. “default” corresponds to the default scale from [3], scaled for the sampling frequency. If a float, this is the value in Hz that the desired wavelet decomposition happens. For reference, [3] used a frequency of 1.25Hz. If an integer, uses that value as the scale.

min_bout_timefloat, optional

Minimum time in seconds for a gait bout. Default is 8s (making a minimum of 3 3-second windows)

max_bout_separation_timefloat, optional

Maximum time in seconds between two bouts of gait for them to be merged into 1 gait bout. Default is 0.5s

max_stride_timefloat, optional

The maximum time in seconds for a stride, for optimization of gait events detection. Default is 2.25s

loading_factorfloat, optional

The factor to determine maximum loading time (initial double support time), for optimization of gait events detection. Default is 0.2

height_factorfloat, optional

The factor multiplied by height to obtain an estimate of leg length. Default is 0.53 [4]. Ignored if leg_length is True

prov_leg_lengthbool, optional

If the actual leg length will be provided. Setting to true would have the same effect as setting height_factor to 1.0 while providing leg length. Default is False

filter_orderint, optional

Acceleration low-pass filter order. Default is 4

filter_cutofffloat, optional

Acceleration low-pass filter cutoff in Hz. Default is 20.0Hz

downsample_aa_filterbool, optional

Apply an anti-aliasing filter before downsampling. Default is True. Uses the same IIR filter as scipy.signal.decimate().

day_windowarray-like

Two (2) element array-like of the base and period of the window to use for determining days. Default is (0, 24), which will look for days starting at midnight and lasting 24 hours. None removes any day-based windowing.

Methods

add_endpoints(endpoints)

Add endpoints to be computed

convert_timestamps(t)

Convert a timestamp/array of timestamps to a datetime object

predict(*, time, accel[, gyro, fs, height, ...])

Get the gait events and endpoints from a time series signal

save_results(results, file_name)

Save the results of the processing pipeline to a csv file

Notes

The optimal scale/frequency relationship found in [5] was based on a cohort of only young women students. While it is recommended to use this relationship, the user should be aware of this shortfall in the generation of the relationship.

3 optimizations are performed on the detected events to minimize false positives.

1. Loading time (initial double support) must be less than \(loading\_factor * max\_stride\_time\)

2. Stance time must be less than \((max\_stride\_time/2) + loading\_factor * max\_stride\_time\)

  1. Stride time must be less than max_stride_time

If angular velocity data is provided, turns are detected [8], and steps during turns are noted in the results. Values are assigned as follows:

  • -1: Turns not detected (lacking angular velocity data)

  • 0: No turn found

  • 1: Turn overlaps with either Initial or Final contact

  • 2: Turn overlaps with both Initial and Final contact

References

[1]

B. Najafi, K. Aminian, A. Paraschiv-Ionescu, F. Loew, C. J. Bula, and P. Robert, “Ambulatory system for human motion analysis using a kinematic sensor: monitoring of daily physical activity in the elderly,” IEEE Transactions on Biomedical Engineering, vol. 50, no. 6, pp. 711–723, Jun. 2003, doi: 10.1109/TBME.2003.812189.

[2]

W. Zijlstra and A. L. Hof, “Assessment of spatio-temporal gait parameters from trunk accelerations during human walking,” Gait & Posture, vol. 18, no. 2, pp. 1–10, Oct. 2003, doi: 10.1016/S0966-6362(02)00190-X.

[3] (1,2)

J. McCamley, M. Donati, E. Grimpampi, and C. Mazzà, “An enhanced estimate of initial contact and final contact instants of time using lower trunk inertial sensor data,” Gait & Posture, vol. 36, no. 2, pp. 316–318, Jun. 2012, doi: 10.1016/j.gaitpost.2012.02.019.

[4]

S. Del Din, A. Godfrey, and L. Rochester, “Validation of an Accelerometer to Quantify a Comprehensive Battery of Gait Characteristics in Healthy Older Adults and Parkinson’s Disease: Toward Clinical and at Home Use,” IEEE J. Biomed. Health Inform., vol. 20, no. 3, pp. 838–847, May 2016, doi: 10.1109/JBHI.2015.2419317.

[5]

C. Caramia, C. De Marchis, and M. Schmid, “Optimizing the Scale of a Wavelet-Based Method for the Detection of Gait Events from a Waist-Mounted Accelerometer under Different Walking Speeds,” Sensors, vol. 19, no. 8, p. 1869, Jan. 2019, doi: 10.3390/s19081869.

[6]

C. Buckley et al., “Gait Asymmetry Post-Stroke: Determining Valid and Reliable Methods Using a Single Accelerometer Located on the Trunk,” Sensors, vol. 20, no. 1, Art. no. 1, Jan. 2020, doi: 10.3390/s20010037.

[7]

R. Moe-Nilssen, “A new method for evaluating motor control in gait under real-life environmental conditions. Part 1: The instrument,” Clinical Biomechanics, vol. 13, no. 4–5, pp. 320–327, Jun. 1998, doi: 10.1016/S0268-0033(98)00089-8.

[8]

M. H. Pham et al., “Algorithm for Turning Detection and Analysis Validated under Home-Like Conditions in Patients with Parkinson’s Disease and Older Adults using a 6 Degree-of-Freedom Inertial Measurement Unit at the Lower Back,” Front. Neurol., vol. 8, Apr. 2017, doi: 10.3389/fneur.2017.00135.

add_endpoints(endpoints)#

Add endpoints to be computed

Parameters:
endpoints{Iterable, callable}

Either an iterable of GaitEventEndpoint or GaitBoutEndpoint references or an individual GaitEventEndpoint/GaitBoutEndpoint reference to be added to the list of endpoints to be computed.

Examples

>>> class NewGaitEndpoint(gait_endpoints.GaitEventEndpoint):
>>>     pass
>>>
>>> gait = Gait()
>>> gait.add_endpoints(NewGaitEndpoint)
>>> class NewGaitEndpoint(gait_endpoints.GaitEventEndpoint):
>>>     pass
>>> class NewGaitEndpoint2(gait_endpoints.GaitEventEndpoint):
>>>     pass
>>>
>>> gait = Gait()
>>> gait.add_endpoints([NewGaitEndpoint, NewGaitEndpoint2])
predict(*, time, accel, gyro=None, fs=None, height=None, gait_pred=None, day_ends={})#

Get the gait events and endpoints from a time series signal

Parameters:
timenumpy.ndarray

(N, ) array of unix timestamps, in seconds

accelnumpy.ndarray

(N, 3) array of accelerations measured by a centrally mounted lumbar inertial measurement device, in units of ‘g’.

gyronumpy.ndarray

(N, 3) array of angular velocities measured by a centrally mounted lumbar inertial measurement device, in units of ‘rad/s’. If provided, will be used to indicate if steps occur during turns. Default is None.

fsfloat, optional

Sampling frequency in Hz of the accelerometer data. If not provided, will be computed form the timestamps.

heightfloat, optional

Either height (False) or leg length (True) of the subject who wore the inertial measurement device, in meters, depending on leg_length. If not provided, spatial endpoints will not be computed.

gait_pred{any, numpy.ndarray}, optional

(N, ) array of boolean predictions of gait, or any value that is not None. If not an ndarray but not None, the entire recording will be taken as gait. If not provided (or None), gait classification will be performed on the acceleration data.

day_endsdict, optional

Optional dictionary containing (N, 2) arrays of start and stop indices for invididual days. Dictionary keys are in the format ({base}, {period}). If not provided, or the key specified by day_window is not found, no day-based windowing will be done.

Returns:
gait_resultsdict

The computed gait endpoints. For a list of endpoints and their definitions, see Event Level Gait Metrics and Bout Level Gait Metrics.

Raises:
LowFrequencyError

If the sampling frequency is less than 20Hz