pulse2percept.stimuli.psychophysics.bar

pulse2percept.stimuli.psychophysics.bar(width=1, direction=0, speed=0, offset=0, edge_width=0, contrast=1, fov=10, shape=(256, 256), time=None, mask=None)[source]

Moving bar

Rasterize a single bright bar of a given angular width, moving at a given speed and direction, and place it in a Scene.

The bar is a stripe perpendicular to the direction of motion, at 0.5 + contrast / 2 on a 0.5 - contrast / 2 background. Its center sits at offset + speed * t along the motion axis, measured from fixation, so offset is where it is at t = 0 and a given timestamp puts it in the same place no matter how the video is sampled.

This generator draws one bar; use grating() for periodic patterns.

Added in version 0.11.0.

Parameters:
  • width (float or Quantity, optional) – Angular width of the bar’s plateau, in dva (e.g. 0.5 * dva), measured across the direction of motion. Must resolve to at least two pixels.

  • direction (float or Quantity, optional) – Direction of motion, in degrees counterclockwise from the positive x axis (e.g. 90 * deg): 0 right, 90 up, 180 left, 270 down. The bar itself is perpendicular to it, so direction=0 is a vertical bar moving rightwards.

  • speed (float or Quantity, optional) – Speed along direction, in dva/s (e.g. 5 * dva / s), non-negative: direction alone says which way the bar moves. 0 leaves the bar stationary; any other speed requires time.

  • offset (float or Quantity, optional) – Signed position of the bar’s center at t = 0, in dva along the motion axis, measured from fixation.

  • edge_width (float or Quantity, optional) – Width in dva of the raised-cosine ramp added to either side of the plateau, over which the bar falls off to the background. The bar is width + 2 * edge_width across in total. 0 gives hard edges.

  • contrast (float, optional) – Michelson contrast in [0, 1] around mean gray 0.5: bar and background sit at 0.5 +/- contrast / 2.

  • fov (float or (width, height), optional) – How much of the visual field the scene covers, in dva. A scalar is the horizontal extent, and the vertical one follows from shape.

  • shape ((rows, cols), optional) – Size of the rasterized frame, in pixels. Raster resolution only: it does not enter the bar’s width or speed.

  • time (array_like or None, optional) – Sample times in ms (e.g. np.arange(0, 500, 10)), which the scene’s source carries as a VideoStimulus. None gives a static ImageStimulus instead, and is only allowed when speed is 0. There is no default frame rate, so a scalar duration is rejected.

  • mask ({'gauss', 'circle', None}, optional) –

    Radial aperture applied to the pattern, which fades to mean gray outside it. Isotropic in dva and centered on fixation:

    • 'gauss': a 2D Gaussian whose 3rd standard deviation lies at the aperture radius

    • 'circle': the largest circle that fits into fov

    • None: no aperture

Returns:

scene

Return type:

Scene

Examples

A static 1-degree bar, 3 degrees left of fixation:

>>> from pulse2percept.stimuli import psychophysics
>>> from pulse2percept.units import dva
>>> scene = psychophysics.bar(width=1 * dva, offset=-3 * dva,
...                           fov=10 * dva)
>>> type(scene.source).__name__
'ImageStimulus'

The same bar sweeping rightwards at 10 dva/s, sampled every 10 ms:

>>> import numpy as np
>>> from pulse2percept.units import s
>>> scene = psychophysics.bar(width=1 * dva, offset=-3 * dva,
...                           speed=10 * dva / s, fov=10 * dva,
...                           time=np.arange(0, 600, 10))
>>> type(scene.source).__name__
'VideoStimulus'