pulse2percept.plotting.comparison

plot_stimulus_percept(),

play_stimulus_percept()

Views that span more than one object: what went into the model next to what came out of it.

Functions

play_stimulus_percept(stim, percept[, fps, ...])

Animate a stimulus next to the percept it produced

plot_stimulus_percept(stim, percept[, axes, ...])

Plot an image next to the percept it produced

pulse2percept.plotting.comparison.play_stimulus_percept(stim, percept, fps=None, axes=None, figsize=None, titles=('Stimulus', 'Percept'), repeat=True, annotate_time=True, colorbar=True, fmt='png', vmin=None, vmax=None)[source]

Animate a stimulus next to the percept it produced

Both panels run off a single clock. The percept’s time axis is authoritative: every displayed percept frame is paired with the source frame that is up at the same physical time (zero-order hold), so a source and a percept sampled at different rates stay in register, and a still image stays put. fps resamples the whole presentation, exactly as in play().

Added in version 0.11.0.

Parameters:
  • stim (ImageStimulus or) – VideoStimulus The image or video that went into the model, not the electrical stimulus an encoder made of it.

  • percept (Percept) – The percept the model predicted. Must have a time axis.

  • fps (float, optional) – Display frame rate in Hz. If None, use the percept’s recorded timing. May also be given as a unitful frequency (e.g., 30 * Hz).

  • axes (list of two matplotlib.axes.Axes, optional) – Axes to animate in, stimulus first. If None, a new figure is created.

  • figsize ((width, height), optional) – Size of that new figure (in inches). Ignored if axes is given.

  • titles ((str, str), optional) – Titles for the two panels.

  • repeat (bool, optional) – Whether to repeat the animation.

  • annotate_time (bool, optional) – Whether to show the current time above the two panels.

  • colorbar (bool, optional) – Whether to show a brightness colorbar next to the percept. An RGB percept never gets one.

  • fmt ({'png', 'jpg'}, optional) – Image format used to encode animation frames. ‘jpg’ keeps notebooks and doc pages smaller, which matters most for a video source; ‘png’ keeps the frames pixel-exact.

  • vmin (float, optional) – Brightness limits for the percept. By default, vmin=0 and vmax is the maximum brightness across the percept. Not available for an RGB percept, whose values are shown as they are.

  • vmax (float, optional) – Brightness limits for the percept. By default, vmin=0 and vmax is the maximum brightness across the percept. Not available for an RGB percept, whose values are shown as they are.

Returns:

ani – The animation.

Return type:

HTMLAnimation

Notes

Neither stimulus nor percept is resampled: the source keeps its own frames, and fps only controls which of them are shown when.

pulse2percept.plotting.comparison.plot_stimulus_percept(stim, percept, axes=None, figsize=None, titles=('Stimulus', 'Percept'), stim_kwargs=None, percept_kwargs=None)[source]

Plot an image next to the percept it produced

Draws stim and percept side by side, each with its own plot method. A video has no single frame that stands for the whole sequence, and neither does the percept it produced, so use play_stimulus_percept() for those.

Added in version 0.11.0.

Parameters:
  • stim (ImageStimulus) – The image that went into the model, not the electrical stimulus an encoder made of it.

  • percept (Percept) – The percept the model predicted.

  • axes (list of two matplotlib.axes.Axes, optional) – Axes to draw into, stimulus first. If None, a new figure is created.

  • figsize ((width, height), optional) – Size of that new figure (in inches). Ignored if axes is given.

  • titles ((str, str), optional) – Titles for the two panels.

  • stim_kwargs (dict, optional) – Passed on to the stimulus’ and the percept’s plot method.

  • percept_kwargs (dict, optional) – Passed on to the stimulus’ and the percept’s plot method.

Returns:

axes – The two Axes that were drawn into.

Return type:

np.ndarray of matplotlib.axes.Axes

Examples

>>> import matplotlib
>>> matplotlib.use('Agg')
>>> import pulse2percept as p2p
>>> stim = p2p.stimuli.samples.logo_ucsb(resize=(24, 32))
>>> model = p2p.models.retina.ScoreboardModel(
...     p2p.implants.retina.ArgusII(), xrange=(-4, 4), yrange=(-4, 4),
...     step=0.5)
>>> percept = model.predict_percept(stim)
>>> axes = p2p.plotting.plot_stimulus_percept(stim, percept)
>>> [ax.get_title() for ax in axes]
['Stimulus', 'Percept']