Very different results between Inverse Dynamics GUI vs Python code

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
giovanni pestrichella
Posts: 4
Joined: Wed Sep 27, 2023 3:15 am

Very different results between Inverse Dynamics GUI vs Python code

Post by giovanni pestrichella » Fri Apr 26, 2024 1:58 pm

Hello! I am using this basic function to perform Inverse Dynamics: def run_inverse_dynamics(grf_xml_path, ik_mot_path, output_folder):
# Carica il modello
model = osim.Model(r"C:\Users\acer\Desktop\THESIS_GIOVANNI\Gait2354_Simbody\subject01_simbody.osim") # Assicurati di aggiungere il percorso al tuo modello OpenSim
model.initSystem()


# Configura l'analisi di Inverse Dynamics
idTool = osim.InverseDynamicsTool()
idTool.setModel(model)
idTool.setExternalLoadsFileName(grf_xml_path)
idTool.setCoordinatesFileName(ik_mot_path)
idTool.setOutputGenForceFileName("inverse_dynamics_prova.sto")
idTool.setResultsDir(output_folder).


# Esegui l'Inverse Dynamics
idTool.run()

# Percorsi ai file di input
grf_xml_path = r"C:\Users\acer\Desktop\THESIS_GIOVANNI\Gait2354_Simbody\subject01_walk1_grf.xml"
ik_mot_path = r"C:\Users\acer\Desktop\THESIS_GIOVANNI\Gait2354_Simbody\subject01_walk1_ik.mot"
output_folder = r"C:\Users\acer\Desktop\THESIS_GIOVANNI\Gait2354_Simbody\ResultsIDON"

# Esegui la funzione
run_inverse_dynamics(grf_xml_path, ik_mot_path, output_folder)

If I put the same files into the GUI, I get the first 5 more or less and the last 5/6 columns very very similar, but the other very different values. Can someone help me? It is for my master thesis, I would be very glad.

Giovanni

User avatar
Mohammadreza Rezaie
Posts: 354
Joined: Fri Nov 24, 2017 12:48 am

Re: Very different results between Inverse Dynamics GUI vs Python code

Post by Mohammadreza Rezaie » Sat Apr 27, 2024 1:31 am

Hi, similar to the setup file generated by ID tool in GUI, you need to exclude muscles:

Code: Select all

exclude = osim.ArrayStr()
exclude.append('Muscles')
idTool.setExcludedForces(exclude)
You may also want to apply filter and crop the time stamp:

Code: Select all

idTool.setLowpassCutoffFrequency(6)

IKData = osim.Storage(ik_mot_path)
idTool.setStartTime(IKData.getFirstTime())
idTool.setEndTime(IKData.getLastTime())
Hope these help.

User avatar
giovanni pestrichella
Posts: 4
Joined: Wed Sep 27, 2023 3:15 am

Re: Very different results between Inverse Dynamics GUI vs Python code

Post by giovanni pestrichella » Sat Apr 27, 2024 5:00 am

So do you mean that to get the same results using python and using the GUI, I have exclude forces in my python code even if I am using exactly the same setup file ID and the same motion file?

And another question, the filter that I could applied filters the motion files or the grf data (or both)?

User avatar
Mohammadreza Rezaie
Posts: 354
Joined: Fri Nov 24, 2017 12:48 am

Re: Very different results between Inverse Dynamics GUI vs Python code

Post by Mohammadreza Rezaie » Mon Apr 29, 2024 1:02 am

So do you mean that to get the same results using python and using the GUI, I have exclude forces in my python code even if I am using exactly the same setup file ID and the same motion file?
Hi, to get identical results, you need identical setup files. You can use either of these to see what is happening inside the tool:

Code: Select all

print(idTool.dump())
idTool.printToXML('test.xml')
And another question, the filter that I could applied filters the motion files or the grf data (or both)?
As its description says, it would be applied to your motion file only.
"Low-pass cut-off frequency for filtering the coordinates_file data"

POST REPLY