pyomeca / ezc3d

Easy to use C3D reader/writer for C++, Python and Matlab
https://pyomeca.github.io/Documentation/ezc3d/index.html
MIT License
142 stars 44 forks source link

transforming a script from matlab to python using an alternative library to btk #313

Closed OfirBitton closed 4 months ago

OfirBitton commented 6 months ago

I'm struggling to find a library that offers btk functions, for example matlab functions like this :

acq = btkReadAcquisition(SelectedFile); Afs = btkGetAnalogFrequency(acq); ratio = btkGetAnalogSampleNumberPerFrame(acq); analogs = btkGetAnalogs(acq); markers = btkGetMarkers(acq); events = btkGetEvents(acq); angles = btkGetAngles(acq); moments = btkGetMoments(acq); power = btkGetPowers(acq);

Maybe I'm searching in the wrong place, but does ezc3d have all of these functions? Alternatively do you know which libraries I need to integrate to get those methods to run in Python?

an answer from @pariterre : All these values can be retrieved using ezc3d. That said, these are Nexus designed functions. Vicon hacked a bit the standard formatting to include data which were not supposed to be in the c3d, namely the angles, the moments and the power. They basically put the data in the "points" data.

Here is the doc for python: https://github.com/pyomeca/ezc3d/?tab=readme-ov-file#python-3

Here are some idea (not tested)

from ezc3d import c3d
c = c3d('path_to_c3d.c3d')
c['header']  # This stores generic information about the data collection such as the frame rate and events
analogs = c['data']['analogs']
markers = c['data']['points']
point_labels = c['parameters']['POINT']['LABELS']
# In point_labels, you will find which columns are dedicated to markers, angles, moments and power
# define the indices using point_labels (e.g. angles_starting_index and angles_last_index)
angles = c['data']['points'][angles_starting_index:angles_last_index, :]
# same for moments and power
# For the analog frequency, you will find these information in the ANALOG parameter, something like
analog_rate = c['parameters']['ANALOG']['RATE']['value'][0]
pariterre commented 6 months ago

Thanks @OfirBitton for copy-pasting this conversion :)

Do not hesitate to update the proposed snippet if you try and correct it!