Batch Processing Scaling in MATLAB

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Koen Flores
Posts: 2
Joined: Fri Dec 15, 2017 11:12 am

Batch Processing Scaling in MATLAB

Post by Koen Flores » Mon Jul 23, 2018 8:40 am

I am trying to batch process scaling in MATLAB, but I have not been able to get the .run() function to work. After looking at the python code provided by Opensim in the scripting folder (runScaling.py) I saw that the code to run the scale tool was quite different (scaleTool.getModelScaler().processModel(myState,myModel,path2subject,subjectMass);). I know that the IK and FD tool both utilized the .run() in MATLAB but I am less sure about the scale tool. Is there a MATLAB equivalent method to the python scale tool running above or known solutions to the error with the .run()? Thank you for the help.

Tags:

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Batch Processing Scaling in MATLAB

Post by jimmy d » Mon Jul 23, 2018 8:48 am

Unfortunately, no. If you want to do scaling through scripting, you have to run ModelScaler() and MarkerPlacer() as separate processes. The example code given in runScaling.py is the framework you will have to use for now. We hope to have a single ScaleTool.run() method in future releases.

User avatar
Koen Flores
Posts: 2
Joined: Fri Dec 15, 2017 11:12 am

Re: Batch Processing Scaling in MATLAB

Post by Koen Flores » Wed Jul 25, 2018 9:08 am

Thank you, but I have been using the runScaling.py as a guide and only been lucky with creating a new xml file titled 'Unassigned'. What I am confused about is the relationship between the ScaleTool and ModelScaler within the code now that I have to run ModelScaler separately. Is there a simple scaleTool.ModelScaler.run()? Thanks once again.

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Batch Processing Scaling in MATLAB

Post by jimmy d » Wed Jul 25, 2018 9:24 am

The Tools (ScaleTool, InverseKinematicsTool, etc) were initially designed to be used by OpenSim GUI, exclusively. Because of this, their use in scripting (Matlab, Python, Jython) is not perfect. If you look at the documentation for the ScaleTool class, ModelScaler() and MarkerPlacer() are packaged as separate processes. When you run the ScaleTool through the GUI, the GUI will run these parts for you behind the scenes, but when you are trying to use the Tool through scripting, you have to run them separately (both ModelScaler() and MarkerPlacer() have a .processModel() method).

In OpenSim 4.0, we have made this easier by adding a .run() method on the ScaleTool. However, if you are running OpenSim 3.3, you will have to perform the operations as they are written out in the example script.

User avatar
Monica Armengol
Posts: 8
Joined: Fri Oct 07, 2016 1:58 am

Re: Batch Processing Scaling in MATLAB

Post by Monica Armengol » Sun Aug 05, 2018 9:43 am

Hi James,

I too am trying to run a scale through matlab. I have managed to get an scaled.osim model, but it doesn't really update the mass to what I am putting in, instead it updates it to the "generic file" data. I can't figure out where it's reading this from. this is part of the code I'm using:

Code: Select all

   import org.opensim.modeling.*
   
   scaleTool = ScaleTool(path.generic_scale_Setup)

    model = Model(path.model_file);
    model.initSystem();
    state = model.initSystem();
    
     scaleTool.setSubjectMass(subject.mass);
    scaleTool.setSubjectHeight(subject.height);
    scaleTool.setSubjectAge(subject.age);
    scaleTool.getModelScaler().setApply(true);
    scaleTool.getModelScaler().setMarkerFileName(path.static_external_MarkerName);
    scaleTool.getModelScaler().setTimeRange(TimeArray);
    scaleTool.getModelScaler().setPreserveMassDist(true);
    scaleTool.getModelScaler().setPrintResultFiles(true);
    scaleTool.getModelScaler().setOutputModelFileName(path.scaled_model);
    scaleTool.getModelScaler().setOutputScaleFileName(path.scale_Set);

   path2subject = scaleTool.getPathToSubject();

    scaleTool.getModelScaler().processModel(state,model,path2subject,subject.mass);
    state = model.initSystem();

    model.print(path.scaled_model);   

Do you know what I'm missing?.

Thank you

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Batch Processing Scaling in MATLAB

Post by jimmy d » Sun Aug 05, 2018 10:17 am

but it doesn't really update the mass to what I am putting in, instead it updates it to the "generic file" data.
What is the original mass of the model, your input mass, and the actual mass of the scaled model? What is "generic file" data?

POST REPLY