spyder (4.0.1, python 3.6), psychopy (v3.0)
I’d like to present N = 2, 4, 6 (set size randomly varies from trial to trial) stimuli located on an imaginary circle. The idea (possibly not very good) was to use the current trial’s nStim as the number of randomly generated angles (thetas). Fixation screen and possibly fixation point from the encoding display are present. The gratings are not generated. Specifically, it stops at the fixation point and waits there (still running) until it self-terminates.
With focus on the relevant parts:
nStim = [2,4,6] # trial list
stim_ecc = 7 # deg
stimN = visual.GratingStim(win, sf=1, size=4, tex='sin', mask='gauss', # create generic stim and only update attributes later
ori=0)
trials = data.TrialHandler(nStim, nReps = 5, # n repeats for all conditions
method='random',
seed=None,
autoLog=True)
exp.addLoop(trials)
totalTrialCnt = 0
thisTrial = trials.nStim[0] # to initialise stimuli with some values
for thisTrial in trials:
if nStim == 2:
current_N = 2
elif nStim == 4:
current_N = 4
else:
current_N = 6
theta = numpy.linspace(0, 2*numpy.pi, **current_N**, retstep=True) # evenly spaced
rho = stim_ecc
stim_vec = {1:current_N}
for i in stim_vec:
def pol2cart(rho, theta):
x = rho*np.cos(theta)
y = rho*np.sin(theta)
return(x, y)
stimN(i).setPos([x, y])
stimN(i).draw()
win.flip()
core.wait(0.7)
trials.next()
exp.nextEntry()
Error:
Traceback (most recent call last):
File "C:\Users\username\Dropbox\trial_handler.py", line 131, in <module>
trials.next() # in which order?
File "C:\Users\username\Anaconda3\envs\psychopy\lib\site-packages\psychopy\data\trial.py", line 350, in __next__
self._terminate()
File "C:\Users\username\Anaconda3\envs\psychopy\lib\site-packages\psychopy\data\base.py", line 115, in _terminate
raise StopIteration
StopIteration
Maybe the calculation time takes longer than the duration of the display (.7 sec)? Or there is an issue in the writing part i don’t see/don’t know.
After uncommenting thisTrial = trials.nStim[0] line there is error:
AttributeError: 'TrialHandler' object has no attribute 'nStim'
So possibly the problem is with the way the ‘conditions’ were added.
Thanks!