Make the pictures in the condition file individually random

Hello, I want to randomize the images without repeating them.

My condition file is as follows:

Each loop randomly selects any line in the condition file.
I want the other four variables to be matched by line, and only the picture variable is not matched by line, that is, the “emopic” is randomly assigned individually.

My code component is as follows:
import random
import pandas as pd
import csv

f = pd.read_excel(‘trials_condition.xlsx’)

Emopic = list(emopic) # convert the tuple to a list to make it editable
header = Emopic.pop(0) # remove the header item
shuffle(Emopic) # randomise the actual values
Emopic.insert(0, header) # restore the header at the top

thisExp.addData(‘Emopic’, Emopic)

But the data saved in the csv file is like this, not the images’ name.
[‘e’, ‘i’, ‘0’, ‘m’, ‘j’, ‘/’, ‘e’, ‘5’, ‘_’, ‘.’, ‘m’, ‘0’, ‘0’, ‘p’, ‘o’, ‘8’, ‘0’, ‘g’, ‘g’, ‘a’]

How can I modify it?
Looking forward to your reply. Thank you.

Hi There,

I would suggest using Builder + code snippets to do this.

  1. Make a spreadsheet that has 4 columns (one for each of your 4 “set” variables"
  2. Add a code component that lists your images e.g. `imgs = [“im1.jpg”, “im2.jpg”, “im3.jpg”]
  3. In your routine where the image is presented, add a code component and in the Begin Routine tab use:
thisIm = imgs[-1]
thisExp.addData('thisIm', thisIm)
  1. in your image component use $thisIm and "set every repeat

Hope this helps,

1 Like