Checking stimulus presentation timing

Hi, I’m trying to get the timing of a series of stimuli in order to check the precision of my experiment. I’m wondering if this approach is reasonable:

from psychopy import core, visual

win = visual.Window(fullscr=True, color='black', allowGUI=False)
stim = visual.TextStim(win, text="Stimulus")
mask = visual.TextStim(win, text="Mask")
stim_clock = core.Clock()

stim_dur = 0

def get_time():
    global stim_dur
    stim_dur  = stim_clock.getTime()

win.callOnFlip(stim_clock.reset)
for frame in range(3):
    stim.draw()
    win.flip()
    
win.callOnFlip(get_time)
for frame in range(5):
    mask.draw()
    win.flip()

In this way, I should be able to get the correct timing right? The results seem ok (I’ve done it 1000 times and then averaged the result). My main doubt is that I’ve seen a lot of coding examples like this:

# setup screen and stimuli
clock = core.Clock()
win.callOnFlip(stim_clock.reset)
for frame in range(3)
    stim.draw()
    win.flip()
win.flip() # this is not compatible with my approach
stim_dur = stim_clock.getTime()

But I need the second stimulus immediately after (no blanks), so my only idea was to use win.callOnFlip() also for getting the time given that it always return None.
What do you think?

In my head, to get the closest to the actual physical stimulus presentation time using software you do the following:

  1. Get a timestamp after completion of the first flip command of the stimulus presentation
  2. Get a timestamp after completion of the first flip command without the stimulus presentation

Your callOnFlip functions effectively do this, so I guess it’s ok :slight_smile:

The procedure I typically use is the following (assuming vsync is enabled so the flip function returns only after the screen has been updated):

stim_clock = core.Clock()
for frame in range(3):
   stim.draw()
   win.flip()
   if frame == 0:
      stim_clock.reset()

for frame in range(5):
   mask.draw()
   win.flip()
   if frame == 0:
      stimulus_duration = stim_clock.getTime()