Created
July 1, 2012 09:36
-
-
Save alexholcombe/3027695 to your computer and use it in GitHub Desktop.
tentative test of psychopy response latency. Is this the recommended way to record response time?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from psychopy import visual, event, core | |
import numpy as np | |
"""Record response latency | |
""" | |
trialClock = core.Clock() | |
Hz = 60 | |
#create a window to draw in | |
bgColor=np.array([-1,-1,-1]) | |
scrn = 0; fullscrn= 0 | |
myWin =visual.Window(color=bgColor, allowGUI=False,screen=scrn,fullscr=fullscrn, units='pix',waitBlanking=False) | |
respText = visual.TextStim(myWin,pos=(0, 0),color=(1,1,1),colorSpace='rgb',alignHoriz='center', alignVert='center', units='norm',autoLog=False) | |
respText.setText('Press up arrow for up, down arrow for down') | |
core.wait(.2) | |
for i in xrange(50): #go through 50 frames that show nothing. | |
#Because sometimes the operating system / graphics pipeline needs to clean up its act before accurate timing ensues | |
myWin.flip() | |
maxRespTime = 5 #sec | |
frame = 0 | |
respMade = False | |
stopExp = False | |
respText.draw() | |
myWin.flip() | |
trialClock.reset() | |
while not respMade and (frame < maxRespTime*Hz) and not stopExp: | |
frame += 1 | |
for key in event.getKeys(): | |
if key in ['up','down']: #up arrow or down arrow | |
respLatencySecs = trialClock.getTime() | |
respLatencyFrames = frame | |
respMade = True | |
if key=='up': | |
resp = 1 | |
if key=='down': | |
resp = -1 | |
#check if pressed abort-type key | |
if key in ['escape','q']: #end experiment | |
stopExp=True | |
respText.draw() | |
myWin.flip() | |
print 'respMade = ',respMade | |
if respMade: | |
print 'Response latency according to trialClock = ', np.around(respLatencySecs,3), 'seconds' | |
print 'According to number of frames that have flipped (', np.around(frame,0), ') = ',np.around(frame*1.0/Hz,3), ' seconds' | |
diffClockFrameCounter = abs(respLatencySecs-frame*1.0/Hz) | |
print 'Difference = ',diffClockFrameCounter, ' and frame precision is ', np.around(1.0/Hz,3), | |
if diffClockFrameCounter > 1.0/Hz: | |
print " so something's out of whack." | |
else: print " so that's no worse from the frame clock than expected." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment