| Reference | Downloads | Github

Dynamically select parameters

Hi all,

Running Psychopy 1.85 on a Mac OSX10.11.6 and have what seems like a fairly simple problem but haven’t been able to quite sort it out.

Problem: I have a conditions.xlsx file with 90 different parameters (i.e. columns, p1,p2,p3,…). This parameter specifies the durations for a particular stimulus. I only want one of these parameters to be chosen when I run the experiment.

Solution: An extremely overwrought solution would be to create a separate excel file containing each parameter, and then create a new conditions file that contains all those filenames, and then dynamically select one row for that experiment, but since I have about 90 parameters, I feel like there should just be a way to choose which parameter is run when I run the experiment. However, I cannot determine how to select a specific parameter (I tried indexing paramName, and also trialList, but neither allowed me to select just one parameter).

Any advice appreciated!

Hi Marty, this doesn’t sound quite right. Can you describe what you mean by:

This seems contradictory. Do you actually mean you just have one parameter (the duration for a particular stimulus), which has 90 values?

How do they vary? i.e. do you just have a single trial, which can contain just one of 90 possible values, or 90 trials, with one value each? We really need a proper description of this to help you out. Think what would be required for a Methods section of a journal article.

Hi Michael,

Sorry, here’s some more detail: I’m using the term “parameter” to describe the variables that are assigned when creating an experiment loop using the handler. More specifically, I have an excel file that contains 90 separate columns, each one with its own name. Within each column are 6 values; those values are being used in the experiment hander to determine the duration that a particular stimulus lasts (so, in a single run through the loop, there will be 6 trials, and I can repeat that loop X number of times).

What I want is to be able to start my experiment, and then specify which of the 90 columns that I want to be used for that experiment (ignoring the other 89). Entering a number at the start and using it to select the name of the parameter is easy, but when it comes time for me to tell the experiment handler “use this parameter” it falls apart.

You could use Python’s eval() function to evaluate a string into a variable name. e.g. you could put this in the duration field of a stimulus:


But nonetheless, you might want to re-think this design. Remember, all 90 columns will appear in your data file, even if only one of them is actually used. And the relevant column in the data file will be different for each subject, complicating your analysis process quite a bit.

There are alternative approaches:

  • Simply have one large conditions file with 540 rows (90 × 6), but in the loop dialog, you restrict it to a particular set of 6 rows. Those row numbers could be entered in the info dialog.
  • Have 90 separate conditions files of 6 rows, with the name of the file entered in the info dialog.
  • Use a code component to generate the set of durations for each subject, based upon some values specified in the info dialog.

Thanks! Eval worked quite easily. I had thought about trying this, but didn’t think it would work in this instance. Now that it’s working, I’ll likely find a way to streamline this into something more efficient. Appreciate the help :slight_smile: