# Two questions about RT measurement with psychopy API

**URL:** <https://discourse.psychopy.org/t/two-questions-about-rt-measurement-with-psychopy-api/5594>\
**Category:** Coding\
**Created:** [October 19, 2018, 3:18am UTC](https://discourse.psychopy.org/t/two-questions-about-rt-measurement-with-psychopy-api/5594 "2018-10-19T03:18:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LJGS](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@LJGS](https://discourse.psychopy.org/u/LJGS)\
**Post date:** [October 19, 2018, 3:18am UTC](https://discourse.psychopy.org/t/two-questions-about-rt-measurement-with-psychopy-api/5594/1 "2018-10-19T03:18:05Z")

</div>

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):

```auto
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!

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [October 21, 2018, 10:04am UTC](https://discourse.psychopy.org/t/two-questions-about-rt-measurement-with-psychopy-api/5594/2 "2018-10-21T10:04:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![LJGS](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@LJGS](https://discourse.psychopy.org/u/LJGS)\
**Post date:** [October 22, 2018, 2:26am UTC](https://discourse.psychopy.org/t/two-questions-about-rt-measurement-with-psychopy-api/5594/3 "2018-10-22T02:26:02Z")

</div>

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

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

```

Thanks.

---

<div class="post-metadata">

**Author:** ![sappelhoff](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/sappelhoff/32/40305_2.png) [@sappelhoff](https://discourse.psychopy.org/u/sappelhoff)\
**Post date:** [October 22, 2018, 6:29am UTC](https://discourse.psychopy.org/t/two-questions-about-rt-measurement-with-psychopy-api/5594/4 "2018-10-22T06:29:18Z")

</div>

no, you need to pass it a [clock object](http://www.psychopy.org/api/core.html):

```python
# 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)

```

---

<div class="post-metadata">

**Author:** ![LJGS](https://avatars.discourse-cdn.com/v4/letter/l/82dd89/32.png) [@LJGS](https://discourse.psychopy.org/u/LJGS)\
**Post date:** [October 22, 2018, 7:32am UTC](https://discourse.psychopy.org/t/two-questions-about-rt-measurement-with-psychopy-api/5594/5 "2018-10-22T07:32:03Z")

</div>

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:

```auto
        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):

```auto
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)

```
