gaitmap.preprocessing.align_dataset_to_gravity#
- gaitmap.preprocessing.align_dataset_to_gravity(dataset: DataFrame | dict[Union[collections.abc.Hashable, str], pandas.core.frame.DataFrame], sampling_rate_hz: float, window_length_s: float = 0.7, static_signal_th: float = 2.5, metric: typing_extensions.Literal[maximum, variance, mean, median, squared_mean] = 'median', gravity: ndarray = array([0., 0., 9.81])) DataFrame | dict[Union[collections.abc.Hashable, str], pandas.core.frame.DataFrame][source]#
Align dataset, so that each sensor z-axis (if multiple present in dataset) will be parallel to gravity.
Median accelerometer vector will be extracted form static windows which will be classified by a sliding window with (window_length -1) overlap and a thresholding of the gyro signal norm. This will be performed for each sensor in the dataset individually.
- Parameters:
- datasetsingle-sensor dataframe, or multi-sensor dataset
A single sensor dataset should be represented as a dataframe. Multi-sensor datasets should be represented as a dictionary of dataframes, where the keys are the sensor names or a pandas dataframe with a multi-index where the first level is the sensor name.
- sampling_rate_hz: float
Samplingrate of input signal in units of hertz.
- window_length_sfloat
Length of desired window in units of seconds.
- static_signal_thfloat
Threshold to decide whether a window should be considered as static or active. Window will be classified on <= threshold on gyro norm
- metric
Metric which will be calculated per window, one of the following strings
- ‘maximum’ (default)
Calculates maximum value per window
- ‘mean’
Calculates mean value per window
- ‘median’
Calculates median value per window
- ‘variance’
Calculates variance value per window
- gravityvector with shape (3,), axis ([x, y ,z]), optional
Expected direction of gravity during rest after the rotation. For example if this is
[0, 0, 1]the sensor will measure +g on the z-axis after rotation (z-axis pointing upwards)
- Returns:
- aligned dataset
This will always be a copy. The original dataframe will not be modified.
See also
gaitmap.utils.static_moment_detection.find_static_sequencesDetails on the used static moment detection function for this method.
Examples
>>> # pd.DataFrame containing one or multiple sensor data streams, each of containing all 6 IMU ... # axis (acc_x, ..., gyr_z) >>> dataset_df = ... >>> align_dataset_to_gravity(dataset_df, window_length_s = 0.7, static_signal_th = 2.0, metric = 'median', ... gravity = np.array([0.0, 0.0, 1.0]) <copy of dataset with all axis aligned to gravity>