psychopy.org | Reference | Downloads | Github

Shuffle stimuli within routine

If this template helps then use it. If not then just delete and start from scratch.

OS: Win10
PsychoPy version: 1.78.00
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I am trying to create a block-design experiment for fMRI.
There are 8 conditions, and each condition is supposed to repeat 4 times, thus resulting in a total of 32 blocks. The order of block presentation is pre-determined. Each block contains the same 5 pictures, whose presentation I want to shuffle within block.
What did you try to make it work?:
Initially I tried creating nested loops but it got too complicated. Realizing that there is a small amount of blocks (32) and a fixed order, I decided to create only one condition file in which each row represents a block. So, the condition’s .xlsx looks like this:

blockType Pic 1 Pic 2 Pic 3 Pic 4 Pic 5
a.png Pic 1.png Pic 2.png Pic 3.png Pic 4.png Pic 5.png
b.png Pic 6.png Pic 7.png Pic 8.png Pic 9 .png Pic 10.png

Currently this is set up in one routine. An image describing the block type is presented for 2.5 seconds, followed by the 5 pictures which are presented for 3 seconds (i.e. pic 1 for 3s, followed by pic 2 for 3s etc.). The loop type is sequential, as the " blocks’ " order is fixed.
Now, I wish to shuffle the presentation of pictures within each “block” (i.e. routine), e.g.:

blockType Pic 1 Pic 2 Pic 3 Pic 4 Pic 5
a.png Pic 2.png Pic 5.png Pic 3.png Pic 1.png Pic 4.png
b.png Pic 10.png Pic 8.png Pic 6.png Pic 9 .png Pic 7.png

Additionally, a key-response is presented simultaneously with each picture, as participants are required to rate the pictures.

What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

Stop fighting it and go back to having nested loops. That way you can separate out the sequential and randomised factors as required instead of trying to somehow meld them together. It might seem complicated but, although there is a way of achieving what you are trying to do currently, it will actually be much more complicated than working with Builder’s provided loop facilities.

Your outer loop conditions file will look like this:

blockType  conditionFile
a.png      pic_1-5.csv
b.png      pic_6-10.csv

pic_1-5.csv will look like this:

imageName
Pic_1.png
Pic_2.png 
Pic_3.png
Pic_4.png
Pic_5.png 

and similarly for pic_6-10.csv

You need two routines. The first will show just the block type image, using the $blockType variable from the outer loop. The outer loop is set to be sequential.

The second routine also has just one image component, controlled by the $imageName variable from the inner loop. The inner loop encompasses just this second routine and is set to be random. The name of the conditions file is the $conditionFile variable from the outer loop.

So for every iteration of the outer loop, the first routine will be shown once, displaying either a.png or b.png, and the second routine will run five times, showing the randomly assigned images from either set.

1 Like

Works perfectly. Thanks!

@Michael

How would you do this same thing but with video files?

Is that possible to connect to a html that would run the video?

Exactly the same, but use video file names.

You really want to control the start/stop of the video yourself, so no, you should get access to a video file and play it within the PsychoPy window, which also avoids all the hassle of switching active windows to another application and then somehow getting back to PsychoPy.

Ok. I used a randomized blocking however, my computer is not connecting the mp4 file from my excel document to connect with the actual video. Any advice.
I’ll attach screenshots.

  • What does “my computer is not connecting the mp4 file from my excel document to connect with the actual video” mean? Do you have an error message to share?
  • You probably need to organise things so they are all in one place. For example, it looks like your outer loop’s conditions file is not in the same folder as your Builder .psyexp file.
  • Where is the inner loop conditions file? With no path specified, PsychoPy will look for it in the experiment folder.
  • The paths to the videos are defined relative to the Builder .psyexp file. Again, your conditions file just contains bare filenames, so PsychoPy expects them to be right there next to the .psyexp file. If you want to tidy them away, then prepend each name with something like movies/ and make a movies sub-folder there.
  • I guess you want to have blocks of files, but for some reason you have just a single conditions file referred to in your outer loop. This arrangement doesn’t do anything for you: this is exactly equivalent to only having the inner loop. The blocking ability comes from having the outer loop switch between multiple conditions files for the inner loop to use. For that, it’s conditions file needs to have more than one row of file names, and there need to be multiple corresponding files available to use for the inner loop.

How do I create a path for my conditions folder? For example, how do I create a place to organize things to be placed all in one place?

Basically, I have 48 video clips that I want to be shown in a random order for each participant.

As above, PsychoPy can use relative paths (ones that don’t start from the top of your hard drive). They are relative to the location of your .psyexp file. So if your conditions file is in exactly the same folder as your .psyexp file, you don’t need any path elements, as the .xlsx filename alone will be sufficient to locate it.

If you have subfolders (e.g. to tidy away your videos), make them subfolders of the folder where your .psyexp is. And then refer to a given video like this videos/some_video.mp4

Note that relative paths don’t start with a /, they begin directly with the name of the sub-folder.

Lastly, use / forward slashes rather than Windows-style \ back slashes, as back slashes occasionally do special things in programming languages (that long predate Windows using them for path separators).

I am still confused. What will my loops look like and what will my excel sheets be?

Additionally, in my trials routine, do I need to attach a movie stimuli with conditions?

@Michael
where do I insert the conditions file and where do I insert the variable?

You really need to watch Jon Peirce’s Youtube video on implementing the Stroop task in PsychoPy, to get a basic understanding of how the software is used…