Kinematics

The kinematics module allows opening trajectories of markers from c3d or n3d files.

[1]:
import kineticstoolkit.lab as ktk
import numpy as np

Loading a c3d or n3d file

The kinematics module provide the methods read_c3d_file and read_n3d_file to read files generated by common motion capture devices. Reading c3d files is provided by the external ezc3d module; see the Installing section for information on how to install ezc3d.

In this tutorial, we will read a n3d file generated by an Optotrak system.

[2]:
# Names of the markers
labels = [
    'Probe1', 'Probe2', 'Probe3', 'Probe4', 'Probe5', 'Probe6',
    'WheelchairRearR', 'WheelchairRearL', 'WheelchairFront',
    'ScapulaL1', 'ScapulaL2', 'ScapulaL3',
    'ScapulaR1', 'ScapulaR2', 'ScapulaR3',
    'Head1', 'Head2', 'Head3',
    'Sternum',
    'ArmL1', 'ArmL2', 'ArmL3',
    'LateralEpicondyleL', 'ForearmL1', 'ForearmL2', 'ForearmL3',
    'NAG',
    'GloveL1', 'GloveL2', 'GloveL3',
    'ArmR1', 'ArmR2', 'ArmR3',
    'LateralEpicondyleR', 'ForearmR1', 'ForearmR2', 'ForearmR3',
    'NAR',
    'GloveR1', 'GloveR2', 'GloveR3']

markers = ktk.kinematics.read_n3d_file('data/kinematics/sample_static.n3d',
                                       labels=labels)

markers
[2]:
TimeSeries with attributes:
             data: <dict with 41 entries>,
        data_info: <dict with 41 entries>,
           events: <list of 0 items>,
             time: <array of shape (700,)>,
        time_info: <dict with 1 entries>

Each data key corresponds to the trajectory of one marker:

[3]:
markers.data
[3]:
{
                   'ArmL1': <array of shape (700, 4)>,
                   'ArmL2': <array of shape (700, 4)>,
                   'ArmL3': <array of shape (700, 4)>,
                   'ArmR1': <array of shape (700, 4)>,
                   'ArmR2': <array of shape (700, 4)>,
                   'ArmR3': <array of shape (700, 4)>,
               'ForearmL1': <array of shape (700, 4)>,
               'ForearmL2': <array of shape (700, 4)>,
               'ForearmL3': <array of shape (700, 4)>,
               'ForearmR1': <array of shape (700, 4)>,
               'ForearmR2': <array of shape (700, 4)>,
               'ForearmR3': <array of shape (700, 4)>,
                 'GloveL1': <array of shape (700, 4)>,
                 'GloveL2': <array of shape (700, 4)>,
                 'GloveL3': <array of shape (700, 4)>,
                 'GloveR1': <array of shape (700, 4)>,
                 'GloveR2': <array of shape (700, 4)>,
                 'GloveR3': <array of shape (700, 4)>,
                   'Head1': <array of shape (700, 4)>,
                   'Head2': <array of shape (700, 4)>,
                   'Head3': <array of shape (700, 4)>,
      'LateralEpicondyleL': <array of shape (700, 4)>,
      'LateralEpicondyleR': <array of shape (700, 4)>,
                     'NAG': <array of shape (700, 4)>,
                     'NAR': <array of shape (700, 4)>,
                  'Probe1': <array of shape (700, 4)>,
                  'Probe2': <array of shape (700, 4)>,
                  'Probe3': <array of shape (700, 4)>,
                  'Probe4': <array of shape (700, 4)>,
                  'Probe5': <array of shape (700, 4)>,
                  'Probe6': <array of shape (700, 4)>,
               'ScapulaL1': <array of shape (700, 4)>,
               'ScapulaL2': <array of shape (700, 4)>,
               'ScapulaL3': <array of shape (700, 4)>,
               'ScapulaR1': <array of shape (700, 4)>,
               'ScapulaR2': <array of shape (700, 4)>,
               'ScapulaR3': <array of shape (700, 4)>,
                 'Sternum': <array of shape (700, 4)>,
         'WheelchairFront': <array of shape (700, 4)>,
         'WheelchairRearL': <array of shape (700, 4)>,
         'WheelchairRearR': <array of shape (700, 4)>
}

Visualizing the markers

The Player class is a matplotlib based user interface to visualize markers, rigid bodies and segments in three dimensions. It is important to select an interactive IPython’s GUI front-end, or the Player’s figure will simply print out without being interactive. See the Installing section for more information.

[4]:
ktk.Player(markers)
[4]:
<kineticstoolkit.player.Player at 0x7fcde3097910>
_images/kinematics_7_1.png

For more information on kinematics, please check the API Reference for the kinematics module.