Individual output text files for parameterstudy run with AnyPyTool

Dear all

I am running a series of Anybody simulations using python and a list of parameters as the input.
The simulations run perfectly.
Previously, when I was still manually changing the parameter, I defined an output file with the variables that I am interested in analyzing.
Is it possible to change the name of the output file during each loop automatically using python such that the output file is not overwritten with every simulation loop?
This would be great as I have already streamlined my analysis and plotting based on the defined structure of the output file.

Thank you and best regards
Johanna

Hi Johanna,

This should be possible,

Please see this link for inspiration https://anybody-research-group.github.io/anypytools-docs/Tutorial/06_Tips%26Tricks.html

Note that NSTEP is a define and sent into the AnyBody model using Python.

You will need to define a filename in the same manner and in AnyBody you then use the filename to construct the name of the file.

Hope it helps

Best regards
Søren

Hi Johanna,

If you are using one of the new versions of the AnyMocap model, then it has a define statement prepared to append to the output file name: MOCAP_OUTPUT_FILENAME_PREFIX This you can define from Python.

Best regards
Michael Skipper Andersen
Associate Professor
Aalborg University

Thank you Søren and Skipper!

Your hints helped me to solve it. I am using the freeposture model, though.
In the end, I automatically changed the output file name per simulation based on the variable that I change in python:

 AnyStringVar file_ID = strval(Main.HumanModel.BodyModel.Right.ShoulderArm.Seg.Scapula.GHReactionCenterNodeRotated.GI, "%03.0f");

  AnyOutputFile OutputData = {
    FileName = "210114_25N_"+..Motion +"_GI" +.file_ID + "degY.txt";

While I am trying to automize and streamline things I wanted to do one more thing:
Passing a string variable (Motion) to my simulation and using it in the variable world as well as hashtag world :slight_smile:
like this:

//__________ Define Motion ________________________

// AnyStringVar Motion = "Abduction" ;
// AnyStringVar Motion = "Flexion" ;
// AnyStringVar Motion = "IntRotation" ;
AnyStringVar Motion = "ExtRotation" ;
//___________________________________________________________

#include "Model/Environment_" +Motion +".any"
#path BM_MANNEQUIN_FILE "Model/MannequinInterpolation_" +Motion +".any"

AnyOutputFile OutputData = {
FileName = "210114_25N_"+..Motion +"_GI" +.file_ID + "degY.txt";

I realized you cannot just pass a string to both worlds like this. But do you know how this could be accomplished? Would be cool, as I could pass the string then through python and could automate the step of initiating the various motions as well.

Thank you and best regards
Johanna

Hi Johanna,

What about just passing another define MOTION to AnyBody defining which motion it is.
Then in the code do something in this line:

Main ={
  #ifndef 
  #define MOTION "Abduction"
  #endif
  
  #if MOTION == "Abduction"
    AnyStringVar Motion = "Abduction" ;
  #endif
  #if MOTION== "Flexionvvv"
    AnyStringVar Motion = "Flexion" ;
  #endif
  #if MOTION== "IntRotation"
    AnyStringVar Motion = "IntRotation" ;
  #endif
  
  #if MOTION== "ExtRotation"
    AnyStringVar Motion = "ExtRotation" ;
  #endif
  
};

Best regards
Søren

Oh, great idea!

Thanks a lot Søren :slight_smile:

Best,
Johanna

Hi Johanna and Søren

I think you can simplify even further and eliminate the if statements:

AnyString Motion = MOTION;

Should work but I did not test it.

Best regards
Michael

Thank you for your tipps!

The comment: AnyString Motion = MOTION; workded for my #paths statement, however, not for my #include statement

#path BM_MANNEQUIN_FILE "Model/MannequinInterpolation_" +MOTION +".any"
#include "Model/Environment_" +MOTION +".any"

So for the #include statement, I solved it using the if-loops as proposed.

#if MOTION == "Abduction"
#include "Model/Environment_Abduction.any"
#endif

#if MOTION == "Flexion"
#include "Model/Environment_Flexion.any"  
#endif

#if MOTION == "IntRotation"
#include "Model/Environment_IntRotation.any"
#endif

#if MOTION == "ExtRotation"
#include "Model/Environment_ExtRotation.any"  
#endif

Thank you again!

Best,
Johanna

Hi Johanna!

I think it is just a little bit of syntax you need. I have made a small example to show how to do this.

Just change the define statement between "A" and "B" to include either file_A.any or file_B.any

Include demo.zip (771 Bytes)

Best regards
Michael

Thank youuu Michael!

Finally I got it and, besides,learned a lot about the Anybody Language :slight_smile:

Thank you and have a nice day!
Johanna

This topic was automatically closed 125 days after the last reply. New replies are no longer allowed.