Stimulus display error crashing an experiment

Hello,

An RA has been running a new experiment for me, and is randomly (approximately 1 in 6 times) obtaining the following (or similar) error messages upon presentation of the first trial:

pyo version 0.8.0 (uses single precision)
Traceback (most recent call last):
  File "C:\Users\tutor\Desktop\username\B1709\B1709D_2.py", line 499, in <module>
    win.flip()
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\window.py", line 568, in flip
    thisStim.draw()
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\shape.py", line 289, in draw
    vertsPix = self.verticesPix
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\basevisual.py", line 467, in verticesPix
    self._updateVertices()
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\visual\basevisual.py", line 502, in _updateVertices
    win=self.win, units=self.units)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\tools\monitorunittools.py", line 82, in convertToPix
    return unit2pixFunc(vertices, pos, win)
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\tools\monitorunittools.py", line 22, in _pix2pix
    return pos + vertices
ValueError: operands could not be broadcast together with shapes (8711696,) (32,2) 

The error is always occurring on a “win.flip()” command, but not always with the same stimulus (sometimes it’s at the point where the fixation cross is presented, sometimes it’s an array of memory stimuli, and sometimes it’s presentation of a test item). Based on the content of the error messages, and some stumbling around I have done in monitorunittools.py, I’m assuming the problem lies in a conversion of some value to pixels, but I haven’t been able to figure out why or how to fix it. Has anyone come across a similar problem before? If so, did you find a solution? Or do you have any suggestions for how I might be able to find the source of the problem?

Some relevant details:

  • When the error doesn’t appear (i.e., on the other 5 out of 6 occasions), the experiment runs perfectly
  • The PsychoPy version that the program is running under is 1.84.2, on Windows (10, I think)
  • The monitor display resolution is 1920*1080, and the experiment is running full-screen
  • The stimuli I’m displaying aren’t anything out of the ordinary. For instance, the fixation stimulus is specified as
    fixation = visual.TextStim(win=win, ori=0, name='fixation', text='+', font='Arial', units='pix', pos=[0,0], height=25, wrapWidth=None, color=[-1,-1,-1], colorSpace='rgb', opacity=1, depth=0.0)
    The other stimuli that have been giving me problems are visual.Circle stimuli, with positions and sizes specified in pixels.
  • This has been happening on multiple identical lab computers.
  • I have run plenty of similar experiments in PsychoPy before (and a few on these computers/with these monitors), and have never had this problem previously.
  • My RA had our IT group update PsychoPy to 1.85.2 while I was away last week, but then had them re-install the older version again due to problems with recording audio (for which I see there is a solution in another thread). I am wondering whether a part of this updating/re-installing process has broken something.

Thanks in advance for any help you are able to give.

Could you show us the code you use to create/change your ShapeStim called thisStim. Given that the error message mentions it, I think that’s going to be pretty relevant! :wink:

Thanks for your reply. Unless I’m misunderstanding, I think “thisStim” is something that window.py is doing, rather than a stimulus I’ve created (at least, I don’t have “thisStim” anywhere in my code). The only stimuli I have created in the experimental program are of the type visual.textStim (for the fixation as above, and for instructions and error messages), and visual.Circle (for memory and probe stimuli). The code I’m using to create the circle stimuli is as follows:

stimuli = []
stimuli.append(visual.Circle(win=win, radius=75, units='pix', name='stim1', pos=possiblePositions[0], opacity=1, fillColor=[0,0,0], fillColorSpace='rgb255', lineWidth=0))
stimuli.append(visual.Circle(win=win, radius=75, units='pix', name='stim2', pos=possiblePositions[1], opacity=1, fillColor=[0,0,0], fillColorSpace='rgb255', lineWidth=0))
stimuli.append(visual.Circle(win=win, radius=75, units='pix', name='stim3', pos=possiblePositions[2], opacity=1, fillColor=[0,0,0], fillColorSpace='rgb255', lineWidth=0))
stimuli.append(visual.Circle(win=win, radius=75, units='pix', name='stim4', pos=possiblePositions[3], opacity=1, fillColor=[0,0,0], fillColorSpace='rgb255', lineWidth=0))

I’m setting their positions using the following code:

def calculateXYRad(radius, angle):
    temp = [0+radius*cos(angle), 0+radius*sin(angle)]
    return temp

stimDist = 250
possiblePositions = []
for step in range(4):
    possiblePositions.append(calculateXYRad(stimDist, step*pi/2))

This leads to stimuli that are displayed at 90-deg intervals on the circumference of an invisible circle with radius 250 pixels, centred at fixation. Note that I have used this code in previous experiments (with various values of stimDist, and various numbers of stimuli and distances between them) and not run into this problem.

My probe stimulus is identical to the above, but always presented centrally (i.e., at 0,0).

(Later on in the program, I give these stimuli different colour values on each trial, but given the error messages it seems unlikely to me that that’s the source of the problem.)

[Edit: The code I’m using to actually display these stimuli, prior to the win.flip() at which point the error is occurring, is:

fixation.setAutoDraw(True)

and

for stim in range(4):
    stimuli[stim].setAutoDraw(True)

]

OK, what you need to create is a “minimal working example” of the problem.

I just pieced together the various bits of your code to give me the script below. I ran it 20 times on an iMac and it never failed. So I’m guessing something else is the problem (or it’s something about your machine, which you could test by running the exact script below on that machine and seeing if it ever fails).

To create the minimal working example you need to keep migrating this (working) script to your (broken) one and see at what point the error starts occurring again. Once you’ve narrowed it down to a specific addition we might be able to help better.

The error message itself is indicating that the calculation of the vertices or position is broken; somewhere it’s being set to a very long array rather than

from psychopy import visual
from numpy import pi, sin, cos

def calculateXYRad(radius, angle):
    temp = [0+radius*cos(angle), 0+radius*sin(angle)]
    return temp

stimDist = 250
possiblePositions = []
for step in range(4):
    possiblePositions.append(calculateXYRad(stimDist, step*pi/2))
    
win = visual.Window()
fixation = visual.TextStim(win=win, ori=0, name='fixation', text='+', 
    font='Arial', units='pix', pos=[0,0], height=25, 
    wrapWidth=None, color=[-1,-1,-1], colorSpace='rgb', 
    opacity=1, depth=0.0)

stimuli = []
stimuli.append(visual.Circle(win=win, radius=75, units='pix', name='stim1', 
    pos=possiblePositions[0], opacity=1, fillColor=[0,0,0], fillColorSpace='rgb255', lineWidth=0))
stimuli.append(visual.Circle(win=win, radius=75, units='pix', name='stim2', 
    pos=possiblePositions[1], opacity=1, fillColor=[0,0,0], fillColorSpace='rgb255', lineWidth=0))
stimuli.append(visual.Circle(win=win, radius=75, units='pix', name='stim3', 
    pos=possiblePositions[2], opacity=1, fillColor=[0,0,0], fillColorSpace='rgb255', lineWidth=0))
stimuli.append(visual.Circle(win=win, radius=75, units='pix', name='stim4', 
    pos=possiblePositions[3], opacity=1, fillColor=[0,0,0], fillColorSpace='rgb255', lineWidth=0))
    
fixation.setAutoDraw(True)
for stim in range(4):
    stimuli[stim].setAutoDraw(True)
    
for frameN in range(60):
    win.flip()