Page 1 of 1

How to convert .c3d to .mot and .trc in python

Posted: Sun Feb 09, 2020 5:42 pm
by corrine
Hello,

I checked this link https://simtk-confluence.stanford.edu:8 ... d%29+Files, in which .c3d can be written into two .sto files using python.

I know that MATLAB can convert .c3d to .mot and .trc files, is it possible to do so in python? If so, does anyone have any examples?

Many thanks,

Re: How to convert .c3d to .mot and .trc in python

Posted: Mon Feb 10, 2020 2:09 am
by mitkof6
Hi,

I am attaching a script and some utility functions that I use in Python. Please note that some settings (rotation, mirror) should be changed to correspond to your lab's coordinate system.
scripts.zip
(7.21 KiB) Downloaded 60 times

Re: How to convert .c3d to .mot and .trc in python

Posted: Tue Feb 11, 2020 3:38 pm
by kernalnet
mitkof6 wrote:
Mon Feb 10, 2020 2:09 am
scripts.zip
Hi Dimitar,

Many thanks for sharing these scripts.
Do you have any solution for python 3.7 (OpenSim 4.1)?
It seems that the BTK package has been only developed for python 2.7.

Cheers

Re: How to convert .c3d to .mot and .trc in python

Posted: Wed Feb 12, 2020 6:52 pm
by mitkof6
These should work with Python 3.7. Actually btk and any related functions can be removed from utils.py. I do some additional processing of c3d that is currently not supported in OpenSim. By the way I had a PR on btk so that it can be build with Python 3:

https://github.com/Biomechanical-ToolKi ... re/pull/29

Re: How to convert .c3d to .mot and .trc in python

Posted: Mon Mar 15, 2021 11:37 am
by kbsmale
mitkof6 wrote:
Mon Feb 10, 2020 2:09 am
Hi,

I am attaching a script and some utility functions that I use in Python. Please note that some settings (rotation, mirror) should be changed to correspond to your lab's coordinate system.

scripts.zip
Hi @Dimitar,

I've set up python 3.7 and OpenSim 4.1 in my Anaconda-Spyder environment. When I try to read my c3d file through the adapter, I get the following error:

Code: Select all

static = adapter.read(os.path.join(c3d_dir, static_file), 1)
Traceback (most recent call last):

  File "<ipython-input-73-526983ac6a6d>", line 1, in <module>
    static = adapter.read(os.path.join(c3d_dir, static_file), 1)

TypeError: read() takes 2 positional arguments but 3 were given
This error is confusing because I believe I'm only passing two arguments (full file name, and 1) so I'm not sure what the issue is. If I simply pass the file path and name to adapter.read, it passes without error but my datatype is "common.StdMapStringAbstractDataTable", which I believe causes problems later on when trying rotate_data_table.

Any idea where I'm going awry here?

Re: How to convert .c3d to .mot and .trc in python

Posted: Thu Mar 18, 2021 11:15 pm
by aymanh
Hello,

Here's an example from our code base (version 4.2 (beta))
https://github.com/opensim-org/opensim- ... ter.py#L33

Hope this helps,
Ayman

Re: How to convert .c3d to .mot and .trc in python

Posted: Tue Mar 23, 2021 3:11 pm
by kernalnet
Hi Kenneth,

First, I would like to thank Dr. Dimitar Stanev for sharing the scripts.

BTK can be installed in python 3.x via this conda distribution:

Code: Select all

conda install -c conda-forge btk
Regarding the error, please add this line before "static":

Code: Select all

adapter.setLocationForForceExpression(opensim.C3DFileAdapter.ForceLocation_CenterOfPressure)
and modify the "static" to:

Code: Select all

static = adapter.read(os.path.join(c3d_dir, static_file))
You can find more info here:
https://simtk.org/api_docs/opensim/api_ ... apter.html

Hope this helps.

Regards,
Mohammadreza