.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/laterality/_01_lrc_mccamley.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_laterality__01_lrc_mccamley.py: McCamley L/R Classifier ======================= The McCamley L/R classifier is a simple algorithm to detect the laterality of initial contacts based on the sign of the angular velocity signal. We use a modified version of the original McCamley algorithm, which includes a smoothing filter to reduce the influence of noise on the detection. This example shows how to use the algorithm and compares the output to the reference labels on some example data. .. GENERATED FROM PYTHON SOURCE LINES 12-15 .. code-block:: default from mobgap.data import LabExampleDataset .. GENERATED FROM PYTHON SOURCE LINES 16-27 Loading some example data ------------------------- .. note :: More infos about data loading can be found in the :ref:`data loading example `. We load example data from the lab dataset together with the INDIP reference system. We will use the INDIP "InitialContact_Event" output as ground truth. We only use the data from the "simulated daily living" activity test from a single participant. Like most algorithms, the algorithm requires the data to be in body frame coordinates. As we know the sensor was well aligned, we can just use ``to_body_frame`` to transform the data. .. GENERATED FROM PYTHON SOURCE LINES 27-44 .. code-block:: default from mobgap.utils.conversions import to_body_frame example_data = LabExampleDataset( reference_system="INDIP", reference_para_level="wb" ) single_test = example_data.get_subset( cohort="MS", participant_id="001", test="Test11", trial="Trial1" ) imu_data = to_body_frame(single_test.data_ss) reference_wbs = single_test.reference_parameters_.wb_list sampling_rate_hz = single_test.sampling_rate_hz ref_ics = single_test.reference_parameters_.ic_list ref_ics_rel_to_gs = single_test.reference_parameters_relative_to_wb_.ic_list reference_wbs .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.9.0/mobgap/data/_mobilised_matlab_loader.py:1082: UserWarning: There were multiple ICs with the same index value, but different LR labels. This is likely an issue with the reference system you should further investigate. For now, we set the `lr_label` of the stride corresponding to this IC to Nan. However, both values still remain in the IC list. return parse_reference_parameters( /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.9.0/mobgap/data/_mobilised_matlab_loader.py:1082: UserWarning: There were multiple ICs with the same index value, but different LR labels. This is likely an issue with the reference system you should further investigate. For now, we set the `lr_label` of the stride corresponding to this IC to Nan. However, both values still remain in the IC list. return parse_reference_parameters( /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.9.0/mobgap/data/_mobilised_matlab_loader.py:1091: UserWarning: There were multiple ICs with the same index value, but different LR labels. This is likely an issue with the reference system you should further investigate. For now, we set the `lr_label` of the stride corresponding to this IC to Nan. However, both values still remain in the IC list. return parse_reference_parameters( .. raw:: html
start end n_strides duration_s length_m avg_walking_speed_mps avg_cadence_spm avg_stride_length_m termination_reason
wb_id
0 1019 1768 9 7.48 4.468932 0.847668 107.795850 0.942678 Pause
1 4534 5549 11 10.14 2.900453 0.365176 93.396106 0.483923 Pause
2 9665 10569 9 9.03 2.140232 0.294058 75.981133 0.506458 Pause
3 12337 14633 28 22.95 11.201110 0.634425 92.337768 0.803933 Pause
4 20151 20982 11 8.30 2.390709 0.371746 87.915774 0.507484 Pause
5 21378 22129 9 7.50 2.517558 0.492965 95.365740 0.599360 Pause


.. GENERATED FROM PYTHON SOURCE LINES 45-55 Applying the algorithm using reference ICs ------------------------------------------ We use the McCamley algorithm to detect the laterality of the initial contacts. For this we need the IMU data and the indices of the initial contacts per GS. To focus this example on the L/R detection, we use the reference ICs from the INDIP system as input. In a real application, we would use the output of the IC-detectors as input. We will use the `GsIterator` to iterate over the gait sequences and apply the algorithm to each wb. Note, that we use the ``ic_list`` result key, as the output of all L/R detectors is identical to the output of the IC-detectors, but with an additional ``lr_label`` column. .. GENERATED FROM PYTHON SOURCE LINES 55-71 .. code-block:: default from mobgap.laterality import LrcMcCamley from mobgap.pipeline import GsIterator iterator = GsIterator() algo = LrcMcCamley() for (gs, data), result in iterator.iterate(imu_data, reference_wbs): result.ic_list = algo.predict( data, ic_list=ref_ics_rel_to_gs.loc[gs.id].drop("lr_label", axis=1), sampling_rate_hz=sampling_rate_hz, ).ic_lr_list_ detected_ics = iterator.results_.ic_list detected_ics.assign(ref_lr_label=ref_ics.lr_label) .. raw:: html
ic lr_label ref_lr_label
wb_id step_id
0 0 1019 right right
1 1065 left left
2 1129 right right
3 1172 left left
4 1236 right right
... ... ... ... ...
5 7 21896 right right
8 21951 right left
9 22042 left right
10 22089 right left
11 22128 right right

93 rows × 3 columns



.. GENERATED FROM PYTHON SOURCE LINES 72-75 We can see that for most ICs we correctly identify the laterality. If you want to learn more about evaluating the algorithm output, you can check the :ref:`evaluation example `. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.831 seconds) **Estimated memory usage:** 9 MB .. _sphx_glr_download_auto_examples_laterality__01_lrc_mccamley.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: _01_lrc_mccamley.py <_01_lrc_mccamley.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: _01_lrc_mccamley.ipynb <_01_lrc_mccamley.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_