Page 1 of 1

Moco analyze() function

Posted: Tue Aug 30, 2022 1:42 am
by grevec
Dear Moco users,

I am trying to perform muscle analysis on a Moco Solution in Python. First I used this code:

Code: Select all

solution = study.solve()
    outputs = osim.StdVectorString()
    outputs.append('.*active_force_length_multiplier')
    table = study.analyze(solution, outputs)


However, I received the error message that the speeds and values were not in the trajectory. Good point I thought and appended the speeds and values from a MovoInverse solution with some additional code:

Code: Select all

solution = study.solve()
    solution.insertStatesTrajectory(osim.TimeSeriesTable(MocoInverseSolutionFileName))
    outputs = osim.StdVectorString()
    outputs.append('.*active_force_length_multiplier')
    table = study.analyze(solution, outputs)
The error message I receive now is that 176 states which are in the solution are not in the model...these are for example: "/forceset/semiten_r".

I also tried the standard OpenSimAnalyze function which works but does not provide valid outputs (e.g. straight line for normalized muscle_lengths during a gait cycle).

So summarizing....I want to perform muscle analysis on a MocoStudy solution but have trouble to get the analyze() function running. Do you have any suggestions?

Thanks and kind regards

Christian

Re: Moco analyze() function

Posted: Tue Aug 30, 2022 11:02 am
by nbianco
Hi Christian,

This is a known issue with MocoInverse, since the problem prescribes kinematics, so all coordinate values and speeds are removed from the problem.

You almost had the right fix, but you accidentally inserted the entire MocoInverse solution into the states trajectory, rather than just the states.

Code: Select all

solutionWithKinematics = osim.MocoTrajectory(MocoInverseSolutionFileName)
statesTable = solutionWithKinematics.exportToStatesTable()

# The states table also includes muscle states, but since we leave the
# 'overwrite' argument false, this should work. 
solution.insertStatesTrajectory(statesTable)
-Nick

Re: Moco analyze() function

Posted: Wed Sep 07, 2022 6:49 am
by grevec
Thanks a lot Nick! That solved the problem....

Regards

Christian