psychopy.org | Reference | Downloads | Github

Can you use more than one win.callOnFlip command per routine

I am just wondering if any know whether it affects time precision to use multiple win.callOnFlip commands at the start of a routine. I want to execute the following commands at the start of each trial to send a trigger to my EEG software when the stimulus appears on screen, and record the UNIX time the trigger is sent in psychopy. I need to record the UNIX time the trigger is sent so I can compare with the UNIX time the trigger is received by the EEG software and check that the delay between triggers being sent and received is consistent across the experiment.

win.callOnFlip(thisExp.addData, “trigger”, time.time() )
win.callOnFlip(outlet.push_sample, x = [marker])

Does anyone know if it is okay to use multiple callOnFlip commands?

If you’re worried about timing in this case, you could make a function which calls both of the two methods (time.time and outlet.push_sample). Any code of callOnFlip will then only be called once.

If you’re worried about timing, you could check the time your two function calls (time.time and outlet.push_sample) take with the timeit package.

Just out of curiosity, why are you using the time package and not the Psychopy psychopy.clock timing methods?

Thanks for your response. That sounds like a good solution, although I am not very confident in python so I have never written a function before, but can certainly investigate it.

I ended up using the time package because this was the only way I could figure out to get PsychoPy to record the timing of the triggers in UNIX time, which I needed to work out the absolute delay between the time when triggers are sent by PsychoPy and received by the EEG software.

I definitely a beginner using PsychoPy Coder so am always open to suggestions.

Feel free to ask any questions you have. Basically, your function definition at the beginning of your experiment would look something like:

def myFunction(thisExp, outlet, marker):
    thisExp.addData('trigger', time.time())
    outlet.push_sample(x = [marker])

Then you could call this function instead of your two calls:

win.callOnFlip(myFunction, thisExp, outlet, marker)