Randomly choose different .csv file per routine iteration

OS (e.g. Win10): 10
PsychoPy version (e.g. 1.84.x): 3.0.5
Standard Standalone? (y/n) : yes

What are you trying to achieve?:
I have an experiment with 4 different routines. Each routine is controlled by a different .csv file, and the order of routines is random. While the set-up I have now worked for our initial purpose, my supervisor has requested a slight change to the experiment that I cannot seem to implement.
Initially, there were 4 routines. Each routine would be randomly selected, and then run 2 times before moving to the next one. Here’s what I did to make this work: First I put an outer loop around the entire experiment. This loop has 1 repetition, has loopType random, and the condition file looks like this:

Routine 1       Routine 2      Routine 3        Routine 4
2               0              0                0
0               2              0                0
0               0              2                0
0               0              0                2

Each separate routine has it’s own inner loop as well, which is set to random, and has $nReps set to a specific routine as listed above (so the first routine would have $nReps: Routine 1, the second routine would have $nReps: Routine 2, and so on).
There is then a final trial specific loop around the part of each routine with the trial structure. This loop is set to random, has $nRep of 1, and draws from the specific condition file associated with it.
This setup works well for what we wanted. It randomly selects 1 of the 4 routines, runs the routine 2 times, and then randomly selects the next routine and continues until the end.
However, we have changed the experiment slightly. When each routine runs, we now have 10 different condition files with a pre-specified order of stimuli. The routine therefore needs to run through the .csv condition file sequentially. While this is easy enough to do, we also want the routine to randomly select 1 of the 10 .csv condition files, run through it sequentially, randomly select one of the other .csv condition files, run through it sequentially as well, and then move on to the next routine and repeat this procedure.
I am including an image of the structure of the experiment in case that helps.

To make things a bit more clear with the image, the Outerloop controls randomization of the innerloops. There are 4 innerloops, each controlling the flow of 1 of the 4 routines (innerloop_3 is displayed in the image). During each routine, participants read the Instructions, wait 5 seconds, and then run through each trail of the routine (governed by the OlfactoryStimuliLoop in the image for example). They wait, and then run through this a second time before randomly moving to the next routine. I want the .csv file used as the condition file for the OlfactoryStimuliLoop to be randomly chosen from 1 of 10 .csv files. When the Routine loops around a second time, a different .csv file would be chosen for the OlfactoryStimuliLoop condition file.
Thank you,
Stephen

1 Like

Hi @Steve_Pierzchajlo, in your new version, you want to run through two conditions files for a routine. Does that mean nReps for that loop should be 1? If nReps is 2 for your loop, you will present both files twice.

Here is one way, simplified. You have your outer loop controlling the nReps of the inner loop. In the outerloop, there is a code component that creates a list of conditions files, and shuffles them for randomization. In the same code, you set a counter. The counter indexes the conditions files for the inner loop. The counter is incremented at the end of the inner loop. The trials within the loop are presented sequentially.

Here is an example (RC = routineControl):

RC.xlsx (7.8 KB)
A.xlsx (7.8 KB)
B.xlsx (7.8 KB)
RC.psyexp (8.0 KB)

Thank you for the reply. I changed my experiment based on your recommendations, and indeed it did work. Now, each routine runs two times, and grabs a random .csv file from a list in my directory.
I do have one final question. The example you provided works well for 1 routine. However, in my experiment I have 4 routines, and each routine uses a different procedure, and therefore, a different list of .csv files. How can I adapt what you have provided so that there are 4 routines that are randomly chosen.
For example, right now I have routine 1, routine 2, routine 3, and routine 4. Each routine uses the setup from your example, but their presentation right now is sequential. I think I would need to add another big outer loop around the 4 routines that can randomly assign an order for each participant, but I cannot figure out how to do that.

Interesting problem! I think this is what you are after. Here is what this example does

The outerloop (routineController) has a column for each routine which controls whether to present a routine, and for how many repetitions. The order of routine presentation is random, and currently runs for 5 repetitions (so 5 reps * 4 lists * 4 trials, each presented once = 80 trials)

The intermediate loops routineOne and routineTwo are the loops controlled directly by the routineController loop, as their nReps are defined by the routineController loop.

If the intermediate loops allow routine presentation, then the presentation of the list of conditions files begins. There are now two sets of lists, setOne and setTwo for their respective routines (you may only want one set of conditions files, and that is easily changed by removing the setTwo list and changing path to the conditions file in the innerTwo routine). On every iteration of the outer routineController, the condition list order is randomized, so that on every iteration, the list of conditions files are random. Each condition list is then presented sequentially. The current counter is reset when > 1, because there are only two items per list - without this, you would get an index error.

My last run, I had the following order of conditions:

CDBA
CDBA
DCAB
BACD
CDBA

A.xlsx (7.8 KB)
B.xlsx (7.8 KB)
C.xlsx (7.8 KB)
D.xlsx (7.8 KB)
RC.psyexp (11.8 KB)
RC.xlsx (7.8 KB)

Many thanks dvbridges. This now works exactly as I had hoped. I have 4 routines that are randomly chosen, and each routine is repeated a second time. Additionally, each routine randomly chooses from a list of .csv files. Thanks again for all your help!

1 Like