dispel.providers.generic.tasks.gait.core module#
All generic transformation steps related to the gait.
- class dispel.providers.generic.tasks.gait.core.AverageRollingVerticalAcceleration[source]#
Bases:
TransformStep
Extract and smooth vertical acceleration (in unit G).
The vertical acceleration is smoothed by using a centered moving average method.
- Parameters:
data_set_id – The id corresponding to the preprocessed accelerometer signal.
axis – The axis on which the centered moving average is computed.
rolling_window – The window size used in the centered moving average operation. Default value 5 has been determined empirically in order to provide the best results.
- class dispel.providers.generic.tasks.gait.core.DetectBouts[source]#
Bases:
TransformStep
Detect walking bouts.
- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: start_time (start time)>, <RawDataValueDefinition: end_time (end time)>, <RawDataValueDefinition: detected_walking (detected walking)>, <RawDataValueDefinition: duration (duration)>, <RawDataValueDefinition: bout_id (bout id)>]#
- class dispel.providers.generic.tasks.gait.core.DetectBoutsBeltPlacement[source]#
Bases:
DetectBouts
Detect walking bouts filtered for placement.
- data_set_ids: str | Iterable[str] = ['movement_bouts', 'placement_bouts']#
An iterable of data sets to be being processed
- thres_min_bout = <dispel.processing.core.Parameter object>#
- class dispel.providers.generic.tasks.gait.core.DetectBoutsBeltPlacementNoTurns[source]#
Bases:
DetectBouts
Detect walking bouts filtered for placement and no turns.
- data_set_ids: str | Iterable[str] = ['movement_bouts', 'placement_bouts', 'gyroscope_ts_rotated_resampled_butterworth_low_pass_filter_x_turns']#
An iterable of data sets to be being processed
- false_final_thres_min_bout = <dispel.processing.core.Parameter object>#
- skip_first_seconds = <dispel.processing.core.Parameter object>#
- true_final_thres_min_bout = <dispel.processing.core.Parameter object>#
- turn_max_angle = <dispel.processing.core.Parameter object>#
- class dispel.providers.generic.tasks.gait.core.DetectBoutsHarmonic[source]#
Bases:
DetectBouts
Detect walking bouts with CWT.
- class dispel.providers.generic.tasks.gait.core.DetectMovementBouts[source]#
Bases:
DetectBouts
Detect walking bouts based on dynamics algorithm.
- cutoff = <dispel.processing.core.Parameter object>#
- data_set_ids: str | Iterable[str] = 'acc_ts_rotated_resampled_detrend'#
An iterable of data sets to be being processed
- rolling_step_size = <dispel.processing.core.Parameter object>#
- rolling_window_size = <dispel.processing.core.Parameter object>#
- thres_min_bout = <dispel.processing.core.Parameter object>#
- thres_moving = <dispel.processing.core.Parameter object>#
- thres_upright = <dispel.processing.core.Parameter object>#
- class dispel.providers.generic.tasks.gait.core.DetectStepsProcessingBase[source]#
Bases:
TransformStep
An abstract base class for step detection.
Given the step detection algorithm specified through the method argument, e.g.:
dispel.providers.generic.tasks.gait.lee.detect_steps()
, the transform step run the step detection on each of the walking bouts and create a generic pandas.DataFrame with annotated events as in Bourke et. al.- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: foot (foot)>, <RawDataValueDefinition: event (event)>, <RawDataValueDefinition: bout_id (bout id)>]#
- class dispel.providers.generic.tasks.gait.core.DetectStepsWithoutBoutsBase[source]#
Bases:
TransformStep
Generic detect steps transform without walking bouts.
- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: foot (foot)>, <RawDataValueDefinition: event (event)>]#
- class dispel.providers.generic.tasks.gait.core.DetectWalking[source]#
Bases:
TransformStep
Identify walking in three seconds fixed temporal windows.
- class dispel.providers.generic.tasks.gait.core.ExtractPowerBoutDivSteps[source]#
Bases:
GaitBoutExtractStep
Extract step to compute the Step Power.
- Parameters:
data_set_ids – The data set ids corresponding to first the walking bouts then the signal to take as the magnitude of acceleration and the step dataset.
level_filter – An optional
LevelFilter
to determine the levels for extraction.
- class dispel.providers.generic.tasks.gait.core.ExtractStepCount[source]#
Bases:
GaitBoutExtractStep
Extract step count.
- Parameters:
data_set_ids – A list of two elements with the id of the walking bout data set and the id of the step_dataset containing the detected steps formatted as the output of TransformStepDetection.
level_filter – An optional
LevelFilter
to determine the levels for extraction.
- definition: ValueDefinition | ValueDefinitionPrototype | None = <dispel.data.measures.MeasureValueDefinitionPrototype object>#
The specification of the measure definition
- class dispel.providers.generic.tasks.gait.core.ExtractStepDurationAll[source]#
Bases:
GaitBoutAggregateStep
Extract step duration related measures.
- Parameters:
data_set_ids – The data set ids that will be considered to extract step duration measures.
- class dispel.providers.generic.tasks.gait.core.ExtractStepIntensityAll[source]#
Bases:
GaitBoutAggregateStep
Extract step intensity related measures.
- Parameters:
data_set_ids – The data set ids that will be considered to extract step intensity measures.
- class dispel.providers.generic.tasks.gait.core.ExtractStepPowerAll[source]#
Bases:
GaitBoutAggregateStep
Extract step power related measures.
- Parameters:
data_set_ids – The data set ids that will be considered to extract step power measures.
- class dispel.providers.generic.tasks.gait.core.ExtractStepRegularity[source]#
Bases:
GaitBoutAggregateStep
Extract step regularity aggregate measures.
- Parameters:
data_set_ids – The data set ids that will be considered to extract step regularity.
- class dispel.providers.generic.tasks.gait.core.ExtractStrideRegularity[source]#
Bases:
GaitBoutAggregateStep
Extract stride regularity aggregate measures.
- Parameters:
data_set_ids – The data set ids that will be considered to extract stride regularity.
- class dispel.providers.generic.tasks.gait.core.FootUsed[source]#
Bases:
IntEnum
Information on the foot being used for step annotation.
- LEFT = 1#
- RIGHT = 2#
- UNKNOWN = 0#
- class dispel.providers.generic.tasks.gait.core.FormatWalkingBouts[source]#
Bases:
TransformStep
Format fixed three seconds walking bouts into bouts of any size.
- class dispel.providers.generic.tasks.gait.core.GaitBoutAggregateStep[source]#
Bases:
AggregateRawDataSetColumn
Base class for gait bouts agg raw data set measure extraction.
- bout_strategy: BoutStrategy#
- process_level(level, reading, **kwargs)[source]#
Overwrite process_level.
- Parameters:
- Return type:
Generator[ProcessingResult | ProcessingControlResult, None, None]
- class dispel.providers.generic.tasks.gait.core.GaitBoutExtractStep[source]#
Bases:
ExtractStep
Base class for gait bouts measure extraction.
- bout_strategy: BoutStrategy#
- process_level(level, reading, **kwargs)[source]#
Overwrite process level.
- Parameters:
- Return type:
Generator[ProcessingResult | ProcessingControlResult, None, None]
- class dispel.providers.generic.tasks.gait.core.StepEvent[source]#
Bases:
IntEnum
Generic events for step annotation.
- FOOT_OFF = 3#
- INITIAL_CONTACT = 1#
- MID_SWING = 2#
- UNKNOWN = 0#
- class dispel.providers.generic.tasks.gait.core.TransformGaitRegularity[source]#
Bases:
_TransformGaitRegularityBase
Transform gait regularity.
Create a data set with columns
step_regularity
,stride_regularity
, andbout_id
indicating the step and stride regularity per step and corresponding bout identifier.- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: step_regularity (step regularity)>, <RawDataValueDefinition: stride_regularity (stride regularity)>, <RawDataValueDefinition: lag_step_regularity (lag step regularity)>, <RawDataValueDefinition: lag_stride_regularity (lag stride regularity)>, <RawDataValueDefinition: bout_id (bout id)>]#
- class dispel.providers.generic.tasks.gait.core.TransformGaitRegularityWithoutBout[source]#
Bases:
_TransformGaitRegularityBase
Transform gait regularity without bout.
Create a data set with two columns
step_regularity
andstride_regularity
per step.- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: step_regularity (step regularity)>, <RawDataValueDefinition: stride_regularity (stride regularity)>, <RawDataValueDefinition: lag_step_regularity (lag step regularity)>, <RawDataValueDefinition: lag_stride_regularity (lag stride regularity)>]#
- class dispel.providers.generic.tasks.gait.core.TransformStepDetection[source]#
Bases:
TransformStep
A transform step that creates a generic data set for step analysis.
Given the step detection algorithm specified through the method argument, e.g.:
dispel.providers.generic.tasks.gait.lee.detect_steps()
, the transform step create a generic data frame with annotated events as in Bourke et. al.- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: foot (foot)>, <RawDataValueDefinition: event (event)>]#
- class dispel.providers.generic.tasks.gait.core.TransformStepDuration[source]#
Bases:
TransformStep
Transform step duration.
Create a data set with one column
step_duration
indicating the amount of time to perform each steps.- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: step_duration (step duration, s)>, <RawDataValueDefinition: bout_id (bout id)>]#
- class dispel.providers.generic.tasks.gait.core.TransformStepDurationWithoutBout[source]#
Bases:
TransformStep
Transform step duration without using walking bout.
Create a data set with one column
step_duration
indicating the amount of time to perform each steps.- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: step_duration (step duration, s)>]#
- class dispel.providers.generic.tasks.gait.core.TransformStepVigor[source]#
Bases:
TransformStep
Transform step vigor.
Create a data set with columns
step_power
,step_intensity
, andbout_id
indicating the power, intensity and respective bout identifier of each step.- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: step_power (step power, m^2/s^3)>, <RawDataValueDefinition: step_intensity (step intensity, m/s^2)>, <RawDataValueDefinition: bout_id (bout id)>]#
- class dispel.providers.generic.tasks.gait.core.TransformStepVigorWithoutBout[source]#
Bases:
TransformStep
Transform step vigor without bout.
Create a data set with two columns
step_power
andstep_intensity
indicating the step power and intensity, respectively for each step.- definitions: List[RawDataValueDefinition] = [<RawDataValueDefinition: step_power (step power, m^2/s^3)>, <RawDataValueDefinition: step_intensity (step intensity, m/s^2)>]#
- dispel.providers.generic.tasks.gait.core.compute_gait_regularity_multiple(acc, step_dataset, window_size_in_steps=14, window_step_in_steps=7, component='norm', bout_filter=False)[source]#
Compute the step and stride regularity.
The step and stride regularity is defined as the first and second peak of the unbiased normalized autocorrelation.
- Parameters:
acc (DataFrame) –
- A pandas DataFrame containing the at least one column with the intended
acceleration signal component to be used for step & stride regularity.
step_dataset (DataFrame) – A pandas series containing at the minimum the the times of the initial contacts (‘IC’ column).
window_size_in_steps (int) – The interval expressed in number of succeeding steps to be used to trim the signal to compute the regularity.
window_step_in_steps (int) – The step of the sliding window expressed in number of steps.
component (str) – A str indicating the column name of acc to be used.
bout_filter (bool) – A boolean indicating whether to take into account bouts in the transformation of the dataset.
- Returns:
The step and stride regularity values.
- Return type:
- dispel.providers.generic.tasks.gait.core.compute_gait_regularity_single(data, find_peak_height_centile=80, find_peak_distance=0.3)[source]#
Compute gait regularity based on filtered signal.
The step and stride regularity is defined as the first and second peak of the unbiased normalized autocorrelation. In order to minimize the negative effect of local maxima we filter the accelerometer signal and detect the lags based on that, which we then apply in the autocorrelation of the non-filtered signal.
- Parameters:
- Returns:
A Tuple containing the step and stride regularity and respective lags.
- Return type:
References
- dispel.providers.generic.tasks.gait.core.compute_step_intensity_single(acc_norm)[source]#
Compute the Step Intensity for a single step.
The step intensity is defined as the RMS of the magnitude of acceleration for the period of a single step.
- Parameters:
acc_norm (Series) – A pandas series containing the magnitude of the acceleration.
- Returns:
The step intensity.
- Return type:
References
[1] Angelini L et al. (2020) Is a Wearable Sensor-Based Characterisation of Gait Robust Enough to Overcome Differences Between Measurement Protocols? A Multi-Centric Pragmatic Study in Patients with MS. https://doi.org/10.3390/s20010079
- dispel.providers.generic.tasks.gait.core.compute_step_power_single(acc_norm)[source]#
Compute the Step Power for a single step.
The step power is defined as the integral of centered magnitude acceleration for the period of a single step.
- Parameters:
acc_norm (Series) – A pandas series containing the magnitude of the acceleration.
- Returns:
The step power.
- Return type:
References
[1] Cheng WY. et al. (2018) Large-Scale Continuous Mobility Monitoring of Parkinson’s Disease Patients Using Smartphones.
- dispel.providers.generic.tasks.gait.core.compute_step_vigor_multiple(acc, step_dataset, component, bout_filter)[source]#
Compute the step vigor for multiple steps.
The step vigor is defined as the step power and step intensity properties.
- Parameters:
acc (DataFrame) –
- A pandas DataFrame containing the at least one column with the intended
acceleration signal component to be used for step power.
step_dataset (DataFrame) – A pandas series containing at the minimum the the times of the initial contacts.
component (str) – A str indicating the column name of acc to be used.
bout_filter (bool) – A boolean indicating whether to take into account bouts in the transformation of the dataset.
- Returns:
The step power and intensity values.
- Return type:
- dispel.providers.generic.tasks.gait.core.find_peaks_in_local_slice(initial_peak_idx, autocorr_values, lag_values, slice_size=5)[source]#
Find peaks in local slice.
- Parameters:
initial_peak_idx (ndarray) – A numpy.ndarray containing the initial guesses for the peak indices.
autocorr_values (ndarray) – The autocorrelation values.
lag_values (ndarray) – The value of the lags.
slice_size (int) – The size of the slice to look for peaks forward and backward in number of samples.
- Returns:
Tuple[np.ndarray, np.ndarray]
A Tuple containing the refined peaks and lags.
- Return type:
- dispel.providers.generic.tasks.gait.core.format_walking_bouts(walking_segments, start_time_col='ts', end_time_col='ts', bool_col='detected_walking')[source]#
Group consecutive flags of same type in a single bin.
- Parameters:
- Returns:
The dataframe with grouped consecutive flags of same type
- Return type:
- dispel.providers.generic.tasks.gait.core.get_mask_from_intervals(intervals, ts_index, bool_column='detected_walking', start_column='start_time', end_column='end_time')[source]#
Get a boolean mask indicating walking or not walking in a signal.
- Parameters:
intervals (DataFrame) – pd.DataFrame: contains start_time and end_time for each interval/bout
ts_index (DatetimeIndex) – pd.DatetimeIndex: a datetime index of the signal to be masked
bool_column (str) – str indicating the column of boolean type to be used for the mask
start_column (str) – str indicating the column of the start time of the interval
end_column (str) – str indicating the column of the end time of the interval
- Returns:
contains the boolean mask of len(timestamp_index)
- Return type:
- dispel.providers.generic.tasks.gait.core.get_step_detector_from_data_set_ids(data_set_ids, position)[source]#
Get step detector from data_set_ids.
- dispel.providers.generic.tasks.gait.core.movement_detection(acc_ts_rotated_resampled_detrend)[source]#
Detect movement bouts.
- Parameters:
acc_ts_rotated_resampled_detrend (DataFrame) – A pd.DataFrame containing the accelerometer signal rotated in a gravity based coordinate frame with x pointing towards gravity
- Returns:
A pd.DataFrame containing the start/end timestamp, duration of each detected movement or non-movement bout
- Return type:
- dispel.providers.generic.tasks.gait.core.power_bout_div_steps(acc_magnitude, step_dataset, walking_bouts=None)[source]#
Compute the Step Power based on bout power divided by number of steps.
The step power is defined as the integral of centered magnitude acceleration divided by the number of steps. For more information please see the section 2.3 of [1]_.
- Parameters:
- Returns:
The step power.
- Return type:
References
[1] Cheng WY. et al. (2018) Large-Scale Continuous Mobility Monitoring of Parkinson’s Disease Patients Using Smartphones.
- dispel.providers.generic.tasks.gait.core.remove_short_bouts(data, true_thres=3, false_thres=0.3, bool_col='detected_walking')[source]#
Remove short walking and non-walking bouts.
- Parameters:
data (DataFrame) – A pd.DataFrame containing the intervals of the bouts with including at least bool_col and duration as columns
true_thres (float) – A float indicating the minimum duration of a true bout
false_thres (float) – A float indicating the minimum duration of a false bout
bool_col (str) – A ‘str’ containing the column name of the boolean
- Returns:
A pd.DataFrame containing the filtered bout data satisfying the bout type and duration criteria.
- Return type:
- dispel.providers.generic.tasks.gait.core.walking_detection_harmonic(vertical_acc, abs_thresh=0.01)[source]#
Detect walking bouts.
A sliding window of three seconds is moved through the time series of vertical acceleration to detect walking bouts. Walking is identified based on spectral measures computed on the temporal window. More specifically, walking is seen if the maximum amplitude of the power spectral density in the walking frequency band [0.6 Hz - 2.0 Hz] is more significant (and more distant than a given threshold) than the maximum amplitude of the power spectral density of the non-walking frequency band [0 - 0.6 Hz].
- Parameters:
vertical_acc (DataFrame) – A smoothed version of the vertical acceleration typically obtained using the transform step ~AverageRollingVerticalAcceleration.
abs_thresh (float) – A threshold defining the minimum distance that should separate the amplitude of the walking harmonic from the amplitude of the non-walking harmonic.
- Returns:
A data frame with the maximum walking and non-walking harmonic as well as the detected walking.
- Return type:
- Raises:
ValueError – Raises a value error if vertical_acc is not sampled at a constant sampling rate.
- dispel.providers.generic.tasks.gait.core.walking_placement_detection(movement_bouts, placement_bouts, placement='belt')[source]#
Detect intersection of walking and intended placement.
- Parameters:
- Returns:
A pd.DataFrame containing the start/end timestamp, duration of each detected walking or no walking bout considering intended placement
- Return type:
- dispel.providers.generic.tasks.gait.core.walking_placement_no_turn_detection(movement_bouts, placement_bouts, turn_bouts, placement_label='belt')[source]#
Intersect walking bouts, placement and no turn constraints.
This function finds all the walking bout and apply a logical and with the mask of the walking bout, the placement detection that respects the label e.g.: ‘belt’ and the non-turn detection mask. A postprocessing step to remove short bouts and fill in gaps at the beginning and end of the signal is applied.
- Parameters:
movement_bouts (DataFrame) – A pd.DataFrame containing the intervals of the walking bouts
placement_bouts (DataFrame) – A pd.DataFrame containing the intervals of the placement bouts
turn_bouts (DataFrame) – A pd.DataFrame containing the intervals of the turns
placement_label (str) – A ‘str’ containing the label of the intended placement
- Returns:
A pd.DataFrame containing the start/end timestamp, duration of each detected walking or no walking bout considering intended placement
- Return type: