Hi everyone,
I used the coder to build a staircase experiment.
The aim of the experiment is to find out which level of contrast of an image is prefered by the observers.
The code is similar to the one in Tutorial 2.
My problem is, that the code is running throw, but the stimulus (the contrast of the image) does not change. Can you please help me fixing my code?
staircase = data.StairHandler(startVal=1.0, # start value
nReversals=3, # number of reversal points
stepSizes= 0.2,# stepsize = single value, list or array
nTrials=1, # minimum number of trials
nUp= 1, # number of ‘incorrect’ (or 0) responses before staircase level increases
nDown= 2, # number of ‘correct’ (or 1) responses before staircase level decreases
stepType='lin',# type of steps
minVal= 0.2, # lower limit for value
maxVal= 1.0) # upper limit for value
# create window where stimulus is presented
win = visual.Window([800,600],allowGUI=True, monitor='testMonitor', units='cm')
# create stimulus
img1 = visual.ImageStim(win, image=path, mask=None, pos=[0.0, 0.0], size=10, anchor=True, ori=0.0, color=[1.0, 1.0, 1.0], colorSpace='rgb', contrast=1.0, opacity=None, depth=0, texRes=128)
# display instructions and wait
message1 = visual.TextStim(win, pos=[0,+3],text='Hit a key when ready')
message2 = visual.TextStim(win, pos=[0,-3],
text="Then press left or right arrow to tell if u like the stimulus better or not - left = no, right = yes")
message1.draw()
message2.draw()
#img1.draw()
win.flip() # to show our newly drawn 'stimuli'
event.waitKeys() # pause until there's a keypress
for thisIncrement in staircase: # will continue the staircase until it terminates!
# set contrast of probe
img1.contrast = (img1.contrast + thisIncrement)
# draw all stimuli
img1.draw()
win.flip()
# wait 500ms; but use a loop of x frames for more accurate timing
core.wait(0.5)
# blank screen
#img1.draw()
#win.flip()
# get response - participant presses left or right arrow
thisResp=None
while thisResp==None:
allKeys=event.waitKeys()
for thisKey in allKeys:
if thisKey=='left': thisResp = -1
elif thisKey=='right': thisResp = 1
elif thisKey in ['q', 'escape']:
core.quit() # abort experiment
event.clearEvents() # clear other (eg mouse) events - they clog the buffer
# add the data to the staircase so it can calculate the next level
staircase.addData(thisResp)
dataFile.write('%.3f,%.3f,%i\n' %(img1.contrast, thisIncrement, thisResp))
core.wait(1)