.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/trajectory_reconstruction/trajectory_reconstruction.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_trajectory_reconstruction_trajectory_reconstruction.py: .. _trajectory_stride: Stride Level Trajectory reconstruction ====================================== Gaitmap has two ways to reconstruct the trajectory (orientation and position) of an IMU. The first method is two use any method from the modules :mod:`~gaitmap.trajectory_reconstruction.orientation_methods` or :mod:`~gaitmap.trajectory_reconstruction.position_methods` directly. This is a great option, if you want to reconstruct a trajectory without performing any other step of the pipeline. The second option is to use any of the available `TrajectoryWrapperClasses` methods from the :mod:`~gaitmap.trajectory_reconstruction` module. These allow you to easily calculate multiple trajectories for e.g. multiple strides. This example illustrates how a trajectory can be reconstructed for each stride by the :class:`~gaitmap.trajectory_reconstruction.StrideLevelTrajectory` class. Note that this example does not take care of any preprocessing steps, which might be necessary for your data, such as alignment to gravity and axis transformations. To learn more about such preprocessing steps see :ref:`this example `. .. GENERATED FROM PYTHON SOURCE LINES 24-29 Getting input data ------------------ For this we need a stride event list obtained from an event detection method and the sensor data. The example data used in the following is already in the correct gaitmap coordinate system. .. GENERATED FROM PYTHON SOURCE LINES 29-39 .. code-block:: default import matplotlib.pyplot as plt from gaitmap.example_data import get_healthy_example_imu_data, get_healthy_example_stride_events from gaitmap.trajectory_reconstruction import ForwardBackwardIntegration, SimpleGyroIntegration, StrideLevelTrajectory stride_list = get_healthy_example_stride_events() imu_data = get_healthy_example_imu_data() stride_list["left_sensor"].head(3) .. raw:: html
s_id start end ic tc min_vel pre_ic
0 0 494.0 709.0 657.0 586.0 494.0 438.0
1 1 709.0 924.0 877.0 803.0 709.0 657.0
2 2 924.0 1180.0 1096.0 1024.0 924.0 877.0


.. GENERATED FROM PYTHON SOURCE LINES 40-63 Selecting and Configuring Algorithms ------------------------------------ The stride level method takes an instance of an orientation and a position estimation method as configuration parameter. Here, we use simple gyroscopic integration for orientation estimation and forward-backward integration for position estimation. You can replace the orientation- or position-estimation methods by any of the methods in :mod:`~gaitmap.trajectory_reconstruction.orientation_methods` and :mod:`~gaitmap.trajectory_reconstruction.position_methods`. Be aware of the assumptions the used methods make. For example the :class:`~gaitmap.trajectory_reconstruction.ForwardBackwardIntegration` assumes that the start and end of each stride is a resting period. The same assumption is used by the :class:`~gaitmap.trajectory_reconstruction.StrideLevelTrajectory` itself to estimate the initial orientation at the beginning of each stride. Note that this method further assumes the sensor to be aligned with your world coordinate system at the beginning of the stride (z-axis in direction of gravity). If this is not True in your case and you need to modify the starting orientation or position, you need to call the orientation and position methods directly for each each stride without the use of the `StrideLevelTrajectory` wrapper. Do so by passing `initial_orientation` to the initialization of the `ori_method`. However, in :class:`~gaitmap.trajectory_reconstruction.StrideLevelTrajectory` this initial orientation will be overwritten by an initial orientation estimated from gravity. .. GENERATED FROM PYTHON SOURCE LINES 63-68 .. code-block:: default ori_method = SimpleGyroIntegration() pos_method = ForwardBackwardIntegration() trajectory = StrideLevelTrajectory(ori_method=ori_method, pos_method=pos_method) .. GENERATED FROM PYTHON SOURCE LINES 69-71 Calculate and inspect results ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 71-92 .. code-block:: default sampling_frequency_hz = 204.8 trajectory.estimate(data=imu_data, stride_event_list=stride_list, sampling_rate_hz=sampling_frequency_hz) # select the position of the first stride first_stride_position = trajectory.position_["left_sensor"].loc[0] first_stride_position.plot() plt.title("Left Foot Trajectory per axis") plt.xlabel("sample") plt.ylabel("position [m]") plt.show() # select the orientation of the first stride first_stride_orientation = trajectory.orientation_["left_sensor"].loc[0] first_stride_orientation.plot() plt.title("Left Foot Orientation per axis") plt.xlabel("sample") plt.ylabel("orientation [a.u.]") plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/trajectory_reconstruction/images/sphx_glr_trajectory_reconstruction_001.png :alt: Left Foot Trajectory per axis :srcset: /auto_examples/trajectory_reconstruction/images/sphx_glr_trajectory_reconstruction_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/trajectory_reconstruction/images/sphx_glr_trajectory_reconstruction_002.png :alt: Left Foot Orientation per axis :srcset: /auto_examples/trajectory_reconstruction/images/sphx_glr_trajectory_reconstruction_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.971 seconds) **Estimated memory usage:** 9 MB .. _sphx_glr_download_auto_examples_trajectory_reconstruction_trajectory_reconstruction.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: trajectory_reconstruction.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: trajectory_reconstruction.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_