Plotting muscle tendon legth against gait cycle - Python
- Jose Ignacio Gil
- Posts: 2
- Joined: Fri Feb 17, 2017 7:16 am
Plotting muscle tendon legth against gait cycle - Python
Hi there!
I'm working on a script that exports the muscle-tendon length data into a .CSV file. When I do this manually in the plot GUI, I choose for the X-Axis "Coordinates(Deg.)" and it works fine but when I try to do it in the code ("addAnalysisCurve bla bla bla") it says that "Coordinates(Deg.)" its not an element.
Any ideas in how can I fix this? Is there a simpler way of exporting muscle-tendon length data?
Thank you very much in advance.
Jose.
I'm working on a script that exports the muscle-tendon length data into a .CSV file. When I do this manually in the plot GUI, I choose for the X-Axis "Coordinates(Deg.)" and it works fine but when I try to do it in the code ("addAnalysisCurve bla bla bla") it says that "Coordinates(Deg.)" its not an element.
Any ideas in how can I fix this? Is there a simpler way of exporting muscle-tendon length data?
Thank you very much in advance.
Jose.
- Thomas Uchida
- Posts: 1790
- Joined: Wed May 16, 2012 11:40 am
Re: Plotting muscle tendon legth against gait cycle - Python
I'm unable to find an addAnalysisCurve() method in the OpenSim API. Where did you find this method and what argument(s) does it take? In the Plotter, the "Coordinates(Deg.)" list item will refer to a previous result you've loaded into the GUI (e.g., the .mot file generated by IK).
There are a couple ways of generating muscle–tendon length data. Based on your question, I'm assuming you're seeking these data for a simulation you've already run, in which case you can add a MuscleAnalysis (https://simtk.org/api_docs/opensim/api_ ... lysis.html) and run an analysis using the AnalyzeTool (https://simtk.org/api_docs/opensim/api_ ... eTool.html).
There are a couple ways of generating muscle–tendon length data. Based on your question, I'm assuming you're seeking these data for a simulation you've already run, in which case you can add a MuscleAnalysis (https://simtk.org/api_docs/opensim/api_ ... lysis.html) and run an analysis using the AnalyzeTool (https://simtk.org/api_docs/opensim/api_ ... eTool.html).
- Jose Ignacio Gil
- Posts: 2
- Joined: Fri Feb 17, 2017 7:16 am
Re: Plotting muscle tendon legth against gait cycle - Python
I found the function in the OpenSim tutorials on plotting and exporting data.
I'll check de MuscleAnalysis tool!
Thank you
PS: Does this works on the Jython Console inside OpenSim?
I'll check de MuscleAnalysis tool!
Thank you
PS: Does this works on the Jython Console inside OpenSim?
- Thomas Uchida
- Posts: 1790
- Joined: Wed May 16, 2012 11:40 am
Re: Plotting muscle tendon legth against gait cycle - Python
Scripting-related information and examples can be found in the "Scripting" section of the documentation: http://simtk-confluence.stanford.edu:80 ... /Scripting.
- Marcos Alfredo Núñez
- Posts: 22
- Joined: Thu Sep 01, 2016 1:41 pm
Re: Plotting muscle tendon legth against gait cycle - Python
As suggested, I created a MuscleAnalysis and ran it through an AnalyzeTool from python, which worked perfectly. The only info I need right now is the muscle-tendon length of a few muscles. The tool, however, creates a myriad of storage files for moments, forces and angles (all of them empty, with only the headers). The only one I care about is xxx_MuscleAnalysis_Length.sto. Is there any way to prevent all these storage files from being created? Even better: is there a way to loop the model's state coordinates, computing the muscle length at every step?
- Thomas Uchida
- Posts: 1790
- Joined: Wed May 16, 2012 11:40 am
Re: Plotting muscle tendon legth against gait cycle - Python
Yes, you can iterate through the states and compute only the variables of interest.Is there any way to prevent all these storage files from being created?
- Marcos Alfredo Núñez
- Posts: 22
- Joined: Thu Sep 01, 2016 1:41 pm
Re: Plotting muscle tendon legth against gait cycle - Python
Thanks Tom! I've no trouble looping through a model with its ModelVisualizer on, since at every step I call getVisualizer().show(newState). It works exactly as you show in other Matlab examples I found here. However, without it, how can I loop the model through the different states? I see that the show() method calls
before reporting the state to the underlying SimbodyVisualizer. However, from my python wrapper, I can't call realize()
Code: Select all
_model.getMultibodySystem().realize(state, SimTK::Stage::Velocity)
Code: Select all
AttributeError: 'SwigPyObject' object has no attribute 'realize'
- Thomas Uchida
- Posts: 1790
- Joined: Wed May 16, 2012 11:40 am
Re: Plotting muscle tendon legth against gait cycle - Python
Have you tried computeStateVariableDerivatives() (https://simtk.org/api_docs/opensim/api_ ... 3dc9c41d17)? I think that method is wrapped and will end up calling realize.
- Marcos Alfredo Núñez
- Posts: 22
- Joined: Thu Sep 01, 2016 1:41 pm
Re: Plotting muscle tendon legth against gait cycle - Python
Tom:
I just saw you post a very similar answer in another post, but Matlab code. I don't think it's working, muscle lengths are far from what informed in the MuscleAnalysis Tool. Posting here the example function I'm working on:
Am I looping the states correctly?
I just saw you post a very similar answer in another post, but Matlab code. I don't think it's working, muscle lengths are far from what informed in the MuscleAnalysis Tool. Posting here the example function I'm working on:
Code: Select all
def computeLen(mot,mod):
storage = opensim.Storage(mot)
model = opensim.Model(mod)
model.setUseVisualizer(False)
state = model.initSystem()
semiten_l = model.getMuscles().get('semiten_l')
lengths_array = []
for i in range(storage.getSize()):
dat = storage.getStateVector(i).getData()
for j in range(model.getNumCoordinates()):
model.updCoordinateSet().get(j).setValue(state,dat.get(j))
# Here should go model.realizePosition(state), which I lack.
model.computeStateVariableDerivatives(state)
lengths_array.append(semiten_l.getLength(state))
return lengths_array
- Thomas Uchida
- Posts: 1790
- Joined: Wed May 16, 2012 11:40 am
Re: Plotting muscle tendon legth against gait cycle - Python
It looks like you are assuming the States are in the same order as the Coordinates in the Model's CoordinateSet, which is not true in general.