Reaction time from mouse click

670 views
Skip to first unread message

Hillary Snyder

unread,
Sep 3, 2014, 11:26:53 AM9/3/14
to psychop...@googlegroups.com
Hi everyone,

I am using the psychopy builder mode and I am trying to collect reaction time data from mouse events. Is there any way I can extract this from the data file or even better, a way that I can add code that will add it to the .csv/.xls generated data file. 

Michael MacAskill

unread,
Sep 3, 2014, 10:52:08 PM9/3/14
to psychop...@googlegroups.com

On 4/09/2014, at 3:26 a.m., Hillary Snyder <hillary...@gmail.com> wrote:

> I am using the psychopy builder mode and I am trying to collect reaction time data from mouse events. Is there any way I can extract this from the data file or even better, a way that I can add code that will add it to the .csv/.xls generated data file.

Dear Hillary,

This isn't intuitive (it took me a a while to figure out), but in the mouse component dialog, if you select "Save mouse state" as "every frame", you will automatically get a variable called mouse.time in your .csv data file. This time is collected once every screen refresh (e.g. ~every 16.7 ms for a 60 Hz screen) but that maximum resolution is swamped by the physiological variation in responding (plus there is an unknown latency lag in your mouse/USB hardware…)

Unfortunately those time values in the data file are wrapped in square brackets, which is something we should fix.

Regards,

Michael



Michael MacAskill

unread,
Sep 3, 2014, 11:22:27 PM9/3/14
to psychop...@googlegroups.com
Dear Hillary,

Correction to that last message:

Select "Save mouse state" as "on click" and you'll get the time value without brackets.

Regards,

Michael
Message has been deleted

Hillary Snyder

unread,
Sep 4, 2014, 11:39:39 AM9/4/14
to psychop...@googlegroups.com
Hi Michael,

That is very helpful. Unfortunately we are using a touchscreen that doesn't seem to interface well with the "click" event. I have put in code that states that if the cursor of the mouse is within one of the two images on the screen, the trial ends (as a workaround). When I use the save mouse state on click, I get an error '    trials_2.addData('m1.x', m1.x[0])
IndexError: list index out of range". This is theoretically because there is no click occurring. Is there any way I can populate the reaction time columns in the data sheet with the time that the trial is ended.

Here is the code I referred to:

if t >= 3.5 and m1.mouseMoved():
    if ImageL1.contains(m1):
        continueRoutine = False
    if ImageR1.contains(m1):
        continueRoutine = False
        
Thanks,

Hillary

Michael MacAskill

unread,
Sep 4, 2014, 7:07:15 PM9/4/14
to psychop...@googlegroups.com
Hi Hillary,

Really cool to see that you are using a touch screen with PsychoPy.
I didn't realise you were already using some custom code. This should make it quite easy.

You could do something like this:

if t >= 3.5 and m1.mouseMoved():
if ImageL1.contains(m1) or ImageR1.contains(m1):
# record the current time:
thisExp.addData("mouse.RT", t)

# if you need the x, y coordinates, access them directly:
thisExp.addData("mouse.x", m1.getPos()[0]
thisExp.addData("mouse.y", m1.getPos()[1]

# end the trial:
continueRoutine = False

t is the time since the trial started, so not sure if that is what you want your latency measured relative to, but you can subtract some other time from it as required.

e.g. thisExp.addData("mouse.RT", t - 3.5) # or some other relevant value

Because you are accessing and saving the mouse data yourself, I guess you could select "never" in the "save mouse state" setting of the mouse component?

Does that help?



Mike
--
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill



Message has been deleted

Hillary Snyder

unread,
Sep 23, 2014, 11:39:07 AM9/23/14
to psychop...@googlegroups.com
Hi Michael,

Thanks so much, it works great! I will let you know if we have any more issues.

Also we are incorporating video and was curious if you knew what the best format of the video would be (ie, .avi, .mov or any codecs that are good).

Thanks,

Hillary
Reply all
Reply to author
Forward
0 new messages