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,
How to convert .c3d to .mot and .trc in python
- corrine bao
- Posts: 1
- Joined: Thu Sep 27, 2018 1:59 am
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: How to convert .c3d to .mot and .trc in python
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.
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.
- Mohammadreza Rezaie
- Posts: 408
- Joined: Fri Nov 24, 2017 12:48 am
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: How to convert .c3d to .mot and .trc in python
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
https://github.com/Biomechanical-ToolKi ... re/pull/29
- Kenneth Smale
- Posts: 12
- Joined: Thu Mar 05, 2015 10:11 am
Re: How to convert .c3d to .mot and .trc in python
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
Any idea where I'm going awry here?
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: How to convert .c3d to .mot and .trc in python
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
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
- Mohammadreza Rezaie
- Posts: 408
- Joined: Fri Nov 24, 2017 12:48 am
Re: How to convert .c3d to .mot and .trc in python
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:
Regarding the error, please add this line before "static":
and modify the "static" to:
You can find more info here:
https://simtk.org/api_docs/opensim/api_ ... apter.html
Hope this helps.
Regards,
Mohammadreza
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
Code: Select all
adapter.setLocationForForceExpression(opensim.C3DFileAdapter.ForceLocation_CenterOfPressure)
Code: Select all
static = adapter.read(os.path.join(c3d_dir, static_file))
https://simtk.org/api_docs/opensim/api_ ... apter.html
Hope this helps.
Regards,
Mohammadreza