ElementArrayStim

863 views
Skip to first unread message

Marco Maas

unread,
Dec 15, 2010, 9:23:16 PM12/15/10
to psychopy-users
I get an error when i want to try ElementArrayStim. I want to use a
Nx1 array for the Size of the elements and then i get an error. Below
my code and the errormessage:


mon = monitors.Monitor('program')
pixsize = misc.deg2pix(6,mon)
globForm = visual.ElementArrayStim(win, fieldPos=(0.0,0.0),
fieldSize=pixSize, fieldShape = 'circle', nElements=50,sizes=[[10]
[20]],sfs=3, elementTex=None, elementMask=None)


---------------------------------------------------
File "C:\Users\Marco\Documents\My Dropbox\Python\distractor\test
\elementArrays.py", line 32, in <module>
globForm = visual.ElementArrayStim(win, fieldPos=(0.0,0.0),
fieldSize= fieldSize, fieldShape = 'circle', nElements=N,sizes=[[10]
[20]],sfs=3, elementTex=None, elementMask=None)
IndexError: list index out of range


thank you.

Further question in this case, is it possible with the depth
parameter, to draw two stimuli in the same position, and one overlap
the other? The documentation give not so much information, how to use
this parameter. My first testing brought no results. Or if this not
work, has psychopy something implemented for masking? For example i
have an elementarraystim to present a star field in a square, but i
want to mask it, that i have only a circle with the stars as output
and the rest of the square is hidden?

best regards
Marco

Jonathan Peirce

unread,
Dec 16, 2010, 4:12:31 AM12/16/10
to psychop...@googlegroups.com

On 16/12/2010 02:23, Marco Maas wrote:
> I get an error when i want to try ElementArrayStim. I want to use a
> Nx1 array for the Size of the elements and then i get an error. Below
> my code and the errormessage:
>
>
> mon = monitors.Monitor('program')
> pixsize = misc.deg2pix(6,mon)
> globForm = visual.ElementArrayStim(win, fieldPos=(0.0,0.0),
> fieldSize=pixSize, fieldShape = 'circle', nElements=50,sizes=[[10]
> [20]],sfs=3, elementTex=None, elementMask=None)
>
>
> ---------------------------------------------------
> File "C:\Users\Marco\Documents\My Dropbox\Python\distractor\test
> \elementArrays.py", line 32, in<module>
> globForm = visual.ElementArrayStim(win, fieldPos=(0.0,0.0),
> fieldSize= fieldSize, fieldShape = 'circle', nElements=N,sizes=[[10]
> [20]],sfs=3, elementTex=None, elementMask=None)
> IndexError: list index out of range

ah, there's a bug that prevents that. Really easy to fix though in
visual.py:
go to ElementArrayStim.setSizes and change the line (around 3150?) from
if value.shape in [(),(1,)]:
to
if value.shape in [(),(1,),(2,)]:

After that fix, this works for me:

from psychopy import monitors, visual, misc, event
win=visual.Window([800,600])
globForm = visual.ElementArrayStim(win, fieldPos=(0.0,0.0),units='pix',
fieldSize=[800,600], fieldShape = 'circle',
nElements=50,sizes=[10,20],sfs=0, elementTex=None, elementMask=None)

globForm.draw()
win.flip()
event.waitKeys()

>
> thank you.
>
> Further question in this case, is it possible with the depth
> parameter, to draw two stimuli in the same position, and one overlap
> the other?

Yes, in theory, but things get strange when you have stimuli with alpha
masks because the depth system doesn't understand those. Better simply
to draw things that you want to appear on top (with a 'lower' depth)
after things that you want to appear obscured.


> The documentation give not so much information, how to use
> this parameter. My first testing brought no results. Or if this not
> work, has psychopy something implemented for masking? For example i
> have an elementarraystim to present a star field in a square, but i
> want to mask it, that i have only a circle with the stars as output
> and the rest of the square is hidden?

To create a circular field you should be able simply to set the
fieldShape='circle', as above.
But if you wanted, you could create an inverse circle as a mask and draw
it after (above) the element array:

from psychopy import filters
invCircle = filters.makeMask(512,'circle')*-1
maskStim = visual.PatchStim(win,tex=None,mask=invCircle, size=[1.0,1.0],
contrast=0)


all the best,
Jon

--
Dr. Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk/

Marco Maas

unread,
Dec 16, 2010, 9:41:54 PM12/16/10
to psychopy-users
thank you, the first works very fine.

but the second, here is my program code:

--------------------------------------
from psychopy import event, visual,monitors, misc, filters


#setup the Window
win = visual.Window(size=[1920, 1200 ], fullscr=True, screen=1,
allowGUI=False,
monitor='program', color=[0,0,0], colorSpace='rgb', units='deg')


elemSize = [1.5,6]

posis = []
for y in range(7,-8,-1):
for x in range (-7,8,1):
posis.append([x*11,y*11])
print posis

N = len(posis)

mon = monitors.Monitor('program')
pixsize = misc.deg2pix(6,mon)

invCircle = filters.makeMask(512,'circle')*-1
maskStim = visual.PatchStim(win,tex=None,mask=invCircle, size=6,color=
[-1,-1,-1] )


globForm = visual.ElementArrayStim(win, units='pix', fieldPos=(0,0),
fieldSize= pixsize, fieldShape = 'circle',
nElements=N,sizes=elemSize,sfs=3,
xys = posis, oris
= 45, elementTex= None, elementMask= None)



globForm.draw()
maskStim.draw()
win.flip()
event.waitKeys()

-----------------------------------------
i have the white rectangles where the filter appears, it seems that
elementarrystim has a priority in the depth level, or i understand
something completely wrong what you say before with the stacking of
things.

The third, yes with this mask will work, when the second going the
right way :). fieldshape='circle' i cannot use, because of the
specific coordinates i need to use for the stimuli

thank you
Marco

--
Marco Maas
BSI Riken, Tokyo

Marco Maas

unread,
Dec 16, 2010, 11:57:28 PM12/16/10
to psychopy-users
a new question in this context, is it possible to rotate a stimuli
produced with elementarrraystim. for example in this program

--------------------------
from psychopy import event, visual,monitors, misc, filters
import numpy #for maths on arrays
from numpy.random import random, shuffle #we only need these two
commands from this lib

#setup the Window
win = visual.Window(size=[1920, 1200 ], fullscr=True, screen=1,
allowGUI=False,
monitor='program', color=[0,0,0], colorSpace='rgb', units='deg')


elemSize = [0.05,0.2]

posisx = []
for y in range(28,-32,-4):
for x in range (-28,32,4):
if y != 0:
posisx.append([x/10.0,y/10.0])

Nx = len(posisx)

posisxd = []
for x in range (28,-32,-4):
posisxd.append([x/10.0,0])

Nxd = len (posisxd)

invCircle = filters.makeMask(512,'circle')*-1
maskStim = visual.PatchStim(win,tex=None,mask=invCircle, size=6,color=
[-1,-1,-1] )

globFormx = visual.ElementArrayStim(win, fieldPos=(0,0),
nElements=Nx,sizes=elemSize,
xys = posisx, oris
= 45, elementTex= None, elementMask=None, texRes=48)

globFormxd = visual.ElementArrayStim(win, fieldPos=(0,0),
nElements=Nxd,sizes=elemSize,
xys = posisxd,
oris = 90, elementTex= None, elementMask=None, texRes=48)

def makeCoherentOris(XYs, coherence, formAngle):
nNew = XYs.shape[0]#length along the first dimension
newOris = random(nNew)*180 #create a random array 0:180
#select some elements to be coherent
possibleIndices = range(nNew)#create an array of indices...
shuffle(possibleIndices) #...shuffle it'in-place' (without
creating a new array)...
coherentIndices = possibleIndices[0:int(nNew*coherence)]#...and
take first nnn elements
#set the ori of the coherent elements
theta, radius = misc.cart2pol(XYs[:,0], XYs[:,1]) #get polar
coordinates for elements
newOris[coherentIndices] = theta[coherentIndices]+formAngle
return newOris

coherence = 0.5

for x in range(5):
globFormx.setOris( makeCoherentOris(globFormx.xys, coherence,
45) )

globFormx.draw()
globFormxd.draw()
maskStim.draw()
win.flip()
event.waitKeys()
--------------------------------------

that i can rotate the stimuli 90 degrees.

thanks
Marco

-----------------------

Marco Maas

unread,
Dec 17, 2010, 1:22:31 AM12/17/10
to psychopy-users
i'm sorry but maybe i found another bug :)

x =np.array ([[-1, -0.5, 0, 1]])

#INITIALISE SOME STIMULI
gabor = visual.PatchStim(myWin,tex="sqr",mask=x,texRes=256,
size=[1.0,1.0], sf=[4,0],
ori = 0)

produce

File "C:\Program Files (x86)\PsychoPy2\lib\site-packages
\psychopy-1.62.01-py2.5.egg\psychopy\demos\coder\gabor.py", line 13,
in <module>
ori = 0)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages
\psychopy-1.62.01-py2.5.egg\psychopy\visual.py", line 1959, in
__init__
self.setMask(mask)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages
\psychopy-1.62.01-py2.5.egg\psychopy\visual.py", line 2018, in setMask
createTexture(value, id=self.maskID, pixFormat=GL.GL_ALPHA,
stim=self, res=self.texRes)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages
\psychopy-1.62.01-py2.5.egg\psychopy\visual.py", line 4532, in
createTexture
res=im.shape[1]
UnboundLocalError: local variable 'im' referenced before assignment

Jonathan Peirce

unread,
Dec 17, 2010, 6:40:57 AM12/17/10
to psychop...@googlegroups.com
You're right. On that line it should say tex.shape[1] rather than
im.shape[1]

But it's also kind of a strange thing to mask for a 2D PatchStim with a
one-dimensional array. That's why the bug has never been spotted before.

Jon

--

Dr. Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk/


This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

Marco Maas

unread,
Dec 17, 2010, 7:54:15 AM12/17/10
to psychopy-users
i was testing different kind of setting to get an effect :)

have you an idea about the questions before? :)

On Dec 17, 8:40 pm, Jonathan Peirce <jonathan.pei...@nottingham.ac.uk>
wrote:

Jonathan Peirce

unread,
Dec 17, 2010, 8:17:13 AM12/17/10
to psychop...@googlegroups.com

On 17/12/2010 12:54, Marco Maas wrote:
>
> have you an idea about the questions before? :)

about setting the orientation of the elementarray? You've obviously seen
the setOris method to set the ori of each element. There isn't a method
to alter the orientation of the whole array, but since you can set the
location and orientation of each element you can manage it that way I
guess? e.g. you could convert the XYs to polar coords, add an angle and
convert back.

By the way, I noticed you're using lots of loops. If you have a large
number of elements it will be worth moving that code to use numpy arrays
instead for speed.

Jon

Marco Maas

unread,
Dec 20, 2010, 2:34:34 AM12/20/10
to psychopy-users
i have now your new version of psychopy and i think i found another
error in elementarraystim, i never tried it in the 1.62.02 version.

setFieldPos() doesn't work for me:



globForm = visual.ElementArrayStim(win, units = 'deg',
fieldPos=(11,0), nElements=10,fieldSize = 6, sizes=0.2,
oris = 90,
elementTex= None, elementMask=None, texRes=48)

globForm.setFieldPos([0,0])

globForm.draw()

Jonathan Peirce

unread,
Dec 20, 2010, 7:48:40 AM12/20/10
to psychop...@googlegroups.com
You're right. It needs an extra line at the end of the setFieldPos
command to update the 'rendered position' (which is the position after
conversion to the screen's inherent coordinate system). That's now fixed
in the repository, but for now you can do it manually in your script for
now by calling
globForm._calcFieldCoordsRendered()
after each setFieldPos call.

thanks,
Jon

--

Reply all
Reply to author
Forward
0 new messages