Sequential and Random Selection at the same time

Thanks for this helpful code! I have successfully used it as a model to code up a very simple paradigm involving interleaved presentation of movies of two different conditions. I am wondering how you would suggest adapting this technique in order to keep information about a correct answer for the trial “with” the stimulus being displayed.

I am trying to code up a slightly more complex paradigm that uses an interleaved block design, in which for each block an instruction slide is presented, followed by two randomly-selected (without replacement) movies of the same experimental condition. A block can be either an imitation block or a control block. For both cases, participants press some buttons during the trial (which could be a correct or incorrect sequence). I have already got a working version of the experiment but the code I’ve used is extremely inelegant…basically it involves taking some initial input .csv files with movieFile, condition, and correctAnswer variables, shuffling and cutting those up, and generating a ton of temporary files that are called subsequently by another conditions file. It works, but it’s a total mess.

So, I’m wondering if there’s a way to use your method if I also need to keep certain information, like the correctAnswer variable, with the stimuli as I shuffle them.

Whenever you have this sort of requirement, what you want is a list of dictionaries. i.e. each dictionary keeps together the pieces of information you need for a trial, so you can shuffle the list itself while the individual dictionaries safely keep their values glued together.

This function will allow you to read in a .csv file, making each column name a dictionary key, and putting a row of values into each single dictionary so they stick together:

https://www.psychopy.org/api/data.html#importconditions

This is basically what PsychoPy’s TrialHandler class does. i.e. it provides a dictionary for each trial, containing all of the values needed for that trial, which it extracts from a conditions file.

Hey Michael,

Sorry to bring this up again, but the .pop function is not working.
Some images are being shown more than once. Do you know how to fix the code so once an image is shown once it does not appear anymore?

Thanks,
Evi

Some screenshots of the code and the excel file I am going through sequentially:

Hi,

The code is fine - once an entry is popped out of a list, it isn’t possible for it to be re-selected, as it is no longer in the list.

The issue is that you are creating your image lists in the “begin routine” tab. This means that the list is re-populated on every trial, so it doesn’t keep shrinking, and used entries re-appear. You need to put the creation of the lists in the “begin experiment” tab, so that it occurs only once per session. That way, on each trial you will pop an entry permanently from a list, and that list will keep getting smaller.

Lastly, you don’t need to specify full absolute paths to your images (i.e. with paths starting at /Users/evi…). Instead, use relative paths, i.e. relative to the folder your .psyexp file is in, which i guess is RDP.

i.e. image paths would look like 'Intact1/helmet.bmp' or 'Scrambled1/S_chocolate.bmp' etc (note that they don’t start with a / character. This makes things less likely to contain errors, but also makes your experiment portable (e.g. you could develop it on your personal computer and then easily copy it over to a lab PC without needing to change all of the paths, or even just shift it to a new folder on the same computer and it would still work).

Hi Michael,

Would this be possible even with multiple routines? I can just put the code at “begin experiment” for each routine and it won’t interfere? The routines are named differently but they use the same stimuli.

And yes I tried the file naming thing, but it was causing me issues. It says the image is not found everytime I use the shortcut without the /Users/desktop… part. So it only worked if I put the complete path in the name. It’s super annoying but it seems to be the only way I can make it work. If you have some helpful tips, that would be appreciated.

Thanks.

It seems to work, but gives me this error when it runs out of intact images.

Disregard this. It seems that there was a typo in one of the excel files. The experiment works! No repetition of images, I think!

Thanks again Michael.