psychopy.org | Reference | Downloads | Github

How to draw additional images depending on which main image is presented

Description of the problem:

I have a list of stimuli I want to display throughout a task. For every given stimuli I present, I want to also present a similar looking stimuli and a dissimilar one. I have created a list of similar and dissimilar images for every stimuli that is presented. However, when I call this in my experiment, the code is not executing properly. Rather, the similar image and dissimilar image being displayed are not from the list I want. However, I am not getting an error. Any help would be greatly appreciated!

initialize list of true images we will show in the main task, total of 10

display_stimuli_list = [vertical_stripes_stimulus, horizontal_stripes_stimulus, pentagon_up_left_empty_stimulus, soft_zig_zag_down_stimulus, pentagon_down_empty_stimulus, soft_zig_zag_right_stimulus, hard_zig_zag_up_stimulus, hard_zig_zag_left_stimulus, diaganol_right_stimulus, few_checkers_stimulus]

stim design for loop

for i in display_stimuli_list:
if i == vertical_stripes_stimulus:
true_image_list = [vertical_stripes_stimulus]
similar_image_list = [vertical_stripes_less_lines_stimulus, many_checkers_stimulus]
dissimilar_image_list = [pentagon_up_right_fill_stimulus, horizontal_stripes_stimulus, pentagon_up_fill_stimulus, horizontal_stripes_extra_lines_stimulus]

elif i == horizontal_stripes_stimulus:
    true_image_list = [horizontal_stripes_stimulus]
    similar_image_list = [horizontal_stripes_extra_lines_stimulus, few_checkers_stimulus]
    dissimilar_image_list = [soft_zig_zag_left_stimulus, pentagon_up_left_fill_stimulus, vertical_stripes_stimulus, vertical_stripes_less_lines_stimulus]
    
elif i == pentagon_up_left_empty_stimulus:
    true_image_list = [pentagon_up_left_empty_stimulus]
    similar_image_list = [pentagon_up_left_fill_stimulus, pentagon_down_empty_stimulus]
    dissimilar_image_list = [horizontal_stripes_stimulus, soft_zig_zag_down_stimulus, many_checkers_stimulus, few_checkers_stimulus]

elif i == soft_zig_zag_down_stimulus:
    true_image_list = [soft_zig_zag_down_stimulus]
    similar_image_list = [hard_zig_zag_down_stimulus, horizontal_stripes_stimulus]
    dissimilar_image_list = [diaganol_left_stimulus, pentagon_up_left_fill_stimulus, diaganol_right_stimulus, vertical_stripes_less_lines_stimulus]
    
elif i == pentagon_down_empty_stimulus:
    true_image_list = [pentagon_down_empty_stimulus]
    similar_image_list = [pentagon_up_left_empty_stimulus, pentagon_up_left_fill_stimulus]
    dissimilar_image_list = [vertical_stripes_stimulus, vertical_stripes_less_lines_stimulus, soft_zig_zag_down_stimulus, hard_zig_zag_down_stimulus]
    
elif i == soft_zig_zag_right_stimulus:
    true_image_list = [soft_zig_zag_right_stimulus]
    similar_image_list = [hard_zig_zag_right_stimulus, vertical_stripes_less_lines_stimulus]
    dissimilar_image_list = [pentagon_up_fill_stimulus, hard_zig_zag_down_stimulus, diaganol_left_stimulus, pentagon_up_left_fill_stimulus]
    
elif i == hard_zig_zag_up_stimulus:
    true_image_list = [hard_zig_zag_up_stimulus]
    similar_image_list = [soft_zig_zag_up_stimulus, vertical_stripes_less_lines_stimulus]
    dissimilar_image_list = [diaganol_left_stimulus, pentagon_down_empty_stimulus, pentagon_up_left_fill_stimulus, diaganol_right_stimulus] 
    
elif i == hard_zig_zag_left_stimulus:
    true_image_list = [hard_zig_zag_left_stimulus]
    similar_image_list = [soft_zig_zag_right_stimulus, vertical_stripes_stimulus]
    dissimilar_image_list = [horizontal_stripes_stimulus, diaganol_left_stimulus, pentagon_up_left_fill_stimulus, horizontal_stripes_extra_lines_stimulus]
     
elif i == diaganol_right_stimulus:
    true_image_list = [diaganol_right_stimulus]
    similar_image_list = [diaganol_left_stimulus, vertical_stripes_less_lines_stimulus]
    dissimilar_image_list = [pentagon_down_fill_stimulus, many_checkers_stimulus, horizontal_stripes_extra_lines_stimulus, pentagon_up_left_empty_stimulus]
    
elif i == few_checkers_stimulus:
    true_image_list = [few_checkers_stimulus]
    similar_image_list = [many_checkers_stimulus, vertical_stripes_less_lines_stimulus]
    dissimilar_image_list = [soft_zig_zag_down_stimulus, diaganol_right_stimulus, pentagon_up_left_fill_stimulus, pentagon_down_empty_stimulus]

fixation_cross = visual.ShapeStim(win, vertices=((0, -0.03), (0, 0.03), (0,0), (-0.03,0), (0.03, 0)), lineWidth=15, closeShape=False, lineColor=“white”, size = [400,400])

initialize_instructions_screens

instructions_1_screen = visual.ImageStim(win=win, image=’/Users/benmuzekari/Desktop/psychophysics/instructions/instructions_1_screen.png’, size = [1200,800])
instructions_2_screen = visual.ImageStim(win=win, image=’/Users/benmuzekari/Desktop/psychophysics/instructions/instructions_2_screen.png’, size = [1200,650])
instructions_3_screen = visual.ImageStim(win=win, image=’/Users/benmuzekari/Desktop/psychophysics/instructions/instructions_3_screen.png’, size = [1200,800])
instructions_4_screen = visual.ImageStim(win=win, image=’/Users/benmuzekari/Desktop/psychophysics/instructions/instructions_4_screen.png’, size = [1200,800])
instructions_5_screen = visual.ImageStim(win=win, image=’/Users/benmuzekari/Desktop/psychophysics/instructions/instructions_5_screen.png’, size = [1200,800])

initialize text screens

thank_you_screen = visual.TextStim(win, text=‘Thank you for your participation’)
missed_trial_screen = visual.TextStim(win, text=‘No response recorded’)
begin_real_task_screen = visual.TextStim(win, text=‘You have completed the practice round. Please press any button to advance to the main game.’)

initialize post trial stimuli

pattern_question_text = visual.TextStim(win, text=‘Which pattern did you see?’, pos=(0, 320)) # pattern question text
min_confidence = 0
max_confidence = 100
confidence_range = range(min_confidence, max_confidence+1)
labelpoints = [0, 0.25, 0.5, 0.75, 1.0] # the fractions of the range you want to have labels at
labels = [str(int(max_confidence * point)) for point in labelpoints] # the actual text for each label
ticks = [len(confidence_range) * point for point in labelpoints]
ratingScale = visual.RatingScale(win, choices=confidence_range,labels=labels, tickMarks=ticks)
confidence_text = visual.TextStim(win, “How confident are you that this is pattern you saw? \n (0 = no confidence, 100 = full confidence)”)

display instructions

event.clearEvents()
instructions_1_screen.draw()
win.flip()
event.waitKeys()
instructions_2_screen.draw()
win.flip()
event.waitKeys()
instructions_3_screen.draw()
win.flip()
event.waitKeys()
instructions_4_screen.draw()
win.flip()
event.waitKeys()
instructions_5_screen.draw()
win.flip()

allow subject to escape using escape button

if ‘escape’ in event.waitKeys():
core.quit()

practice loop

for i in range(0, prac_num_trials):

fixation_cross.draw()
win.flip()
core.wait(random.choice(iti_duration_list))
i = random.choice(display_stimuli_list)
present_true_stimulus = i
present_similar_stimulus = random.choice(similar_image_list) #
present_dissimilar_stimulus = random.choice(dissimilar_image_list) #
mask_stimulus = grey_square_stimulus
present_true_stimulus.draw()
mask_stimulus.draw()
win.flip()

thisResp = None #
while thisResp == None:
    wait_for_response = event.waitKeys()
    for key in wait_for_response:
        if key == 'space':
            thisResp = 1
            
            present_true_stimulus.size = [150,150]
            present_true_stimulus.pos = (-200, 200)
            present_similar_stimulus.size = [150,150]
            present_similar_stimulus.pos = (200, 200)
            present_dissimilar_stimulus.size = [150,150]
            present_dissimilar_stimulus.pos = (0, 200)
            mouse = event.Mouse(win=win)
            Pressed = False

            while not Pressed:
                pattern_question_text.draw()
                present_true_stimulus.draw()
                present_similar_stimulus.draw()
                present_dissimilar_stimulus.draw()
                win.flip()

                if mouse.isPressedIn(present_true_stimulus) or mouse.isPressedIn(present_similar_stimulus) or mouse.isPressedIn(present_dissimilar_stimulus):
                    ratingScale = visual.RatingScale(win, choices=confidence_range,labels=labels, tickMarks=ticks)
                    while ratingScale.noResponse:
                        present_true_stimulus.draw()
                        present_similar_stimulus.draw()
                        present_dissimilar_stimulus.draw()
                        confidence_text.draw()
                        ratingScale.draw()
                        win.flip()
                    rating = ratingScale.getRating()
                    Pressed = True
                    
                    
        elif thisKey in ['q', 'escape']:
            core.quit()  # abort experiment

    event.clearEvents()

thank subject for participation

thank_you_screen.draw()
win.flip()
core.wait(thank_subject_duration)