How do I call values from two different lists, in pairs, to specify parameters of two sequential stimuli in Python?

I'm quite new to Pyhon, so I apologize beforehand if this is a very simple or obvious thing to do or if it turns out to be too long of a question.

I'm trying to code an experiment through PsychoPy where, on each trial, I present two sequential stimuli for a given duration each, both separated by an Inter Stimulus Interval. Now, in order to specify the duration, I'm using the wait() function and had successfully done so before, on single-stimulus trials, by calling the values from a list, however, this time around I'm using a different list for each stimulus:

FSTIMDUR = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2]
SSTIMDUR = [1.5, 2.25, 3.0, 3.75, 4.5, 5.25, 6]

That being said, what I want to do is to make the first stimulus appear for a duration corresponding to the first element of the FSTIMDUR list (0.5 seconds, that is), then allow for an ISI to pass, and then present the second stimulus for a duration corresponding to the first element of the SSTIMDUR list (1.5 seconds), for one trial. On subsequent trials I'd like to present the rest of the stimuli the same way, calling the duration of each by pairs coming from both lists in order (0.75 and 2.25 for the second trial, 1.0 and 3.0 for the third and so on.

As an example, here's a bit of code that does what I want to do, but does it in an inconvenient way and requires me to write a similar bit for each combination of durations since it does not rely on calling values from lists:

# TOTAL STIMULUS DURATION (2s, 0.5:1.5)

# draw the fixation stimulus
fixstim.draw()
fixonset = disp.flip()
wait(FIXTIME)
# draw the sample stimulus 1
probstim.draw()
probonset = disp.flip()
wait(0.5)
# allow for an ISI to pass
isi = disp.flip()
wait(ISI)
# draw the sample stimulus 2
probstim.draw()
probonset = disp.flip()
wait(1.5)

Upvotes: 0

Views: 66

Answers (1)

sehigle
sehigle

Reputation: 332

 for ftime, stime in zip(FSTIMDUR,SSTIMDUR):
    fixstim.draw()
    fixonset = disp.flip()
    wait(FIXTIME)
    # draw the sample stimulus 1
    probstim.draw()
    probonset = disp.flip()
    wait(ftime)
    # allow for an ISI to pass
    isi = disp.flip()
    wait(ISI)
    # draw the sample stimulus 2
    probstim.draw()
    probonset = disp.flip()
    wait(stime)

This should work like you want, if I get your problem right.

Upvotes: 2

Related Questions