Timing issues / Diverging durations from expected data

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

OS (e.g. Win10): Win7
PsychoPy version (e.g. 1.84.x): v2022.1.3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:
Hello everyone!

I’m trying to build an fMRI experiment in which a routine consists of a cue (displayed text = coloured fixation cross, 1 s), followed by the stimulus (an image, 8 s), a response window (displayed text = question mark, 4 s), and a jittered ITI (displayed text = fixation cross, duration 4 / 6 / 8 s).

What did you try to make it work?:
First attempt: At the beginning of the routine, I included a code element with

Begin Routine
ITIs = [4, 6, 8]

For the ITI fixation element, I specified $ITIs[0] as a duration.

This routine is repeated several times using the Loop option.

Second attempt: Instead of this, I specified the durations for the ITIs in an Excel sheet (which is actually better as this way, I can ensure that each of the three durations are used equally often when looping through the stimuli).

What specifically went wrong when you tried that?:
The durations for the ITI turn out to be about 0.2 s longer independent of whether I go with the first or the second attempt. More specifically, the durations for the cue match the expected 1 s (e.g. 0.999914947, 1.00003996, 1.000019064, 1.000011365, 1.000016131), the durations for the stimulus match the expected 8 s (e.g. 8.00018587, 8.000067456, 8.000078821, 8.00010595, 8.000068922), the durations for the response window match the expected 4 s (e.g. 3.999994867, 4.00004326, 4.000098251, 4.000069655, 4.00006489), but the durations for the ITI do not match the expected 4 / 6 / 8 s, but are about 0.2 s longer (e.g. 4.18341439, 6.166791313, 6.250049675, 8.183504209).

Now of course, I could subtract 0.2 s from the specified durations, but this is certainly not optimal as I have no idea whether it is always ~ 0.2 s. Another solution would be to wait for a trigger from the MRI scanner at the beginning of the routines to ensure that stimulus onsets happen roughly at the same time relative to the TR from the scanner (timing is not really critical in my case, but I would nonetheless prefer the onsets to roughly align with the TR, and accumulating 0.2 s are certainly not what I would like). However, why does this deviation occur in the first place? 0.2 s also seem to be huge in my opinion.

Thank you.

What timing method are you using here (time by secs, time by frames, by condition, etc.)? The natural debugging strategy is to look at what’s different in your ITI routine and the Routines where the timing is working. Are they using different timing strategies?

Thank you for the input. Time is always specified in seconds (no decimal places). After trying out a fixed duration for the ITI event I’ve noticed that the same effect remains, and on a different computer there is an ITI-specific deviation as well, although the deviation is not as large anymore (more like 0.13 to 0.14 s). Thus I guess the deviation depends on the system / processor speed, and it seems the ITI is affected due to being the last event in the routine (?).

Edit 1: When defining durations via onsets / offsets in frames, it is basically the same on the second computer (about 0.12 s for the ITI, about 0.016 s / thus approx. one frame for the other events).

Edit 2: I have defined a static component at the beginning of the routine following Static Component — PsychoPy v2022.2.0 , lasting for 60 frames like the cue, and I have adjusted the settings for the image “set during: Part1.ISI”. Now the deviance of the ITI is within the range of a frame. Funnily, now the deviation of the cue amounts to several frames too short (while for the ITI, the deviation had been too long).

Edit 3: Anyway. I probably gonna wait for a trigger at the beginning of each trial.