How can I extract muscle activations after static optimization?
Posted: Mon Mar 04, 2024 10:29 am
Hi,
I am running a static optimization simulation using Python scripting with OpenSim 4.4. I am interested to store muscle activations after a static optimization run. With this code below, I can access muscle names in my model and print activations, but the values seem un-correct (prints 0.05 for all the muscles). I understand that I need to access the model state corresponding the static optimization but failed to do this so far.
----
model = osim.Model(modelpath)
stat_opt = osim.AnalyzeTool('staticOpt_Setup.xml')
stat_opt.setModel(model)
stat_opt.setStartTime(0)
stat_opt.setFinalTime(0)
stat_opt.setCoordinatesFileName(posturepath)
stat_opt.run();
state = model.initSystem();
muscle_set = model.getMuscles()
for i in range(0, muscle_set.getSize()):
print(muscle_set.get(i).getName())
print(muscle_set.get(i).getActivation(state))
----
Another question I have is that I am more interested in storing the mathematical sum of all the muscles in the model than individual muscle activations. Is there a feature/default parameter in OpenSim that stores this value? Thanks for any help on this post.
I am running a static optimization simulation using Python scripting with OpenSim 4.4. I am interested to store muscle activations after a static optimization run. With this code below, I can access muscle names in my model and print activations, but the values seem un-correct (prints 0.05 for all the muscles). I understand that I need to access the model state corresponding the static optimization but failed to do this so far.
----
model = osim.Model(modelpath)
stat_opt = osim.AnalyzeTool('staticOpt_Setup.xml')
stat_opt.setModel(model)
stat_opt.setStartTime(0)
stat_opt.setFinalTime(0)
stat_opt.setCoordinatesFileName(posturepath)
stat_opt.run();
state = model.initSystem();
muscle_set = model.getMuscles()
for i in range(0, muscle_set.getSize()):
print(muscle_set.get(i).getName())
print(muscle_set.get(i).getActivation(state))
----
Another question I have is that I am more interested in storing the mathematical sum of all the muscles in the model than individual muscle activations. Is there a feature/default parameter in OpenSim that stores this value? Thanks for any help on this post.