| Reference | Downloads | Github

Presenting stimuli for X frames

Hello! I am fairly new to psychopy, but I know python. As an exercise, I would like to present a stimulus for say, X = 40 frames (I have a 60Hz monitor), measure the timing accuracy of the presentation, and record potential dropped frames. I was thinking of doing something like:

> for i in range (40):
>    stim.draw()
>    win.flip()
>    if i == 0:
>       time = core.Clock()
> print time.getTime()

which should be 666.66. Am I correct? What should I do to record frames that are dropped?

Thanks guys!

Minor point: Strictly, I would create the timer earlier and just reset it when i == 0. Realistically, creating a timer will take very little time, but it is good practice to get into initialising objects before they are needed in time-sensitive code, as some objects take quite a while to instantiate.

I think your interval will actually be 650 ms, though (there are 40 screen refreshes, but you are measuring the time between them, which is 39 intervals). Sometimes easiest to imagine this with just two flips:

timer = core.Clock()
timer.reset() # start timing
time = timer.getTime() #end timing

i.e. there are two flips above, but the time between them is only one refresh interval (e.g. 16.666 ms).

To capture any dropped frames, store a list of all of your refresh intervals. They should all be 16.66 ms. Outliers (e.g. 33.33 ms) indicate a dropped frame.

NB time is the name of library in the Python standard library, so perhaps best to avoid it as a variable name.