Page 1 of 1

Analysis Tool computing normalised muscle fiber lengths

Posted: Wed Jun 15, 2022 8:04 am
by grevec
Dear OpenSim Team,

I am trying to compute normalised muscle fiber lengths with the AnalyzeTool in OpenSim GUI and Python. The problem I encountered is that the output is just a straight line at some value. It does happen with different models and interfaces (Python vs GUI). Is anybody else encountering the problem? The fiber length changes are fine.

Thanks and kind regards

Christian

Re: Analysis Tool computing normalised muscle fiber lengths

Posted: Wed Jun 15, 2022 4:47 pm
by nicos1993
Hey Christian,

What files are you inputting into the analysis tool and what is your simulation pipeline? If you have performed static optimization you can determine the normalized fibre length by subtracting the tendon slack length from the muscle tendon unit length and dividing by the muscle's optimum fibre length - due to the rigid tendon assumption. If you have performed Computed Muscle Control then I believe you should get an output file with the time histories of the normalised muscle fibre lengths - as they are included as state variables.

Hope that helps!

Nicos

Re: Analysis Tool computing normalised muscle fiber lengths

Posted: Thu Jun 16, 2022 1:11 am
by grevec
Hi Nicos,

thanks for your fast reply. I am using OpenSim Moco to compute muscle activations and excitations. I am using the output from the Moco solution as controls for the AnalyzeTool() + the coordinates. Maybe the code snipet below helps to clarify what I am doing.

Code: Select all

solution = osim.MocoTrajectory(Controls_Filename)
coordinates = osim.Storage(Coordinates_Filename)
osim.STOFileAdapter.write(solution.exportToControlsTable(),os.path.join(Path,"MocoInverse_controls.sto"))
ControlsFile = os.path.join(Path, 'MocoInverse_controls.sto')
setUpFile = os.path.join(Path,'subject01_Setup_Analyze_generic.xml')
analyzeTool = osim.AnalyzeTool(setUpFile,False)
model = osim.Model(Scaled_modelFileName)
model.initSystem()

AnalysisResultsFolder = os.path.join(Path,"AnalysisResults")
if not os.path.exists(AnalysisResultsFolder):
    os.mkdir(AnalysisResultsFolder)

initial_time = coordinates.getFirstTime()
final_time = coordinates.getLastTime()

myState = model.initSystem()
# model = getCurrentModel()
analyzeTool.setModel(model)
analyzeTool.setName('MocoAnalysis')
analyzeTool.setResultsDir(AnalysisResultsFolder)
analyzeTool.setCoordinatesFileName(Coordinates_Filename)
analyzeTool.setControlsFileName("MocoInverse_controls.sto")
analyzeTool.setInitialTime(initial_time);
analyzeTool.setFinalTime(final_time); 
analyzeTool.updAnalysisSet().cloneAndAppend(osim.MuscleAnalysis())
analyzeTool.setStatesFromMotion(myState,coordinates,True)
analyzeTool.run()

Re: Analysis Tool computing normalised muscle fiber lengths

Posted: Thu Jun 16, 2022 10:46 am
by nicos1993
You should be able to extract the normalised muscle fibre lengths without having to use the Analyze tool due to using Moco - you can access them after solving a problem. This code snippet should provide some insight into doing so:

mySolution = study.solve(); % Solve your problem
outputPaths = StdVectorString();
outputPaths.add('.*fiber_length');
outputTable = study.analyze(mySolution,outputPaths);
opensimMoco,writeTableToFile(outputTable,'yourFile.sto');

If it doesn't help then posting your question on the Moco forum should definitely help (Limited experience with using Moco).

Thanks,

Nicos

Re: Analysis Tool computing normalised muscle fiber lengths

Posted: Sat Apr 01, 2023 6:40 am
by sjk123
Hi,Nicos!
In the matlab moco simulation, I use the following code to extract the target result information.


gaitTrackingSolution = study.solve();
outputs = StdVectorString();
outputs.add('/jointset/groundPelvis/pelvis_tilt/value');
table = study.analyze(gaitTrackingSolution,outputs);

However, the desired results cannot be obtained, and the following warning prompts are provided:

"Warning: No outputs were connected to 'reporter' of type TableReporter__double_. You can connect outputs by calling addToReport()."

Could you help me? Or give me some inspiration.
Thank you very much!

Song Jingke

Re: Analysis Tool computing normalised muscle fiber lengths

Posted: Sat Apr 01, 2023 8:12 pm
by sjk123
OK, I have found the cause of the problem.