Weird absolute reaction time times

Dear all,
I programmed a simple fingertapping experiment see code below. Piloting worked perfectly, but during real data acquisition I suddenly realized that in two subjects and 3 trials each reaction times went back in time. That is tap two had an earlier absolute reaction time than tap one. Anybody an idea what went wrong here? I want to make sure my other data is ok… Best, Kat

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# The first line is called the hash bang. It helps operating systems 
# understand what to do with this script. The second line describes 
# the encoding of this file. UTF-8 is the only one used nowadays.
# It supports all alphabeths, even runes and linear B.
 
# Import the PsychoPy libraries that you want to use
from psychopy import core, visual, event, sound
import time, csv

# Create a window
win = visual.Window(fullscr=True, monitor="testMonitor")
 
# Create a stimulus for a certain window
message = visual.TextStim(win, text='Please type subject number')

# Draw the stimulus to the window. We always draw at the back buffer of the window.
message.draw()
 
# Flip back buffer and front  buffer of the window.
win.flip()

c= event.waitKeys()

# open data output file
filename= 'fingertap_with_met%02d.csv' % int(c[0])

datafile = open(filename, "wb")

# connect it with a csv writer
writer = csv.writer(datafile, delimiter=";")
# create output file header
writer.writerow([
    "number", 
    "responseTime",
    ])


# Create a window
win = visual.Window(fullscr=True)
 
# Create a stimulus for a certain window
message = visual.TextStim(win, height= 0.08, text='Hi! \n \nThis is a quick experiment about your ability to follow a rythm.\n \nIn the following you will hear a metronome ticking in a constant rhythm. \n \nPlease tap with your right index finger along with it on the space bar. \n \nPlease continue tapping along with it until we notify you that you finished the task. \n \nPlease press the space bar once you are ready to start.  ')
 
# Draw the stimulus to the window. We always draw at the back buffer of the window.
message.draw()
 
# Flip back buffer and front  buffer of the window.
win.flip()

c= event.waitKeys()

s = sound.Sound(value='met1220.wav') 

message = visual.TextStim(win, text='Please start tapping with the metronome!')
# Draw the stimulus to the window. We always draw at the back buffer of the window.
message.draw()
# Flip back buffer and front  buffer of the window.
win.flip()
core.wait(1.0)
s.play()

responseTime=[]
for i in range(1,1201):
    c= event.waitKeys()
    if 'escape' in c:
        core.quit()
    else:   
        responseTime=time.time()
        writer.writerow([
            i,  
            "{:.3f}".format(responseTime),
            ])

s.stop()
message = visual.TextStim(win, text='Thanks for this! \n You have finished!')
# Draw the stimulus to the window. We always draw at the back buffer of the window.
message.draw()
# Flip back buffer and front  buffer of the window.
win.flip()
core.wait(2)
# Close the window
win.close()
 
# Close PsychoPy
core.quit()

Hi, I don’t know what exactly is going wrong here, but I do have some general recommendations.

This list is never used, but instead overwritten in each trial.

You probably want to use the TrialHandler instead, which will make it much easier to create an output file.

You probably want to call waitKeys() with the timeStamped=True parameter. That way, you don’t have to use time.time() anymore.

Good luck,

Richard

PS: If you wrap program code with three backticks (`), it will be automatically syntax-highlighted. I have edited your original post to enable the syntax highlighting.

Edit: I also realized you’re creating your window twice:

win = visual.Window(fullscr=True, monitor="testMonitor")
...
win = visual.Window(fullscr=True)

You probably don’t want that.

Edit 2: You never close datafile! You should not do that! Instead, the recommended syntax is:

with open(filename, "wb") as datafile:
    writer = csv.writer(datafile, delimiter=";")
    ...

This will close datafile automatically when done.

1 Like