OS: MacOS Mojave 10.14
PsychoPy version: 3.0.0b11
Standard Standalone? (y/n): y
I’m new to psychopy (and python) and am working on designing an experiment
Here’s what I am trying to do:
I am designing an experiment where participants will see two images (on the left and right sides of the screen) at a time for two seconds. The position of the images should be randomized such that in some trials the image on the left is from List A and the image on the right is from List B and in other trials it should be the opposite. Once the images have been shown for 2 seconds, they disappear and the experiment will prompt the participant to press “Q” to view the image that was on the left or “P” to view the image that was on the right. They will then see their choice for 4 seconds. The experiment will then repeat until all images have been presented.
What I have so far:
Here’s a link to my builder screen
Builder screenshot (https://i.stack.imgur.com/yk9j8.jpg)
In the InitCode routine under begin experiment I have:
# Modified from https://groups.google.com/forum/#!topic/psychopy-users/WljgXeoy6Ik
# In this script I use a csv file to define my variables as opposed to explicity defining them in my code.
# I then use the participant's number and the session number to create personalized order files
import random
import csv
#randomize seed
random.seed()
#Now, I am going to use the image_stimuli.csv file to define my pics instead of doing it explicitly
# first, I open the file called 'image_stimuli.csv' and read its contents into the variable 'words'
#idk what rU is
pics=list(csv.reader(open('image_stimuli.csv',"rU")))
# Next I will create two 'empty' variables into which I will put the pic lists
FriendlyPics = []
ViolentPics = []
# Next I will loop through the 'pics' object and place the appropriate pics in their respective objects
for i in range(len(pics)):
FriendlyPics.append(pics[i][0])
ViolentPics.append(pics[i][1])
# Now we take out the header line
FriendlyPics = FriendlyPics[1:]
ViolentPics = ViolentPics[1:]
# Then I randomize them
# this will create my two randomized pic lists
FriendlyRand = random.sample(FriendlyPics,len(FriendlyPics))
ViolentRand = random.sample(ViolentPics,len(ViolentPics))
# Now we do the writing to file part
# First though, we define the 'subjectID' and 'sessionID' variables for naming the order files
subjectID = expInfo['participant']
sessionID = expInfo['session']
# now we create a file name based on those variables
filename1 = subjectID + '_' + sessionID + '.csv'
with open(filename1,'w') as w:
writer=csv.writer(w)
writer.writerow(['FriendlyPics','ViolentPics'])
for i in range(len(FriendlyRand)):
writer.writerow([FriendlyRand[i],ViolentRand[i]])
# Now put $filename1 in the conditionFile field in the trials loop dialog box
Then in the randomize_locations routine under begin experiment I have:
import random, copy
from random import randint
from decimal import *
master_positions=[[-0.5, 0.0],[0.5,0.0]]
# setup an array to store 2 locations to randomly allocate to our pics master_positions=[[-0.5, 0.0],[0.5,0.0]]
positions = copy.deepcopy(master_positions)
and for begin routine:
# reset 'positions'
positions = copy.deepcopy(master_positions)
#randomise this for each trial
random.shuffle(positions)
print(positions)
Basically, I have it such that the images will be presented in random order and randomly on the left or right. But I’m not sure how to present the image based on the choice that is made. The issue for me is that since I randomized the position, I don’t know how to call based on their selection. I.e., if they press “Q”, I don’t know which image (from List A or List B) was on that side for that trial, and so I don’t know how to tell psychopy to present the correct image based on the choice. Perhaps there’s an easy way to name a variable based on the position of the image? or maybe an easier way to randomize. Open to either solution.
If it’s any help, I’m using the virtually the same paradigm as the ePrime-based experiment found here: https://osf.io/ip7kb/
Any help would be greatly appreciated. Thanks!