Two questions about RT measurement with psychopy API

Hi all, I have been coding an experiment using the psychopy API to manage my display, present stimuli, etc. As I’m inexperienced with the API, I want to ask a couple of questions about RT measurement.

One: I want to confirm that my procedure will measure RT correctly. First I prepare the stimulus (or make a list of stimuli). Then I draw the stimulus(or list of stimuli), followed by a win.flip and an event.waitkeys. The RT is then the timestamp of the event.waitKeys minus core.getTime() right after the win.flip. Below is a sample take from my experiment code (and simplified to be self-contained):

from psychopy import visual, core
exp_window = visual.Window(color=(-1, -1, -1), fullscr=False)


stim = visual.TextStim(win=exp_window, text=text,
                               font="Arial", height=height, wrapWidth=wrapWidth)
stim.draw()
win.flip(clearBuffer=True)
t0 = core.getTime()
resp = event.waitKeys(timeStamped=True)
RT = resp[0][1] - t0

Two: I am wondering whether my monitor refresh rate will have a large effect on my RT measurement from the start of the stimulus presentation to the response time. I am really most interested in this, a little bit of variability in the amount of time it takes for the stimulus to be initially presented isn’t a big deal as long as the RT measurement from that point onwards is good. As I understand it, the procedure I pasted above should get the initial time (t0) right after the win flip succeeds. Does that mean that my t0 will start from after the screen refresh, and thus my RT measurement will be relatively independent from refresh rate?

Thanks very much for your time and fantastic python package!

Rather than setting timeStamped = True, you should replace True with a clock object that you’ve zeroed immediately after the win.flip(). That way, the time stamp will automatically be counting from the appropriate zero point, and you don’t need to do any subtraction.

But in answer to your question, in your case, refresh rate is indeed irrelevant to your RT precision, as you are not checking for keypresses within a drawing loop. i.e. you draw the stimulus just once, leaving it static on screen while you wait for the next response, whenever it occurs. So your code is not suffering from the 16.7 ms granularity in response times that would occur if you checked once per 60 Hz screen refresh, say.

2 Likes

Great, so just confirming, you are recommending I change my code to:

resp = event.waitKeys(timeStamped=core.getTime())
RT = resp[0][1]

Thanks.

no, you need to pass it a clock object:

# initialize a clock at some point
myclock = core.Clock()

# reset the clock to 0 immediately after you flip the window
win.callOnFlip(myclock.reset)
win.flip()

# Wait for button press and get time compared to last reset of clock
resp = event.waitKeys(timeStamped=myclock)


2 Likes

Fantastic, thanks.

I think I got that working now. For mine to work I had to use had to use core.Clock() not core.clock() and had to give win.callOnFlip trial_clock.reset without a () after the function name. Here it is in my actual code:

        trial_clock = core.Clock()
        self.canvas.win.callOnFlip(trial_clock.reset)
        self.canvas.show()
        resp = event.waitKeys(timeStamped=trial_clock)

The canvas object the code refers to is an instance of below (shortened):

from psychopy import visual, core


class Canvas():

    def __init__(self, win):
        self.win = win
        self.stim_list = []

    def show(self):
        for stim in self.stim_list:
            stim.draw()
        self.win.flip(clearBuffer=True)

1 Like