Page 1 of 1

Batch Processing Scaling in MATLAB

Posted: Mon Jul 23, 2018 8:40 am
by koenflores21
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.

Re: Batch Processing Scaling in MATLAB

Posted: Mon Jul 23, 2018 8:48 am
by jimmy
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.

Re: Batch Processing Scaling in MATLAB

Posted: Wed Jul 25, 2018 9:08 am
by koenflores21
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.

Re: Batch Processing Scaling in MATLAB

Posted: Wed Jul 25, 2018 9:24 am
by jimmy
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.

Re: Batch Processing Scaling in MATLAB

Posted: Sun Aug 05, 2018 9:43 am
by moniquiu
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

Re: Batch Processing Scaling in MATLAB

Posted: Sun Aug 05, 2018 10:17 am
by jimmy
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?