Table Of Contents

Previous topic

Line

Next topic

PatchStim (deprecated)

This Page

Quick links

MovieStim

Attributes

MovieStim(win[, filename, units, size, pos, ...]) A stimulus class for playing movies (mpeg, avi, etc...) in PsychoPy.
MovieStim.win The Window object in which the stimulus will be rendered
MovieStim.mask
MovieStim.units None, ‘norm’, ‘cm’, ‘deg’ or ‘pix’
MovieStim.pos The position of the center of the stimulus in the stimulus units
MovieStim.ori The orientation of the stimulus (in degrees).
MovieStim.size The size (w,h) of the stimulus in the stimulus units
MovieStim.opacity Determines how visible the stimulus is relative to background
MovieStim.name The name of the object to be using during logged messages about this stim.
MovieStim.autoLog Whether every change in this stimulus should be logged automatically
MovieStim.draw([win]) Draw the current frame to a particular visual.Window (or to the
MovieStim.autoDraw Determines whether the stimulus should be automatically drawn on
MovieStim.loadMovie(filename[, log]) Load a movie from file
MovieStim.play([log]) Continue a paused movie from current position
MovieStim.seek(timestamp[, log]) Seek to a particular timestamp in the movie.
MovieStim.pause([log]) Pause the current point in the movie (sound will stop, current frame will not advance).
MovieStim.stop([log]) Stop the current point in the movie (sound will stop, current frame will not advance).
MovieStim.setFlipHoriz([newVal, log]) If set to True then the movie will be flipped horizontally (left-to-right).
MovieStim.setFlipVert([newVal, log]) If set to True then the movie will be flipped vertically (top-to-bottom).

Details

class psychopy.visual.MovieStim(win, filename='', units='pix', size=None, pos=(0.0, 0.0), ori=0.0, flipVert=False, flipHoriz=False, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, volume=1.0, name='', loop=False, autoLog=True, depth=0.0)

A stimulus class for playing movies (mpeg, avi, etc...) in PsychoPy.

Example:

mov = visual.MovieStim(myWin, 'testMovie.mp4', flipVert=False)
print mov.duration
print mov.format.width, mov.format.height #give the original size of the movie in pixels

mov.draw() #draw the current frame (automagically determined)

See MovieStim.py for demo.

Parameters:
filename :

a string giving the relative or absolute path to the movie. Can be any movie that AVbin can read (e.g. mpeg, DivX)

flipVert : True or False

If True then the movie will be top-bottom flipped

flipHoriz : True or False

If True then the movie will be right-left flipped

volume :

The nominal level is 1.0, and 0.0 is silence, see pyglet.media.Player

loop : bool, optional

Whether to start the movie over from the beginning if draw is called and the movie is done.

autoDraw None

Determines whether the stimulus should be automatically drawn on

Value should be: True or False

You do NOT need to set this on every frame flip!

autoLog None

Whether every change in this stimulus should be logged automatically

Value should be: True or False

Set this to False if your stimulus is updating frequently (e.g. updating its position every frame) or you will swamp the log file with messages that aren’t likely to be useful.

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

Determines 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 blob) then this is not accounted for by the contains method; the extent of the stmulus is determined purely by the size, pos and orientation settings (and by the vertices for shape stimuli).

See coder demo, shapeContains.py

depth None

Deprecated. Depth is now controlled simply by drawing order.

draw(win=None)

Draw the current frame to a particular visual.Window (or to the default win for this object if not specified). The current position in the movie will be determined automatically.

This method should be called on every frame that the movie is meant to appear

loadMovie(filename, log=True)

Load a movie from file

Parameters:
filename: string

The name of the file, including path if necessary

Brings up a warning if avbin is not found on the computer. After the file is loaded MovieStim.duration is updated with the movie duration (in seconds).

name 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!

type: String

Example:

upper = visual.TextStim(win, text='Monty', name='upperStim')
lower = visual.TextStim(win, text='Python', name='lowerStim')
upper.setAutoDraw(True)
for frameN in range(3):
    win.flip()
# turn off top and turn on bottom
upper.setAutoDraw(False)
lower.setAutoDraw(True)
for frameN in range(3):
    win.flip()
# log file will include names to identify which stim came on/off
opacity None

Determines how visible the stimulus is relative to background

The value should be a single float ranging 1.0 (opaque) to 0.0 (transparent). Operations are supported.

Precisely how this is used depends on the Blend Mode

ori None

The orientation of the stimulus (in degrees).

Should be a single value (scalar). Operations are supported.

Orientation convention is like a clock: 0 is vertical, and positive values rotate clockwise. Beyond 360 and below zero values wrap appropriately.

overlaps(polygon)

Determines 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 only approximate; it can fail with pointy shapes. Returns True if the two shapes overlap.

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

pause(log=True)

Pause the current point in the movie (sound will stop, current frame will not advance). If play() is called again both will restart.

play(log=True)

Continue a paused movie from current position

pos None

The position of the center of the stimulus in the stimulus units

Value should be an x,y-pair. Operations are also supported.

Example:

stim.pos = (0.5, 0)  # Set slightly to the right of center
stim.pos += (0.5, -1)  # Increment pos rightwards and upwards. Is now (1.0, -1.0)
stim.pos *= 0.2  # Move stim towards the center. Is now (0.2, -0.2)

Tip: if you can see the actual pixel range this corresponds to by looking at stim._posRendered

seek(timestamp, log=True)

Seek to a particular timestamp in the movie. NB this does not seem very robust as at version 1.62 and may cause crashes!

setAutoDraw(val, log=True)

Add or remove a stimulus from the list of stimuli that will be automatically drawn on each flip

Parameters:
  • val: True/False

    True to add the stimulus to the draw list, False to remove it

setAutoLog(value=True)

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

setContrast()

Not yet implemented for MovieStim

setDKL(newDKL, operation='')

DEPRECATED since v1.60.05: Please use the color attribute

setDepth(newDepth, operation='', log=True)

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

setFlipHoriz(newVal=True, log=True)

If set to True then the movie will be flipped horizontally (left-to-right). Note that this is relative to the original, not relative to the current state.

setFlipVert(newVal=True, log=True)

If set to True then the movie will be flipped vertically (top-to-bottom). Note that this is relative to the original, not relative to the current state.

setLMS(newLMS, operation='')

DEPRECATED since v1.60.05: Please use the color attribute

setMovie(filename, log=True)

See ~MovieStim.loadMovie (the functions are identical). This form is provided for syntactic consistency with other visual stimuli.

setOpacity(newOpacity, operation='', log=True)

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

setOri(newOri, operation='', log=True)

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

setPos(newPos, operation='', log=True)

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

setRGB(newRGB, operation='')

DEPRECATED since v1.60.05: Please use the color attribute

setSize(newSize, operation='', units=None, log=True)

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

setUseShaders(value=True)

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

size None

The size (w,h) of the stimulus in the stimulus units

Value should be x,y-pair, scalar (applies to both dimensions) or None (resets to default). Operations are supported.

Sizes can be negative (causing a mirror-image reversal) and can extend beyond the window.

Example:

stim.size = 0.8  # Set size to (xsize, ysize) = (0.8, 0.8), quadratic.
print stim.size  # Outputs array([0.8, 0.8])
stim.size += (0.5, -0.5)  # make wider and flatter. Is now (1.3, 0.3)

Tip: if you can see the actual pixel range this corresponds to by looking at stim._sizeRendered

stop(log=True)

Stop the current point in the movie (sound will stop, current frame will not advance). Once stopped the movie cannot be restarted - it must be loaded again. Use pause() if you may need to restart the movie.

units None

None, ‘norm’, ‘cm’, ‘deg’ or ‘pix’

If None then the current units of the Window will be used. See Units for the window and stimuli for explanation of other options.

Note that when you change units, you don’t change the stimulus parameters and it is likely to change appearance. Example:

# This stimulus is 20% wide and 50% tall with respect to window
stim = visual.PatchStim(win, units='norm', size=(0.2, 0.5)

# This stimulus is 0.2 degrees wide and 0.5 degrees tall.
stim.units = 'deg'
useShaders None

Should shaders be used to render the stimulus (typically leave as True)

If the system support the use of OpenGL shader language then leaving this set to True is highly recommended. If shaders cannot be used then various operations will be slower (notably, changes to stimulus color or contrast)

verticesPix None

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

win None
The Window object in which the stimulus will be rendered
by default. (required)

Example, drawing same stimulus in two different windows and display simultaneously. Assuming that you have two windows and a stimulus (win1, win2 and stim):

   stim.win = win1  # stimulus will be drawn in win1
   stim.draw()  # stimulus is now drawn to win1
   stim.win = win2  # stimulus will be drawn in win2
   stim.draw()  # it is now drawn in win2
   win1.flip(waitBlanking=False)  # do not wait for next monitor update
   win2.flip()  # wait for vertical blanking.

Note that this just changes **default** window for stimulus.
You could also specify window-to-draw-to when drawing::

   stim.draw(win1)
   stim.draw(win2)