pulse2percept.implants.ensemble

EnsembleImplant

Classes

EnsembleImplant(implants[, stim, ...])

class pulse2percept.implants.ensemble.EnsembleImplant(implants, stim=None, preprocess=False, safe_mode=False)[source]
classmethod from_cortical_map(implant_type, vfmap, locs=None, xrange=None, yrange=None, step=None, region='v1')[source]

Create an ensemble implant from a cortical visual field map.

The implant will be created by creating an implant of type implant_type for each visual field location specified either by locs or by xrange, yrange, and step. Each implant will be centered at the given location.

Parameters:
  • vfmap (p2p.topography.CorticalMap) – Visual field map to create implant from.

  • implant_type (type) – Type of implant to create for the ensemble. Must subclass p2p.implants.ProsthesisSystem

  • locs (np.ndarray with shape (n, 2), optional) – Array of visual field locations to create implants at (dva). Not needed if using xrange, yrange, and step.

  • xrange (tuple of floats, optional) – Range of x and y coordinates (dva) to create implants at.

  • yrange (tuple of floats, optional) – Range of x and y coordinates (dva) to create implants at.

  • step (float or (x_step, y_step), optional) –

    Spacing (dva) between implant centers.

    Changed in version 0.10.0: Renamed from xystep, which suggested that one step size applies to both axes. The old name still works as a keyword argument, but is deprecated and will be removed in v0.11.0.

  • region (str, optional) – Region of cortex to create implant in.

Returns:

ensemble – Ensemble implant created from the cortical visual field map.

Return type:

p2p.implants.EnsembleImplant

Notes

  • These are visual field coordinates, so they may be given as plain numbers of degrees or as unitful quantities (e.g. xrange=(-3 * dva, 3 * dva)). Contrast from_coords(), which places implants by their physical position in microns. See pulse2percept.units.

classmethod from_coords(implant_type, locs=None, xrange=None, yrange=None, step=None)[source]

Create an ensemble implant using physical (cortical or retinal) coordinates.

Parameters:
  • implant_type (type) – The type of implant to create for the ensemble.

  • locs (np.ndarray with shape (n, 2), optional) – Array of physical locations (um) to create implants at. Not needed if using xrange, yrange, and step.

  • xrange (tuple of floats, optional) – Range of x and y coordinates (um) to create implants at. Required (together with step) if locs is not given.

  • yrange (tuple of floats, optional) – Range of x and y coordinates (um) to create implants at. Required (together with step) if locs is not given.

  • step (float or (x_step, y_step), optional) –

    Spacing (um) between implant centers.

    Changed in version 0.10.0: Renamed from xystep, which suggested that one step size applies to both axes. The old name still works as a keyword argument, but is deprecated and will be removed in v0.11.0.

Raises:

ValueError – If neither locs nor all three of xrange, yrange and step are given.

Notes

  • Lengths may be given as plain numbers of microns or as unitful quantities (e.g. xrange=(-1 * mm, 1 * mm)). See pulse2percept.units.

Changed in version 0.10.0: The grid arguments no longer have defaults. They used to fall back on (-3, 3) and 1, which are the degrees of visual angle from_cortical_map() works in; here they are microns, so the default laid every implant out inside a 6 um square.

property stim

Stimulus

A stimulus can be created from many source types, such as scalars, NumPy arrays, and dictionaries (see Stimulus for a complete list).

A stimulus can be assigned either in the ProsthesisSystem constructor or later by assigning a value to stim.

Note

Unless when using dictionary notation, the number of stimuli must equal the number of electrodes in earray.

Examples

Send a biphasic pulse (30uA, 0.45ms phase duration) to an implant made from a single DiskElectrode:

>>> from pulse2percept.implants import DiskElectrode, ProsthesisSystem
>>> from pulse2percept.stimuli import BiphasicPulse
>>> implant = ProsthesisSystem(DiskElectrode(0, 0, 0, 100))
>>> implant.stim = BiphasicPulse(30, 0.45)

Stimulate Electrode B7 in Argus II with 13 uA:

>>> from pulse2percept.implants import ArgusII
>>> implant = ArgusII(stim={'B7': 13})
check_stim(stim)[source]

Quality-check the stimulus

This method is executed every time a new value is assigned to stim.

If safe_mode is set to True, this function will only allow stimuli that are charge-balanced. If max_current is set, it will only allow stimuli whose total instantaneous current stays within it.

Both are questions about electricity, and neither can be answered about a stimulus that is not a current, so each raises a DimensionMismatchError on one. An implant that asks for neither does not run either check, which is why a dimensionless stimulus may still be assigned to one – preprocess has already had its chance to turn it into current, and if it did not, no safety claim is being made about it either.

The user can define their own checks in implants that inherit from ProsthesisSystem.

Parameters:

stim (Stimulus source type) – A valid source type for the Stimulus object (e.g., scalar, NumPy array, pulse train).

Raises:
  • DimensionMismatchError – If an electrical check was requested and stim is not measured in units of current.

  • .. versionchanged: – 0.10.0: The electrical checks verify that the stimulus really is electrical, instead of reading whatever numbers it holds as microamps.

property earray

Electrode array

property electrode_names

Return a list of all electrode names in the electrode array

property electrode_objects

Return a list of all electrode objects in the array

property electrodes

Return all electrode names and objects in the electrode array

Internally, electrodes are stored in an ordered dictionary. You can iterate over different electrodes in the array as follows:

for name, electrode in implant.electrodes.items():
    print(name, electrode)

You can access an individual electrode by indexing directly into the prosthesis system object, e.g. implant['A1'] or implant[0].

property eye

Implanted eye

A ProsthesisSystem can be implanted either in a left eye (‘LE’) or right eye (‘RE’). Models such as AxonMapModel will treat left and right eyes differently (for example, adjusting the location of the optic disc).

Examples

Implant Argus II in a left eye:

>>> from pulse2percept.implants import ArgusII
>>> implant = ArgusII(eye='LE')
property implants

Dict of implants

property max_current

Total instantaneous current (uA) the stimulator can source

property n_electrodes

Number of electrodes in the array

This is equivalent to calling earray.n_electrodes.

plot(annotate=False, autoscale=True, ax=None, stim_cmap=False)[source]

Plot

Parameters:
  • annotate (bool, optional) – Whether to scale the axes view to the data

  • autoscale (bool, optional) – Whether to adjust the x,y limits of the plot to fit the implant

  • ax (matplotlib.axes._subplots.AxesSubplot, optional) – A Matplotlib axes object. If None, will either use the current axes (if exists) or create a new Axes object.

  • stim_cmap (bool, str, or matplotlib colormap, optional) – If not false, the fill color of the plotted electrodes will vary based on maximum stimulus amplitude on each electrode. The chosen colormap will be used if provided

Returns:

ax – Returns the axis object of the plot

Return type:

matplotlib.axes.Axes

preprocess_stim(stim)[source]

Preprocess the stimulus

This methods is executed every time a new value is assigned to stim.

No preprocessing is performed by default, but the user can define their own method in implants that inherit from return stim ProsthesisSystem.

A custom method must return a Stimulus object with the correct number of electrodes for the implant.

Parameters:

stim (Stimulus source type) – A valid source type for the Stimulus object (e.g., scalar, NumPy array, pulse train).

Returns:

stim_out

Return type:

Stimulus object

property raster

Raster pattern

Most implants do not set this in their constructor, so the slot backing it may never have been written to; an unset raster means all electrodes may fire at once.

merge_stimuli()[source]

Constructs the combined stimulus for all implants in self._implants