In my code for a masked priming experiment, I have 4 routines:
- forward mask, 500ms long
- prime, 33 ms long
- backward mask, 17ms long
- target (not timed)
I’m checking if timing of each of the routines above is fine, but I’m facing some weird results.
For one of my routines (the prime), my code says the following:
# ------Prepare to start Routine "prime"------- t = 0 primeClock.reset() # clock frameN = -1 continueRoutine = True routineTimer.add(0.050000) # update component parameters for each repeat prime_txt.setText(prime) # keep track of which components have finished primeComponents = [prime_txt] for thisComponent in primeComponents: if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # -------Start Routine "prime"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = primeClock.getTime() frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *prime_txt* updates if t >= 0.0 and prime_txt.status == NOT_STARTED: # keep track of start time/frame for later prime_txt.tStart = t prime_txt.frameNStart = frameN # exact frame index prime_txt.setAutoDraw(True) frameRemains = 0.0 + .050- win.monitorFramePeriod * 0.75 # most of one frame period left if prime_txt.status == STARTED and t >= frameRemains: prime_txt.setAutoDraw(False) prime_txt.tEnd = t # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in primeComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # check for quit (the Esc key) if endExpNow or event.getKeys(keyList=["escape"]): core.quit() # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() # -------Ending Routine "prime"------- for thisComponent in primeComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) loop_warmup.addData('on_prime', prime_txt.tStart) loop_warmup.addData('off_prime', prime_txt.tEnd) loop_warmup.addData('t_prime', prime_txt.tEnd-prime_txt.tStart)
Basically, it’s the usual automated code from the Builder, with two additions (signaled with an arrow):
if prime_txt.status == STARTED and t >= frameRemains: prime_txt.setAutoDraw(False) prime_txt.tEnd = t <---- [...] for thisComponent in primeComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) loop_warmup.addData('on_prime', prime_txt.tStart) <--- loop_warmup.addData('off_prime', prime_txt.tEnd) <--- loop_warmup.addData('t_prime', prime_txt.tEnd-prime_txt.tStart) <---
When I run the code, I have a couple of issues:
- from time to time, the run would crash with the following error:
AttributeError: ‘TextStim’ object has no attribute ‘tEnd’
- In the csv file, the
't_prime'values appears to be lower than expected: about 25 ms, instead of the 33 ms that I would expect given the refresh rate of the monitor (60 Hz). At times, the
't_prime'values drastically drop (even close to 0 ms), with no apparent reason.
Weirdly enough, this happens only with the prime routine, while the timing for the masks are pretty stable.
Can anyone help figure out why this happens, and how to fix it?