psychopy.org | Reference | Downloads | Github

Presenting faces on screen

Hi all,

So I’m trying to present 6 stimuli (faces) around a fixation cross. This will be in a block of 6 trials, with 6 faces on each. I wish the images to remain there until a button is pressed. I am able to present an outline of the images (a white box), but not the images themselves. I’m not sure if this is because the matrix I am using is in the form of text (as it has been used for creating trials for text previously). As I have not got an error message per se, here is a screenshot of the exp as its running, showing the issue.

The data is outputting ok, with the randomisation working fine, and the button presses and RT’s being recorded.

Here’s the code

from psychopy import visual, core, event #import some libraries from PsychoPy
import psychopy.event
import os
from psychopy import data
from random import shuffle
import random, copy

#
expName = 'CIT_Experiment'
thisPath = os.path.split(__file__)[0]
os.chdir(thisPath)


expInfo = {}

expInfo['date'] = data.getDateStr()  # add a simple timestamp

#IMPORTANT NEED TO CHANGE INFO FOR EACH PARTICIPANT
expInfo['participant'] = 'p18 f 22 '


filename = 'data/%s_%s_%s' %(expInfo['participant'], expName, expInfo['date'])
##create psychopy experiment handler
thisExp = data.ExperimentHandler(version='',
    extraInfo=expInfo, 
    savePickle=True, saveWideText=True,
    dataFileName=filename)
    

print('Created EXPinfo')


#This section creates the trials

Matrix = [[0 for x in xrange(6)] for x in xrange(6)]


Matrix[0][0] = 1
Matrix[0][1] = 2
Matrix[0][2] = 5
Matrix[0][3] = 6
Matrix[0][4] = 7
Matrix[0][5] = 8

Matrix[1][0] = 1
Matrix[1][1] = 3
Matrix[1][2] = 9
Matrix[1][3] = 11
Matrix[1][4] = 7
Matrix[1][5] = 12

Matrix[2][0] = 1
Matrix[2][1] = 4
Matrix[2][2] = 9
Matrix[2][3] = 12
Matrix[2][4] = 6
Matrix[2][5] = 10

Matrix[3][0] = 2
Matrix[3][1] = 3
Matrix[3][2] = 8
Matrix[3][3] = 10
Matrix[3][4] = 5
Matrix[3][5] = 9

Matrix[4][0] = 2
Matrix[4][1] = 4
Matrix[4][2] = 8
Matrix[4][3] = 11
Matrix[4][4] = 7
Matrix[4][5] = 12

Matrix[5][0] = 3
Matrix[5][1] = 4
Matrix[5][2] = 5
Matrix[5][3] = 6
Matrix[5][4] = 11
Matrix[5][5] = 10

#Thise section Loads into trial handler
print('Created trials')
trialsList = []


for trial in range(6):
    thisTrial = {}
    order = range(6)
    random.shuffle(order)
    for i in range(6):
        
        id = Matrix[trial][order[i]]
        
        if(id ==1):
            image = 'Face.1.jpg'
        elif(id == 2):
            image = 'Face.2.jpg'
        elif(id == 3):
            image = 'Face.3.jpg'
        elif(id == 4):
            image = 'Face.4.jpg'
        elif(id == 5):
            image = 'Face.5.jpg'
        elif(id == 6):
            image = 'Face.6.jpg'
        elif(id == 7):
            image = 'Face.7.jpg'
        elif(id == 8):
            image = 'Face.8.jpg'
        elif(id == 9):
            image = 'Face.9.jpg'
        elif(id == 10):
            image = 'Face.10.jpg'
        elif(id == 11):
            image = 'Face.11.jpg'
        elif(id == 12):
            image = 'Face.12.jpg'
        else:
            image = id
        
        thisTrial[i] = image
    trialsList.append(thisTrial)
    
print('SavedTrials')


positions = [
 (-10, 10),
 (10, 10),
 (-10, -10),
 (10, -10),
 (-1, -10),
 (1, 10),
 ]


#This section creates the objects we need for the experiment

trials = data.TrialHandler(trialList=trialsList, nReps=1,
    method='random', 
    extraInfo=expInfo, name='trials')
thisExp.addLoop(trials)

#create a window
mywin = visual.Window([1920,1080], monitor="testMonitor", units="deg")
mywin.update()

img1 = visual.ImageStim(mywin, size=[5, 5])


Target = visual.ImageStim(mywin, size=[5, 5])

fixation = visual.GratingStim(mywin, tex=None, mask='raisedCos', size=20, units='pix')

responseClock = core.Clock()

#Running the trials

for trial in trials:
    for i in range(6):
        # Prepare stimulus
        #fixation.draw()
        # Show it 
        Target.pos = positions[i]
        Target.text = trial[i]
        Target.draw()
        
    mywin.flip()
    responseClock.reset()
    resp = event.waitKeys()
    if resp == ["escape"]:
        core.quit()
    trials.addData('respDetect.keys', resp)
    trials.addData('respDetect.rt', responseClock.getTime())
    mywin.flip()
        
    thisExp.nextEntry()

Any thoughts welcome

Nathan

Perhaps try replacing Target.text = trial[i] with Target.image = trial[i].

A simple thing as ever…

Thank you very much :slight_smile: