Previous topic

psychopy.visual - many visual stimuli

Next topic

BufferImageStim

This Page

Quick links

Aperture

class psychopy.visual.Aperture(win, size=1, pos=(0, 0), ori=0, nVert=120, shape='circle', units=None, name=None, autoLog=None)

Restrict a stimulus visibility area to a basic shape or list of vertices.

When enabled, any drawing commands will only operate on pixels within the Aperture. Once disabled, subsequent draw operations affect the whole screen as usual.

If shape is ‘square’ or ‘triangle’ then that is what will be used (obviously) If shape is ‘circle’ or None then a polygon with nVerts will be used (120 for a rough circle) If shape is a list or numpy array (Nx2) then it will be used directly as the vertices to a ShapeStim

See demos/stimuli/aperture.py for example usage

Author:2011, Yuri Spitsyn 2011, Jon Peirce added units options, Jeremy Gray added shape & orientation 2014, Jeremy Gray added .contains() option
autoDraw

Determines whether the stimulus should be automatically drawn on every frame flip.

Value should be: True or False. You do NOT need to set this on every frame flip!

autoLog

Whether every change in this stimulus should be logged automatically

Value should be: True or False. Set to False if your stimulus is updating frequently (e.g. updating its position every frame) and you want to avoid swamping the log file with messages that aren’t likely to be useful.

contains(x, y=None, units=None)

Returns True if a point x,y is inside the extent of the stimulus.

Can accept variety of input options:
  • two separate args, x and y

  • one arg (list, tuple or array) containing two vals (x,y)

  • an object with a getPos() method that returns x,y, such

    as a Mouse.

Returns True if the point is within the area defined by vertices. This method handles complex shapes, including concavities and self-crossings.

Note that, if your stimulus uses a mask (such as a Gaussian) then this is not accounted for by the contains method; the extent of the stimulus is determined purely by the size, position (pos), and orientation (ori) settings (and by the vertices for shape stimuli).

See coder demo, shapeContains.py

disable()

Use Aperture.enabled = False instead.

enable()

Use Aperture.enabled = True instead.

enabled

True / False. Enable or disable the aperture. Determines whether it is used in future drawing operations.

NB. The Aperture is enabled by default, when created.

name

String or None. The name of the object to be using during logged messages about this stim. If you have multiple stimuli in your experiment this really helps to make sense of log files!

If name = None your stimulus will be called “unnamed <type>”, e.g. visual.TextStim(win) will be called “unnamed TextStim” in the logs.

ori

Set the orientation of the Aperture.

This essentially controls a ShapeStim so see documentation for ShapeStim.ori.

Operations supported here as well as ShapeStim.

Use setOri() if you want to control logging and resetting.

overlaps(polygon)

Returns True if this stimulus intersects another one.

If polygon is another stimulus instance, then the vertices and location of that stimulus will be used as the polygon. Overlap detection is typically very good, but it can fail with very pointy shapes in a crossed-swords configuration.

Note that, if your stimulus uses a mask (such as a Gaussian blob) then this is not accounted for by the overlaps method; the extent of the stimulus is determined purely by the size, pos, and orientation settings (and by the vertices for shape stimuli).

See coder demo, shapeContains.py

pos

Set the pos (centre) of the Aperture. Operations supported.

This essentially controls a ShapeStim so see documentation for ShapeStim.pos.

Operations supported here as well as ShapeStim.

Use setPos() if you want to control logging and resetting.

posPix

The position of the aperture in pixels

setAutoDraw(value, log=None)

Sets autoDraw. Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

setAutoLog(value=True, log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

setOri(ori, needReset=True, log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message.

setPos(pos, needReset=True, log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

setSize(size, needReset=True, log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

size

Set the size (diameter) of the Aperture.

This essentially controls a ShapeStim so see documentation for ShapeStim.size.

Operations supported here as well as ShapeStim.

Use setSize() if you want to control 0logging and resetting.

sizePix

The size of the aperture in pixels

verticesPix

This determines the coordinates of the vertices for the current stimulus in pixels, accounting for size, ori, pos and units