psychopy.org | Reference | Downloads | Github

How to make an ITI + a set amount of time

I am trying to build a Dot Probe task in which a fixation cross gets shown for a random amount of time, afterwards two images appear for .1 second after which a dot appears on either the left or right side of the screen. Inputting the ITI and images is simple enough, however I cannot get the dot to appear at the right moment (either it appears over one of the images or too long after they have dissapeared).

the code for my ITI is:

import random

randomPractITI=random.randint(1000, 3000)
ITIPract = randomPractITI *0.001 

Is there a way to take this ITI and add .1 seconds to it so the dot appears on time?

Many thanks in advance!

This line should be deleted: you are over-writing an alternative random library that Builder already imports at the top of your script (i.e. you are replacing Builder’s imported random function from numpy.random with the Python standard library’s random package. Just make use of what Builder has already done for you at the top of the file:

from numpy.random import random, randint, normal, shuffle

i.e. call the random(), randint() etc functions directly.

Notre that you almost certainly don’t have a screen which supports millisecond-level time resolution. e.g. a typical display runs at 60 Hz, meaning 16.667 ms between screen refreshes. If that is the case, you might want to, say, choose intervals at a granularity of say 50 ms, which can be well represented by a 60 Hz screen, or a 100 Hz display, etc.

ITI_start = 1.0
ITI_duration = 2.0
granularity = 0.05 # 50 ms
ITIPract = ITI_start + randint(low = 0, high = int(ITI_duration/granularity)) * granularity

i.e. this will give you times at a resolution of 0.05 seconds, which would fit with the refresh rate of a 60 Hz screen.

Lastly, to control the timing of your other stimuli simply means adding a constant to the value of ITIPract, e.g. an expression like:

ITIPract + 0.1

Hi Michael,

Thanks a bunch for this very detailed reply! I am happy to report that this did solve my question and even some other trouble I was having! :smiley:

1 Like