I am using the psychopy code from this publication: "Using a variant of the optomotor response as a visual defect detection assay in zebrafish". The code is a series of while loops on a countdown. Each loop should run for 10 seconds. I want to add another countdown before the first 10 seconds loop that will last for 5 seconds and will just be a black screen.
The problem that I am having is that the first 5 seconds while loop (the black screen) is overlapping with the first 10 seconds while loop. This results in the first 10 second loop only lasting for 5 seconds. Oddly enough, the rest of the loops that are supposed to last for 10 seconds each are not overlapped or disturbed.
Does anyone have any ideas why this might be happening? I don't get any errors when I run my code.
Irrelevant note: I am planning on changing the times for each loop
#import libraries needed from PsychoPy
from psychopy import visual, core, event, sys
#create a window
mywin = visual.Window([1680,1050], monitor="testMonitor", units="deg", fullscr = True)
#To run the stimulus, "save" + "run"
#Create the black screen for acclimation
TIMEBLACK = 5
black = visual.GratingStim(win=mywin, size=999, pos=[0,0], sf=0, color=[-1,-1,-1])
blacktimer = core.CountdownTimer(TIMEBLACK)
#Create OMR Stimuli
TIME = 10 #this is seconds of stimulus display and should be changed based on experimental needs (See Table 2)
SPEED = 1.04 #1.033 is adult optimal, 1.04 is larvae optimal. See table for additional speeds; correlates to 12 angular cycles for adults and 16 angular cycles for larvae.
grating = visual.RadialStim(win=mywin, mask='circle', tex='saw',size=20, color=[1,1,1],pos=[0,0],angularCycles = 4, angularRes = 3600, contrast = -1.0) #angularCycles are the number of black/white bars presented by the stimulus. Adult optimal is 12 angular cycles, larvae optimal is 16 angular cycles (See Table 1).
fixation = visual.GratingStim(win=mywin, size=999, pos=[0,0], sf=0, color=[0.5,0.5,0.5])
timer = core.CountdownTimer(TIME)
while blacktimer.getTime()>0:
black.draw()
mywin.flip()
if len(event.getKeys())>0: sys.exit(0)
event.clearEvents()
blacktimer.reset(TIMEBLACK)
#draw the stimuli and update the window. The phase is always advanced by 0.05 of a cycle.
while True: #this creates a never-ending loop
while timer.getTime()>0:
grating.setAngularPhase(SPEED, '-')
grating.draw()
mywin.flip()
if len(event.getKeys())>0: sys.exit(0)
event.clearEvents()
timer.reset(TIME)
while timer.getTime()>0:
fixation.draw()
mywin.flip()
if len(event.getKeys())>0: sys.exit(0)
event.clearEvents()
timer.reset(TIME)
while timer.getTime()>0:
grating.setAngularPhase(SPEED, '+')
grating.draw()
mywin.flip()
if len(event.getKeys())>0: sys.exit(0)
event.clearEvents()
timer.reset(TIME)
while timer.getTime()>0:
fixation.draw()
mywin.flip()
if len(event.getKeys())>0: sys.exit(0)
event.clearEvents()
timer.reset(TIME)
if len(event.getKeys())>0: break
event.clearEvents()
#cleanup. To exit, press any key.
mywin.close()
core.quit()
Here are my updates after edits. I moved everything having to do with the black screen to be before the first 10 second while loop:
#Create the black screen for acclimation
TIMEBLACK = 5
black = visual.GratingStim(win=mywin, size=999, pos=[0,0], sf=0, color=[1,-1,-1])
blacktimer = core.CountdownTimer(TIMEBLACK)
while blacktimer.getTime()>0:
black.draw()
mywin.flip()
if len(event.getKeys())>0: core.quit(0)
blacktimer.reset(TIMEBLACK)
#Create OMR Stimuli
TIME = 10 #this is seconds of stimulus display and should be changed based on experimental needs (See Table 2)
SPEED = 1.04 #1.033 is adult optimal, 1.04 is larvae optimal. See table for additional speeds; correlates to 12 angular cycles for adults and 16 angular cycles for larvae.
grating = visual.RadialStim(win=mywin, mask='circle', tex='saw',size=20, color=[1,1,1],pos=[0,0],angularCycles = 4, angularRes = 3600, contrast = -1.0) #angularCycles are the number of black/white bars presented by the stimulus. Adult optimal is 12 angular cycles, larvae optimal is 16 angular cycles (See Table 1).
fixation = visual.GratingStim(win=mywin, size=999, pos=[0,0], sf=0, color=[0.5,0.5,0.5])
timer = core.CountdownTimer(TIME)
#draw the stimuli and update the window. The phase is always advanced by 0.05 of a cycle.
while True: #this creates a never-ending loop
while timer.getTime()>0:
grating.setAngularPhase(SPEED, '-')
grating.draw()
mywin.flip()
if len(event.getKeys())>0: core.quit(0)
timer.reset(TIME)