Adding offset times for stimuli that last till the end of the routine

I want to add offset times for a stimulus which stays on the screen until the end of the routine. As you may know, the offset times are recorded only if the stimulus goes off the screen during the routine. For routines which keep the stimulus on till the end, offset times are not recorded.

So far, to get offset times I have been using the onset of the next stimulus (the next routine), but this is not the most viable option (during analysis, it makes things confusing).

So I tried putting a stimulus component to the very beginning of my experiment, and took it as a time reference, the time_reference here is a text component.

time_ref = time_reference.tStartRefresh
def getTimeStamp():
    return time_ref + globalClock.getTime()

And then I use this to receive the offset time (I place the code to the end of the routine) assume the stimulus component I want to save the offset is “some_text” so, the offset would be:


Doing this, I assume I can get accurate offset times. But it turns out that taking the onset of the next stimulus in the next routine is faster (it gives a smaller value), on average a ~20ms difference happens between the measurement of my custom offset code and the onset of the next stimulus.

This is not a huge difference, but as you can see it is not strictly accurate either. It would be a nice feature to have the opportunity to save offset times even if they last till the end of the routine.

EDIT: Oh wait, is it because I am not subtracting frameTolerance from my timestamp?

Hi There,

Do you want the offset to be stored relative to the start of the routine or relative to the start of the experiment? if the start of the routine is there a reason that you couldn’t use this in a code component in the End Routine tab?

thisExp.addData('routine_end_time', t)


Thank you for your response Becca.

I am looking for a neat way of implementing the offset relative to the experiment start, just like how the onsets are on the data sheet. So your solution won’t help me much, I would need to add t to the value of stimulus onset – again, that’s not what I want. I want a neater way.

This is primarily because the code I write to generate event files for fMRI. It will be much more readable and less confusing and I don’t need to bother myself with other components to get the offset of a stimulus.

However, I noticed that this yields is a little more accurate timings than my previous attempt:

def getTimeStamp():
    return tThisFlipGlobal

Let me know if you have a better solution. Otherwise I’ll just stick to this one.

Can you define a custom clock in the first routine?

myClock = core.Clock()

and then save the value whenever you need to.

thisExp.addData(‘Timeline’, myClock.getTime())