Python Plotting Total Fiber Force

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
John Kounetas
Posts: 2
Joined: Tue Mar 26, 2024 5:44 pm

Python Plotting Total Fiber Force

Post by John Kounetas » Thu May 23, 2024 11:54 pm

Hi OpenSim Forums,

I am new too OpenSim, and I am trying to figure out how to produce the same total fiber force plot I plot in the GUI in Python so I can make batch processing easier (Plus I often get visualisation sizing errors in the plot window on the GUI).

The process on the GUI is to listed below, and I have included a screenshot of the window.
  • Load ARMS_bimanual.osim model
  • Load Skeletal.mot motion
  • Open plot window
  • Select Y-Quantity - total fiber force
  • Select Muscles, Select all shown, sum only
  • Select X-Quantity - Results (Skeletal.mot Name in header)
  • Select Add, than Rename.
OpenSim_Plot_window.PNG
OpenSim_Plot_window.PNG (81.86 KiB) Viewed 1600 times

I am assuming this process is replicable in Python, and while I have some parts individually working, I am struggling to put it all together (loading in the .mot files in particular). I have tested the example codes to ensure Python OpenSim is installed correctly, everything seems to be working fine.

Any help or guidance would be really appreciated, I have tried going through the documentation and working back from the examples but I am struggling to find exactly what I need.

For Context, previously my team completed this analysis manually in the GUI, one by one, but I am trying to connect to the other processes that utilise python so I can speed everything up.

Tags:

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Python Plotting Total Fiber Force

Post by Thomas Uchida » Wed May 29, 2024 12:53 pm

You can run a MuscleAnalysis in the GUI or in Python (https://opensimconfluence.atlassian.net ... lysis+Tool, https://simtk.org/api_docs/opensim/api_ ... lysis.html) which will generate a file containing the fiber force for each muscle over time. You can then read in this file and compute the sum for each time point.

User avatar
John Kounetas
Posts: 2
Joined: Tue Mar 26, 2024 5:44 pm

Re: Python Plotting Total Fiber Force

Post by John Kounetas » Wed Jun 26, 2024 11:33 pm

Hi Thomas and OpenSim Community,

Thank you for the reply. I have manged to make some progress with the workfow using the GUI Scripting environment. As I just need the Total Fiber Force plots, I am trying to use the function "addMotionCurve" but I am struggling to use it for more than one muscle.

For Example, addMotionCurve(plotterPanel, 'FiberForce', "TRIlong_l", motSrc) will plot but addMotionCurve(plotterPanel, 'FiberForce', "TRIlong_l+TRIlong_r", motSrc) results in an error. In the GUI Plotting window, I can select the all the muscles, and then hit "sum only".

Is there an equivalence for GUI Scripting? I have tried searching online, and have tried the GUI Scripting tutorials (tutorial 2 looks close, but isn't working) but to no avail. Any help on this issue would be really appreciated!

Best Regards,

John

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Python Plotting Total Fiber Force

Post by Thomas Uchida » Mon Jul 01, 2024 11:04 am

You could read through the gui repo on GitHub to dig up the syntax but I don't think it's straightforward. The "sum only" checkbox sets a flag that gets processed in JPlotterPanel.java (starting at line 1130, https://github.com/opensim-org/opensim- ... java#L1130) to assemble an instance of PlotCurveSettings which then gets passed to the rest of the plotting infrastructure. It may be easier to compute the sum yourself.

POST REPLY