ktk.write_c3d#
- write_c3d(filename, points=None, analogs=None, rotations=None)[source]#
Write points, analog, and rotations data to a C3D file.
- Parameters:
filename (str) – Path of the C3D file
points (TimeSeries | None) –
Optional. Points trajectories, where data key corresponds to a point, expressed as an Nx4 point series:
[ [x0, y0, z0, 1.0], [x1, y1, z1, 1.0], [x2, y2, z2, 1.0], ..., ]
Events from this TimeSeries are also added to the c3d.
analogs (TimeSeries | None) –
Optional. Analog signals, where each data key is one series. Series that are not unidimensional are converted to multiple unidimensional series. For instance, if the shape of analogs.data[“Forces”] is 1000x3, then three unidimensional series of length 1000 are created in the C3D: Forces[0], Forces[1] and Forces[2].
If both analogs and points are specified, the sample rate of analogs must be an integer multiple of the points’s sample rate. Also, analogs.time[0] must be the same as points.time[0].
rotations (TimeSeries | None) –
Optional. Rotation matrices, where each data key corresponds to a rotation matrix, expressed as a Nx4x4 array.
If both rotations and points are specified, the sample rate of rotations must be an integer multiple of the points’s sample rate. Also, rotations.time[0] must be the same as rotations.time[0].
- Return type:
None
See also
Notes
This function relies on ezc3d, which is installed by default using conda, but not using pip. Please install ezc3d before using write_c3d. pyomeca/ezc3d
Example
Create a simple c3d file with two markers sampled at 240 Hz and two sinusoidal analog signals sampled at 1200 Hz, during 10 seconds:
import kineticstoolkit.lab as ktk import numpy as np points = ktk.TimeSeries() points.time = np.linspace(0, 10, 10*240, endpoint=False) points.data["Marker1"] = np.ones((2400, 4)) points.data["Marker2"] = np.ones((2400, 4)) analogs = ktk.TimeSeries() analogs.time = np.linspace(0, 10, 10*2400, endpoint=False) analogs.data["Signal1"] = np.sin(analogs.time) analogs.data["Signal2"] = np.cos(analogs.time) ktk.write_c3d("testfile.c3d", points=points, analogs=analogs)