Hello,
I’m new in Psychopy and would appreciate your help in solving the following problem:
Background: I’m using a version of the additional singleton task where participants search for a known-shape (pentagon) and an irrelevant (singleton) distractor is presented on 50% of the trials, usually in a different color.
My experiment: Instead of colors, we’re manipulating emotion distractors (4 blocks: angry, happy, sad, neutral; counterbalanced). We have 3 images per emotion condition (3img x 4blocks) from which one image should be randomly selected if singletonPresence == True
.
- Note that the selected image should specifically replace the (non-target) circle item.
- Also note that I’m using a Psychopy script and the images are stored in a local path
The issue: I’m using costume code to preload and specify under which conditions these images should be presented, but I get an indexing error.
- The images are loaded in a costume code rather than condition files because I use these to choose practice/main blocks and specify the singletonPresence manipulation.
So:
[begin experiment]
emotion_dist = []
#store images path in lists
angry_stim = ['stimuli/angry1.jpg',
'stimuli/angry2.jpg',
'stimuli/angry3.jpg']
happy_stim = ['stimuli/happy1.jpg',
'stimuli/happy2.jpg',
'stimuli/happy3.jpg']
sad_stim = ['stimuli/sad1.jpg',
'stimuli/sad2.jpg',
'stimuli/sad3.jpg']
neutral_stim = ['stimuli/neutral1.jpg',
'stimuli/neutral2.jpg',
'stimuli/neutral3.jpg']
#set a dictionary of image lists, nested in block keys
conditionBlock_d = {'angry':[angry_stim], 'happy':[happy_stim],
'sad':[sad_stim], 'neutral':[neutral_stim]}
#counterbalance blocks
conditionBlock_k = list(conditionBlock_d.keys()) #convert to list
shuffle(conditionBlock_k) #randomized blocks across participants
Now, I’m trying to use random.choice()
to select only one image per trial from the appropriate key list (the emotion condition, or block). Then, I want to store it in a list so I could call the last item in this list when distPresence == True
[begin routine]
#randomly choose images based on emotion block
for emotion_img in emotion_dist:
for block in conditionBlock_k:
if conditionBlock_k =="angry":
emotion_img = random.choice(angry_stim)
elif conditionBlock_k == "happy":
emotion_img = random.choice(happy_stim)
elif conditionBlock_k == "sad":
emotion_img = random.choice(sad_stim)
elif conditionBlock_k == "neutral":
emotion_img = random.choice(neutral_stim)
emotion_dist.append(emotion_img)
In another routine (i.e., search), I use an if statement to set the image’s opacity to 1 in singleton present trials, and zero in singleton absent trials. Then, I store the last item in emotion_dist list as a variable to draw in each frame.
[begin routine]
this_singleton = emotion_dist[-1] #set last item as the singleton in trial[i]
#present emotion singletons
if distPresence == "present":
this_singleton = visual.ImageStim(win, image=this_singleton)
this_singleton.setOpacity(1.0)
singleton_name.append('this_singleton')
else:
this_singleton.setOpacity(0)
singleton_name.append("absent");
[each frame]
this_singleton.draw()
this_singleton.setPos([placeholder_size, placeholder_size])
this_singleton.setSize([placeholder_side, placeholder_side])
win.flip()
core.wait(2)
My experiment crashes because of an indexing error that I can’t figure out how to fix -
this_singleton = emotion_dist[-1] #set last item as the singleton in trial[i]
IndexError: list index out of range
I’m completely stuck with how to program thus experiment and would be grateful for your help!
emojiExp.psyexp (60.5 KB)
emojiExp.py (54.2 KB)