I'm trying to script JRA with Python.
First I noticed there are 2 different pythons used. OpenSim uses Jython that comes with it. Also one can use system's python (CPython) but I had to compile GitHub version of opensim-core in order to make my (anaconda) python able to import opensim.
Then I noticed difference in API for 2 versions of python.
In python a have to do
Code: Select all
import opensim
Code: Select all
modelling
Than I adapted JRA script from this GitHub issue. My script is as follows. I tried to make it work both with Opensim's Jython and Python.
Also I used this model from OpenSim downloads.
Now running the script in python I get following error
Code: Select all
Updating Model file from 20302 to latest format...
Loaded model subject01 from file /Users/ali/Documents/OpenSim/JRA/subject01_simbody_adjusted.osim
Storage: read data file =/Users/ali/Documents/OpenSim/JRA/subject01_walk1_Kinematics.sto (nr=1500 nc=24)
IO.OpenInputFile(const string&,openmode mode): failed to open
Traceback (most recent call last):
File "jra.py", line 76, in <module>
perform_jra(JRA_MODEL, JRA_KINEMATICS, JRA_JRF, JRA_JRF_XML, JRA_RESERVE_ACTUATORS, JRA_MUSCLE, JRA_RESULTS_DIR)
File "jra.py", line 74, in perform_jra
analysis.run()
File "/Users/ali/miniconda3/envs/opensim/lib/python2.7/site-packages/opensim-4.0-py2.7.egg/opensim/tools.py", line 8730, in run
return _tools.AnalyzeTool_run(self, *args)
RuntimeError: std::exception in 'bool OpenSim::AnalyzeTool::run()': Storage: Failed to open file ''. Verify that the file exists at the specified location.
Thrown at Storage.cpp:181 in Storage().
Running the same in Juthon it fails earlier:
Code: Select all
Traceback (most recent call last):
File "/Users/ali/Documents/OpenSim/jra.py", line 76, in <module>
perform_jra(JRA_MODEL, JRA_KINEMATICS, JRA_JRF, JRA_JRF_XML, JRA_RESERVE_ACTUATORS, JRA_MUSCLE, JRA_RESULTS_DIR)
File "/Users/ali/Documents/OpenSim/jra.py", line 40, in perform_jra
external_loads = modeling.ExternalLoads(model, grf_xml)
at org.opensim.modeling.opensimSimulationJNI.new_ExternalLoads__SWIG_3(Native Method)
at org.opensim.modeling.ExternalLoads.<init>(ExternalLoads.java:73)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:210)
java.lang.NullPointerException: java.lang.NullPointerException: OpenSim::Model & reference is null