psychopy.org | Reference | Downloads | Github

Recording lag time

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x):
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
Sometimes the stimuli present lags and we would like to find a way to track which exact stimuli the experiment lagged on since it changes with each trial. This will help with our reliability.
What did you try to make it work?:
We don’t know where to start
What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

Hi @ccjewell, take a look at these links. You may be interested in detecting dropped frames, which would be the reason for your lag:

PsychoPy timing
Detecting dropped frames
Timing issues

From those links, I was told to go code this in order tor record the time interval of each lag:

import matplotlib.pyplot as plt
plt.plot(win.frameIntervals)
plt.show()

Is there a certain area I am supposed to write this in the code?

Yes, it says to place them at the end of the script, and the easy way to do that is to use a code component. In a code component, in the relevant tabs, add the following:

# Begin Experiment
import matplotlib.pyplot as plt
win.recordFrameIntervals = True


# End Experiment
win.close()
plt.plot(win.frameIntervals)
plt.show()

I’ve added the win.close() command so that the window closes and you can see the plot. You will get an error after the plot, which is fine while you are testing your timing and not actually collecting data.

I tried adding what you wrote to the bottom of the script, and I am still not receiving a list of lag times. You mentioned “relevant tabs” though, there are no tabs in script that match those.

Are there any other options of being able to detect which frame lagged (or extended/descended against the set frame interval)?

David is not suggesting that you edit the script, but that you insert a code component, from the custom component panel. Using the tabs in that component ensures the code gets inserted in the correct place in the generated script, to avoid you having to figure out where it goes.

Thank you so much for your clarification! How do I go about inserting a code component?

I have found the code component and attempted adding the new script into it. I utilized the “custom code: insert python commands…” component. Though, no list of each frames true duration , or a list of the lagged frames, was given. Is there a different component I should insert this into? Do I insert this component into the “get speech” tab or “the end” tab? Thanks!

Hi @ccjewell,

I would recommend going to this link: https://www.youtube.com/watch?v=r0z6lGhuaEY

It talks in detail about how to add a code component and how to write the codes too.

Hope this helps!