Page 1 of 2
C3D export
Posted: Tue Feb 11, 2020 4:21 pm
by kernalnet
Dear Experts,
I have a problem in using python for OpenSim 4.1
My Anaconda is for python 2 (anaconda2),
I created a new environment for OpenSim 4.1 with python 3.7
The 4.1\bin folder is on my system path environment.
The codes are exactly the same as "Reading C3D files through Python"
in addition to importing os, opensim and numpy
But this error appears in that code:
(opensim41) C:\Users\MohammadReza\Desktop>python opensim41.py
Traceback (most recent call last):
File "opensim41.py", line 14, in <module>
tables = C3DFileAdapter.readFile(os.path.join(test_dir, 'walking2.c3d'), 1)
NameError: name 'C3DFileAdapter' is not defined
Would you please help me with this code and error?
Your help would be greatly appreciated.
Cheers
Re: C3D export
Posted: Tue Feb 11, 2020 10:33 pm
by aymanh
Hello,
The interface to C3DFileAdapter has changed, please consult the doxygen documentation here for available methods
https://simtk.org/api_docs/opensim/api_ ... apter.html
The class now uses the generic read method from its base class rather than a custom readFile method as of version 4.1
Best regards,
-Ayman
Re: C3D export
Posted: Wed Feb 12, 2020 12:58 am
by kernalnet
Hi Aymen,
Many thanks for your reply.
Is there anything wrong with this new code?
import opensim
C3DFileAdapter c3dFileAdapter;
c3dFileAdapter.setLocationForForceExpression(opensim.C3DFileAdapter.ForceLocation_CenterOfPressure);
tables = c3dFileAdapter.read("walking5.c3d")
markers = tables['markers']
forces = tables['forces']
There is still an error:
(opensim41) C:\Users\MohammadReza\Desktop>python opensim41.py
File "opensim41.py", line 2
C3DFileAdapter c3dFileAdapter;
^
SyntaxError: invalid syntax
I execute this code in Anaconda Prompt and this is my python version:
(opensim41) C:\Users\MohammadReza\Desktop>python --version
Python 3.7.6
I'm grateful for your help
Cheers
Re: C3D export
Posted: Wed Feb 12, 2020 1:05 am
by tkuchida
It looks like your code is part C++ and part Python. For reference, there's a related test case here:
https://github.com/opensim-org/opensim- ... ter.py#L33. You should have something like this:
Code: Select all
import opensim
c3dFileAdapter = opensim.C3DFileAdapter()
...
Re: C3D export
Posted: Wed Feb 12, 2020 1:17 am
by kernalnet
tkuchida wrote: ↑Wed Feb 12, 2020 1:05 am
It looks like your code is part C++ and part Python.
Thanks Tom,
There is an example on doxygen for python:
- 1.JPG (19.68 KiB) Viewed 589 times
https://simtk.org/api_docs/opensim/api_ ... apter.html
But now it works well
Cheers
Re: C3D export
Posted: Wed Feb 12, 2020 8:14 am
by tkuchida
Great. Thanks for reporting- I'll submit a fix.
Re: C3D export
Posted: Wed Feb 12, 2020 1:06 pm
by kernalnet
Hi,
It would be great if these examples become updated for 4.1 version as well.
https://simtk-confluence.stanford.edu:8 ... d%29+Files
Best Wishes
Re: C3D export
Posted: Wed Feb 12, 2020 1:14 pm
by tkuchida
Thanks for reporting. I've opened an Issue on GitHub (
https://github.com/opensim-org/opensim-core/issues/2673) to investigate.
Re: C3D export
Posted: Thu Feb 13, 2020 11:24 am
by kernalnet
Hi again,
In MATLAB, "rotateData" and "convertMillimeters2Meters" were defined
but in python, I can't find them. are there any examples of these
functions in python for "forces"?
adapter = opensim.C3DFileAdapter()
task = adapter.read(os.path.join(output_dir, 'task.c3d'))
forces = adapter.getForcesTable(task)
Your response would be greatly appreciated.
Cheers
Re: C3D export
Posted: Fri Feb 14, 2020 8:58 am
by tkuchida
rotateData() and convertMillimeters2Meters() are functions written in Matlab (
https://github.com/opensim-org/opensim- ... C3D.m#L138 and
https://github.com/opensim-org/opensim- ... C3D.m#L154). You can implement them in Python if you need them there.