gaitmap.trajectory_reconstruction.StrideLevelTrajectory#

class gaitmap.trajectory_reconstruction.StrideLevelTrajectory(*, ori_method: BaseOrientationMethod | None = cf(SimpleGyroIntegration(initial_orientation=array([0., 0., 0., 1.]), memory=None)), pos_method: BasePositionMethod | None = cf(ForwardBackwardIntegration(gravity=array([0., 0., 9.81]), level_assumption=True, steepness=0.08, turning_point=0.5)), trajectory_method: BaseTrajectoryMethod | None = None, align_window_width: int = 8)[source]#

Estimate the trajectory over the duration of a stride by considering each stride individually.

You can select a method for the orientation estimation and a method for the position estimation (or a combined method). These methods will then be applied to each stride. This class will calculate the initial orientation of each stride assuming that it starts at a region of minimal movement (min_vel). Some methods to dedrift the orientation or position will additionally assume that the stride also ends in a static period. Check the documentation of the individual ori and pos methods for details.

Parameters:
ori_method

An instance of any available orientation method with the desired parameters set. This method is called with the data of each stride to actually calculate the orientation. Note, the the initial_orientation parameter of this method will be overwritten, as this class estimates new per-stride initial orientations based on the mid-stance assumption.

pos_method

An instance of any available position method with the desired parameters set. This method is called with the data of each stride to actually calculate the position. The provided data is already transformed into the global frame using the orientations calculated by the ori_method on the same stride.

trajectory_method

Instead of providind a separate ori_method and pos_method, a single trajectory_method can be provided that calculated the orientation and the position in one go. This method is called with the data of each stride. If a trajectory_method is provided the values for ori_method and pos_method are ignored. Note, the the initial_orientation parameter of this method will be overwritten, as this class estimates new per-stride initial orientations based on the mid-stance assumption.

align_window_width

This is the width of the window that will be used to align the beginning of the signal of each stride with gravity. To do so, half the window size before and half the window size after the start of the stride will be used to obtain the median value of acceleration data in this phase. Note, that +-np.floor(align_window_size/2) around the start sample will be used for this. For the first stride, start of the stride might coincide with the start of the signal. In that case the start of the window would result in a negative index, thus the window to get the initial orientation will be reduced (from 0 to start+np.floor(align_window_size/2))

Other Parameters:
data

The data passed to the estimate method.

stride_event_list

The event list passed to the estimate method.

sampling_rate_hz

The sampling rate of the data.

Attributes:
orientation_

Output of the selected orientation method applied per stride. The first orientation is obtained by aligning the acceleration data at the start of each stride with gravity. This contains len(data) + 1 orientations for each stride, as the initial orientation is included in the output.

position_

Output of the selected position method applied per stride. The initial value of the postion is assumed to be [0, 0, 0]. This contains len(data) + 1 values for each stride, as the initial position is included in the output.

velocity_

The velocity as provided by the selected position method applied per stride. The initial value of the velocity is assumed to be [0, 0, 0]. This contains len(data) + 1 values for each stride, as the initial velocity is included in the output.

See also

gaitmap.trajectory_reconstruction

Implemented algorithms for orientation and position estimation

Examples

You can pick any orientation and any position estimation method that is implemented for this wrapper.

>>> from gaitmap.trajectory_reconstruction import SimpleGyroIntegration
>>> from gaitmap.trajectory_reconstruction import ForwardBackwardIntegration
>>> # Create custom instances of the methods you want to use
>>> ori_method = SimpleGyroIntegration()
>>> pos_method = ForwardBackwardIntegration()
>>> # Create an instance of the wrapper
>>> per_stride_traj = StrideLevelTrajectory(ori_method=ori_method, pos_method=pos_method)
>>> # Apply the method
>>> data = ...
>>> sampling_rate_hz = 204.8
>>> stride_list = ...
>>> per_stride_traj = per_stride_traj.estimate(
...     data, stride_event_list=stride_list, sampling_rate_hz=sampling_rate_hz
... )
>>> per_stride_traj.position_
<Dataframe or dict with all the positions per stride>
>>> per_stride_traj.orientation_
<Dataframe or dict with all the orientations per stride>

Methods

clone()

Create a new instance of the class with all parameters copied over.

estimate(data, stride_event_list, *, ...)

Use the initial rotation and the gyroscope signal to estimate the orientation to every time point .

from_json(json_str)

Import an gaitmap object from its json representation.

get_params([deep])

Get parameters for this algorithm.

set_params(**params)

Set the parameters of this Algorithm.

to_json()

Export the current object parameters as json.

__init__(*, ori_method: BaseOrientationMethod | None = cf(SimpleGyroIntegration(initial_orientation=array([0., 0., 0., 1.]), memory=None)), pos_method: BasePositionMethod | None = cf(ForwardBackwardIntegration(gravity=array([0., 0., 9.81]), level_assumption=True, steepness=0.08, turning_point=0.5)), trajectory_method: BaseTrajectoryMethod | None = None, align_window_width: int = 8) None[source]#
clone() Self[source]#

Create a new instance of the class with all parameters copied over.

This will create a new instance of the class itself and all nested objects

estimate(data: DataFrame | dict[Union[collections.abc.Hashable, str], pandas.core.frame.DataFrame], stride_event_list: DataFrame | dict[Union[collections.abc.Hashable, str], pandas.core.frame.DataFrame], *, sampling_rate_hz: float) Self[source]#

Use the initial rotation and the gyroscope signal to estimate the orientation to every time point .

Parameters:
data

At least must contain 3D-gyroscope and 3D-accelerometer data.

stride_event_list

List of events for one or multiple sensors. For each stride, the orientation and position will be calculated separately. The events per strides will be forwarded as the optional stride list to the underlying ori/pos/traj method.

sampling_rate_hz

Sampling rate with which IMU data was recorded.

classmethod from_json(json_str: str) Self[source]#

Import an gaitmap object from its json representation.

For details have a look at the this example.

You can use the to_json method of a class to export it as a compatible json string.

Parameters:
json_str

json formatted string

get_params(deep: bool = True) dict[str, Any][source]#

Get parameters for this algorithm.

Parameters:
deep

Only relevant if object contains nested algorithm objects. If this is the case and deep is True, the params of these nested objects are included in the output using a prefix like nested_object_name__ (Note the two “_” at the end)

Returns:
params

Parameter names mapped to their values.

set_params(**params: Any) Self[source]#

Set the parameters of this Algorithm.

To set parameters of nested objects use nested_object_name__para_name=.

to_json() str[source]#

Export the current object parameters as json.

For details have a look at the this example.

You can use the from_json method of any gaitmap algorithm to load the object again.

Warning

This will only export the Parameters of the instance, but not any results!

Examples using gaitmap.trajectory_reconstruction.StrideLevelTrajectory#

MaD DiGait Pipeline

MaD DiGait Pipeline

MaD DiGait Pipeline
Stride Level Trajectory reconstruction

Stride Level Trajectory reconstruction

Stride Level Trajectory reconstruction
Export Algorithms to JSON

Export Algorithms to JSON

Export Algorithms to JSON