# Lagging gabor drifting in a multi apertures stimulus

Hello everyone,
I am programming a multigabor aperture stimulus just as shown in the figure below.

I tried to put hundreds of Gabor and, as I could expect, the stimulus is lagging. gabors are slowing down a lot.
To let you know how I coded it, you may find my code, I just coded the number of gabors I wanted.

``````import psychopy
from psychopy import visual, core, event  # import some libraries from PsychoPy
from random import randrange, choice, shuffle
from math import cos, radians, fabs

#Paramters

list_oriG = []
list_oriR = []
list_ori = []

n = 200 # Numbers of gabors

N = int(n*0) #Noise
S = int(n*1) # Signal

v = 0

for v in range(n):
v = 30
list_ori.append(v)

o = 0

for o in range(N):
o = randrange(0,360)
list_oriR.append(o)

for g in range(S):
g = -30
list_oriG.append(g)

list_oritot = list_oriG + list_oriR

shuffle(list_oritot)

list_rand = []

s = 0
a = 0

for a in range(n):
#s = cos(radians(list_oritot[0]) - radians(list_ori[a]))
s = 1
list_rand.append(s)

#create a window
mywin = visual.Window([1000,1000], monitor="testMonitor", units="deg")

#create some stimuli

fixation = visual.TextStim(win = mywin, text = "N", pos = (0.0,0.0), color=(1.0,0.0,0.0),colorSpace='rgb')

grating0= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-15], sf = 1.5)
grating1= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-14], sf = 1.5)
grating2= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-13], sf = 1.5)
grating3= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-12], sf = 1.5)
grating4= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-11], sf = 1.5)
grating5= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-10], sf = 1.5)
grating6= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-9], sf = 1.5)
grating7= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-8], sf = 1.5)
grating8= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-7], sf = 1.5)
grating9= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-6], sf = 1.5)
grating10= visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos =[-15,-5], sf = 1.5)
#..... Till grating200

grating0.setOri(list_ori[0])
grating1.setOri(list_ori[1])
grating2.setOri(list_ori[2])
grating3.setOri(list_ori[3])
grating4.setOri(list_ori[4])
grating5.setOri(list_ori[5])
grating6.setOri(list_ori[6])
grating7.setOri(list_ori[7])
grating8.setOri(list_ori[8])
grating9.setOri(list_ori[9])
grating10.setOri(list_ori[10])
#until grating200

while(1):

#phase
grating0.setPhase(list_rand[0]*0.01, '+')
grating1.setPhase(list_rand[1]*0.01, '+')
grating2.setPhase(list_rand[2]*0.01, '+')
grating3.setPhase(list_rand[3]*0.01, '+')
grating4.setPhase(list_rand[4]*0.01, '+')
grating5.setPhase(list_rand[5]*0.01, '+')
grating6.setPhase(list_rand[6]*0.01, '+')
grating7.setPhase(list_rand[7]*0.01, '+')
grating8.setPhase(list_rand[8]*0.01, '+')
grating9.setPhase(list_rand[9]*0.01, '+')
grating10.setPhase(list_rand[10]*0.01, '+')
grating11.setPhase(list_rand[11]*0.01, '+')
grating12.setPhase(list_rand[12]*0.01, '+')
grating13.setPhase(list_rand[13]*0.01, '+')
grating14.setPhase(list_rand[14]*0.01, '+')
grating15.setPhase(list_rand[15]*0.01, '+')
#until grating200

fixation.draw()

grating0.draw()
grating1.draw()
grating2.draw()
grating3.draw()
grating4.draw()
grating5.draw()
grating6.draw()
grating7.draw()
grating8.draw()
grating9.draw()
grating10.draw()
grating11.draw()
grating12.draw()
grating13.draw()
grating14.draw()
grating15.draw()
grating16.draw()
grating17.draw()
grating18.draw()
grating19.draw()
grating20.draw()
grating21.draw()
grating22.draw()
grating23.draw()
grating24.draw()
grating25.draw()
grating26.draw()
grating27.draw()
grating28.draw()
grating29.draw()
grating30.draw()
grating31.draw()
grating32.draw()
grating33.draw()
grating34.draw()
grating35.draw()
grating36.draw()
grating37.draw()
grating38.draw()
grating39.draw()
grating40.draw()
grating41.draw()
grating42.draw()
grating43.draw()
grating44.draw()
grating45.draw()
grating46.draw()
grating47.draw()
grating48.draw()
grating49.draw()
grating50.draw()
grating51.draw()
grating52.draw()
grating53.draw()
grating54.draw()
grating55.draw()
grating56.draw()
grating57.draw()
grating58.draw()
grating59.draw()
grating60.draw()
grating61.draw()
grating62.draw()
grating63.draw()
grating64.draw()
grating65.draw()
grating66.draw()
grating67.draw()
grating68.draw()
grating69.draw()
grating70.draw()
grating71.draw()
grating72.draw()
grating73.draw()
grating74.draw()
grating75.draw()
grating76.draw()
grating77.draw()
grating78.draw()
grating79.draw()
grating80.draw()
grating81.draw()
grating82.draw()
grating83.draw()
grating84.draw()
grating85.draw()
grating86.draw()
grating87.draw()
grating88.draw()
grating89.draw()
grating90.draw()
grating91.draw()
grating92.draw()
grating93.draw()
grating94.draw()
grating95.draw()
grating96.draw()
grating97.draw()
grating98.draw()
grating99.draw()
grating100.draw()
grating101.draw()
grating102.draw()
grating103.draw()
grating104.draw()
grating105.draw()
grating106.draw()
grating107.draw()
grating108.draw()
grating109.draw()
grating110.draw()
grating111.draw()
grating112.draw()
grating113.draw()
grating114.draw()
grating115.draw()
grating116.draw()
grating117.draw()
grating118.draw()
grating119.draw()
grating120.draw()
grating121.draw()
grating122.draw()
grating123.draw()
grating124.draw()
grating125.draw()
grating126.draw()
grating127.draw()
grating128.draw()
grating129.draw()
grating130.draw()
grating131.draw()
grating132.draw()
grating133.draw()
grating134.draw()
grating135.draw()
grating136.draw()
grating137.draw()
grating138.draw()
grating139.draw()
grating140.draw()
grating141.draw()
grating142.draw()
grating143.draw()
grating144.draw()
grating145.draw()
grating146.draw()
grating147.draw()
grating148.draw()
grating149.draw()
grating150.draw()
grating151.draw()
grating152.draw()
grating153.draw()
grating154.draw()
grating155.draw()
grating156.draw()
grating157.draw()
grating158.draw()
grating159.draw()
grating160.draw()
grating161.draw()
grating162.draw()
grating163.draw()
grating164.draw()
grating165.draw()
grating166.draw()
grating167.draw()
grating168.draw()
grating169.draw()
grating170.draw()
grating171.draw()
grating172.draw()
grating173.draw()
grating174.draw()
grating175.draw()
grating176.draw()
grating177.draw()
grating178.draw()
grating179.draw()
grating180.draw()
grating181.draw()
grating182.draw()
grating183.draw()
grating184.draw()
grating185.draw()
grating186.draw()
grating187.draw()
grating188.draw()
grating189.draw()
grating190.draw()
grating191.draw()
grating192.draw()
grating193.draw()
grating194.draw()
grating195.draw()
grating196.draw()
grating197.draw()
grating198.draw()
grating199.draw()
grating200.draw()

mywin.flip()

if len(event.getKeys()) > 0:
break
event.clearEvents()

mywin.close()
``````

Does anyone have already faced this issue?

Thanks a lot for your help !

OK perhaps some ways you could improve efficiency here - although it might still be lagging because it is alot to draw on every frame.

``````nGratings = 200
positions = []#populate this with your list of positions or provide a range of values to work through
gratingList = []

for i, position in enumerate(positions):
thisGrating = visual.GratingStim(win=mywin, mask = "gauss", size = 1, pos = position, sf = 1.5)
gratingList.append(thisGrating)

#when it comes to drawing
for grating in gratingList:
grating.draw()
``````

Alternatively you might want to consider checking out elementArrayStim this post might also be helpful? ElementArrayStim - updating and passing lists of parameters / stimuli? becca