PsychoPy imprecise synchronization between stimulus and mask

44 views Asked by At

I am designing an experiment where, in each trial loop, an ImageStim is randomly drawn from a set of ~200 photos (each about 140kb) in a folder. ImageStim would start at 0.0 local trial time, and last for 150ms. At +0.1(100ms) local trial time, an ImageMask is drawn to overlay ImageStim and lasts for 200ms. We only used one photo for the mask. The result would be an ImageStim with the duration of 100ms and an ImageMask with the same duration.

After piloting, I noticed some weird synchronization issues where, for a small number of trials, ImageStim would appear to last very shortly where my eyes could not perceive them very well. So I calculated ImageStim durations (Mask onset - Stim onset), etc., but unexpectedly found that our ImageStim only appeared for ~75ms on average of all trials. StimDuration & StimOnset

I also calculated Stim durations from a prior version of the experiment where there is no ImageMask, and found them to be very accurate.

I realized that this is due to a ~25ms delay to ImageStim onset at the start of every trial, probably mainly due to the time it takes to randomly select one image to present out of the 200. PsychoPy's default timing system also only allowed me to set ImageMask onset time relative to trial start time, so it is not taking into account of ImageStim's actual onset time.

I end up writing customized code to set ImageMask's onset time to be exactly 100ms after ImageStim, but now there is a delay to ImageMask's onset time so that ImageStim's average duration is ~113ms (SD = 0.3).

I am wondering if anyone else who is doing/has done similar experiments on PsychoPy faced this problem, is there any other way to fix it, or if you are aware of any articles where they reported actual stimulus duration to differ from target duration in their Methods section. I swear I came across several articles a while ago who did that, but now I am having a hard time locating them.

1

There are 1 answers

0
Jon On

The answer is that, yes your stimulus is probably starting late due to the time loading the image from disk, if it's being loaded on every trial, so you need to think carefully about when the image is loaded.

PsychoPy supports a way to handle this by allowing you to load your stimulus at a specific time in a Static Component (that is a period where you know that the screen won't be changing like an inter-trial interval and so PsychoPy can go and do other tasks without missing a stimulus update). https://www.psychopy.org/builder/components/static.html

Other solutions, if you don't have any blank periods between trials, would be:

  • set the stimulus to have a fixed duration rather than fixed end time (so PsychoPy will take the actual start time into account). The start will be delayed by however long is required to load the image but will last the correct time. Then set the mask stimulus to start with a condition that stim.status==FINISHED so that it also starts at the right time after the stimulus
  • pre-load all your images in advance (but this requires a code snippet and you should only do it if you know they all fit on your graphics card memory)