If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): Win10 PsychoPy version (e.g. 1.84.x): 2022.2.5 Standard Standalone? (y/n) If not then what?: What are you trying to achieve?:
I am developing an incentivized facial emotion recognition task, and I want the subjects to see a pair of photos of people portraying different emotional expressions. For each trial, the face & the emotion will be the same, but in a different moment (gradient 50, 70 or 90). As you can see, I have 3 sets of images, that are disposed as 3 different columns in an .xlsx file. I want one of the image components to always be the gradient 50, and the other one of the pair has to be randomized between gradient 70 and gradient 90. Also, I want the images components to randomize in their position in the screen, that is, image component from gradient 50 to be sometimes in the right, and others in the left - the same goes for gradient 70/90.
What did you try to make it work?:
At the moment, I have an experiment that works as I described, but only presenting images from the columns corresponding to only 2 gradients, i.e., 50 & 70 (or 90, if I change it), as I do not know how to make the second image component to vary between the 2 columns (70 & 90) so that the subjects are sometimes presented with an image from gradient 70 (+ gradient 50), and others with an image from gradient 90 (+ gradient 50) - and doing so from the Builder.
Add a code component at the bottom and insert the following into the “Begin Routine” tab:
gradients_70_90 = [Stimuli_2, Stimuli_3] # the two alternatives
rnd_gradient_70_90 = np.random.choice(gradients_70_90, 1) # pick one of the alternatives at random
rnd_gradients = np.append(rnd_gradient_70_90 , Stimuli_1) # add the fixed stimulus
np.random.shuffle(rnd_gradients) # get random order of fixed and picked alternative
# set images with random stimuli
Image_left.setImage(rnd_gradients[0])
Image_right.setImage(rnd_gradients[1])
Add the random location xpos7090 to the Position parameter of the Image7090. Do the same for the Position parameter of Image50, use xpos50 instead of xpos7090.
I have used the component names Image50 and Image7090 simply for the sake of clarity. IMHO this makes more sense if you want random positions for your stimuli.
You need to set the x and y positions in your image properties, surrounded by “( …)”, e.g. (xpos50, 0). For the program to run, the values don’t really matter.
I tried copying your code to a code component, but I realized I did not know what should I be putting in the image field of the image component…Which is the variable?
It does not matter, you can even leave it blank. The image is set in the code snippet.
Although I’d suggest you use Jens’ approach as it tells you in the data which stimulus was used and where it was placed.
The error you encounter (NameError: name ‘xpos50’ is not defined) is because for Jens’ approach you have to put the code component at the very top of the component list (right click on component → “move to top”).
I see. Jens solution assumes, you rename the variables in the xlsx as well:
Go into your Excel file and rename the colums “Stimulus1”, “Stimulus2” and “Stimulus3” to “Stim50”, “Stim70” and “Stim90”.
For the Image_50 component, set the image to Stim50. Leave everything else as is.
Sorry for not using your variable names, but umb’s explanation is correct. It works both ways. Changing the names I used to the ones you use also works.