How to build blocks of trials from multiple excel files

OS (Win10):
PsychoPy version (e.g. 1.85.6):
Standard Standalone
What are you trying to achieve?:

I’m building a fluid intelligence task similar to the Ravens Progressive Matrices. A key difference is that stimuli are presented semi-randomly – we want to minimize the training effects from trial to trial. I have 60 unique matrices across three difficulties (easy, standard, and advanced), the filepaths for each class of matrices are stored in an excel file. At the start of the flow I want to build 10 blocks of six matrices that feature two problems of each difficulty, such that each participant will be exposed to a different, psuedo-randomized set of blocks.

What did you try to make it work?:

It seems like this is definitely doable, and relatively easy, but I’ve had little success trying to piece together the code I need and where to run it. I’m very new with python and psychopy, but happy to learn more.

Initially I tried using a nested loop, one for the trials, and one for selecting a difficulty. This ran correctly, but didn’t have the desired outcome. The entire set of 20 trials would be presented after selecting a difficulty. If I could set this loop up to select only one trial at random before repeating the loop, while recalling which stimuli have been used, that would be perfect! However, I was only able to take one step towards this goal.

///if trials.thisN == 0: # i.e. trial 0 has been completed
/// trials.finished = True # end the loop early
This is very close to what I want, but has the problem of potentially resampling stimuli multiple times. If I can work around that issue, this solution is fully sufficient.

Then I created a more brute force version. I set up 10 blocks by hand, and replaced the difficulty selection loop with block selection. This works great and achieves a very similar effect, but locks the total number of possible presentations to somewhere in the low billions. Not bad, but I was really trying for more.

What specifically went wrong when you tried that?:

Psychopy builder is working as intended. I think I could figure it out if some of the steps had a youtube video associated with them – it’s kinda hard for me to read a page of code and “get it” at this point, but the gestalt ideas are usually salient enough that I can figure them out if someone shows me an easy one, then lets me play with it.

Here are the steps I think I need, but am not sure how to implement. Please correct me if I’m wrong or using incorrect/imprecise terminology:

  1. At the start of the flow, create 10 excel files named block1-10.
  2. Load in the difficulty sheets from excel (3 files, each with 20 stimuli, answers, and corAns)
  3. Shuffle all rows in the difficulty sheets – I have a question here. The difficulty sheets have stimulus (a .jpg), multiple choice options for that stimulus (also a .jpg), and the correct answer stored in three consecutive columns. If I shuffle all rows, will the pairings for stimulus-answers-corAns be maintained?
  4. Select 0:1 from each difficulty, put them in block1, then loop this process for 2:3, 4:5, etc, until all 10 sheets are filled with 6 different items, 2 from each difficulty.
  5. Present all 10 blocks in sequential order, without replacement. (This one is easy if everything else is in order, but clarifies my desired endstate).

Thank you very much for your time and energy. I hope we are able to help each other out!

Hi @asakoda121, did you ever find a solution to this?

I believe I have a similar problem.

What am I trying to achieve?
My trial blocks are drawn from 5 different excel files. Within each file are three identical conditions, $location, $scene and $corrAns.
I want to loop through these files in a random order. The outcome should resemble 5 blocks of trials, one from each excel file.

What did I try to make it work?
Two nested loops around the trial block.
The outer loop names conditions from a file $path which contains the 5 file paths.
The inner loop names the three conditions from each trial block, $location, $scene and $corrAns.

What went wrong?
The error message reads:
ValueError: Conditions file not found: C:\Users\name-a\Desktop\Spatial N Back\WM training\Stimuli\Nback_stimuli\scene, $location, $corrAns

How can I get these two nested loops to ‘talk’ to each other, such that the inner loop will recognize variables presented from the paths in the outer loop?


Replying to my own thread to say that I solved this. Super easy fix I came to by checking my task against the RandomiseBlocks.psy demo – happy to help anyone else with a related problem!