psychopy.org | Reference | Downloads | Github

A precise way to time stimuli duration offline and online

Hi everyone,

After reading PsychoPy documentation on timing, I came to the conclusion there are too many factors to exactly control visual stimuli display. However, I would like to time the onset and the duration of my stimuli in the most precise manner.

In my experiment, I present a series of letters for 9 frames each using a Text Component in a loop. To get onset and duration of each stimulus, I use a Code Component that does the following at the end of the routine:

# Stimulus duration in ms
thisExp.addData("stimDuration", 1000 * (textTrial.tStop - textTrial.tStart))

# Stimulus onset in global clock
thisExp.addData("stimOnset", textTrial.tStartRefresh)

After the experiment is run, the duration of each stimulus I get from the code lines above is between 146 ms - 155 ms (Ideally it would be 60 Hz * 9 frames = 150 ms). My question is, is this an acceptable approach to time my stimuli?

Besides, these commands seems not to work if the experiment is run online. Is there any alternative to make it work online?

Thanks.

That timing code you’ve got is not taking into account when the actual screen refresh occurs, only when the stimulus on/offset was requested. The timing columns that PsychoPy itself outputs in recent versions, or the log files (in all versions) should be a lot more precise than that.

Online, the time that is reported by those commands will never be quite so precise because the estimate of when the screen has performed a refresh is less precise (it has to go via the browser). See our timing study for further details about the sort of precision that’s possible there.

Hey @jon, thanks for answering,

I decided to modify the .js code in the html folder. More precisely, the trialRoutineEachFrame() function, so I mark the onset of the stimulus just after textTrial.setAutoDraw(true) and the end of it just after textTrial.setAutoDraw(false) .

I think that´s a better option compared to the one I described above.

Just after setAutoDraw() still doesn’t account for the time to screen refresh if that’s what you were hoping? The screen flip call has not occurred (and, more importantly, returned) at this point.

Thanks again @jon, I have read your timing study and found it very useful. I know I cannot get the same precision in an online study compared to offline, however when I run my experiment online (pilot mode), I do not get a column with the stimuli onset in the resulting .csv (I do get this column offline), so I am just trying to figure out the most precise way to time my stimuli online…

Ah, right, yes. We didn’t add that and the online version doesn’t yet have the Window methods that I added to the Python version to make it possible. I’m afraid the log files are probably your best bet there, even though those are harder to analyse

Hey @jon, I get your point, but are the log files available online? When I run the experiment online (Pilot mode), the only thing I get is a .csv file. Do I need to go into Running mode to have access to them?

Ah yes, you’re right. They only appear in running mode (and with recent versions of PsychoJS, I forget which version they got added)