Location Randomization

OS (e.g. Win10): macOS 12.4
PsychoPy version (e.g. 1.84.x): v.2022.2.4
Standard Standalone? (y/n) If not then what?:

What are you trying to achieve?:
I would like to randomise the locations of two stimuli. I want to simultaneously present two pictures of two categories (exercise vs inactive pictures). I could successfully randomise the order of the stimuli in the two categories with code and an excel conditions file:

image

What did you try to make it work?:

I want to randomise the location of the stimuli of the two categories, where I always want one exe(rcise) image combined with an ina(active) image, but the exercise image should be presented randomly on the left or the right location and the inactive image on the other side.

What specifically went wrong when you tried that?:

This is the code I used for the randomisation of stimuli at ‘Begin experiment’:

import random, xlrd
random.seed()

in_file = "stimulus_sheet2.xls"

#number of items to load
num_items = 10

#counters to hold the next stimulus reference
cur_exe = 0
cur_ina = 0

‘Begin routine’:

inbook = xlrd.open_workbook(in_file)
insheet = inbook.sheet_by_index(0)

#arrays to hold our stimuli
exe_stim = []
ina_stim = []

#loop thorugh the rows in the stimulus file
for rowx in range(1,num_items+1):
    
    #read in an entire row
    row = insheet.row_values(rowx)
    
    #save exe and ina
    exe_stim.append(row[0]) 
    ina_stim.append(row[1]) 


random.shuffle(exe_stim)
random.shuffle(ina_stim)

As I am pretty new to PsychoPy other forum entries to randomisation of locations did not help because I either did not how to apply the suggested code or it did not fit my problem.

Any help is highly appreciated!
Thank you!

Hi @sinika,

you could add

Begin experiment

positions = [(-.5,0),(.5,0)] # these are the two locations were images will be presented.

Begin routine

random.shuffle(positions)

and then use $positions[0] for the position of one image and $positions[1] for the other one.

Perfect! Thank you for your fast reply!
Adding

thisExp.addData('position_0', positions[0][0])
thisExp.addData('position_1', positions[1][0])

to the End of the Routine helped to trace back which stimuli was placed on which location.

1 Like