pulse2percept.implants.retina.alpha
Classes
|
Alpha-AMS |
|
Alpha-IMS |
- class pulse2percept.implants.retina.alpha.AlphaIMS(z=0, eye='right', preprocess=True, safe_mode=False)[source]
Alpha-IMS
This class creates an Alpha-IMS array with 1500 photovoltaic pixels (each 50um in diameter) as described in [Stingl2013]. Electrode coordinates are device-local, centered on
(0, 0).The device consists of 1500 50um-wide square pixels, arranged on a 39x39 rectangular grid with 72um pixel pitch.
The array is oriented upright in the visual field, such that an array with center (0,0) has the top three rows lie in the lower retina (upper visual field).
An electrode can be addressed by name, row/column index, or integer index (into the flattened array).
Note
Column order is reversed in a left-eye implant.
- Parameters:
z (float, list, or Quantity, optional) – Electrode height (um) above the array’s own plane: a scalar applies to every electrode, a list of 1500 entries gives each its own. May be given as unitful quantities (e.g.
z=100 * um); seepulse2percept.units.eye ({'right', 'left'}, optional) – Eye in which array is implanted.
preprocess (bool or callable, optional) – Either True/False to indicate whether to execute the implant’s default preprocessing method whenever a stimulus is prepared, or a custom function (callable).
safe_mode (bool, optional) – If safe mode is enabled, only charge-balanced stimuli are allowed.
Examples
Create an Alpha-IMS array:
>>> from pulse2percept.implants.retina import AlphaIMS >>> AlphaIMS() AlphaIMS(electrode_array=ElectrodeGrid, eye='right', preprocess=True, safe_mode=False, shape=(39, 39))
Get access to the third electrode in the top row (by name or by row/column index):
>>> alpha_ims = AlphaIMS() >>> alpha_ims['A3'] SquareElectrode(activated=True, name='A3', side_length=50.0, x=-1224.0, y=-1368.0, z=0.0) >>> alpha_ims[0, 2] SquareElectrode(activated=True, name='A3', side_length=50.0, x=-1224.0, y=-1368.0, z=0.0)
- placement = 'subretinal'
Where the device sits relative to the tissue it stimulates, where the literature is unambiguous about it; None where it is not, or where the class describes a family rather than a device.
- property eye
Implanted eye
A
RetinalImplantcan be implanted either in a left eye (‘left’) or right eye (‘right’). Models such asAxonMapModelwill 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.retina import ArgusII >>> implant = ArgusII(eye='left')
- property electrode_array
Electrode array
- check_stim(stim)[source]
Quality-check the stimulus
This method is executed every time a stimulus is prepared (see
prepare_stim()).If
safe_modeis set to True, this function will only allow stimuli that are charge-balanced. Ifmax_currentis 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
DimensionMismatchErroron one. In the ordinary flow this cannot happen:prepare_stim()has already checked the stimulus againststimulus_unit.check_stimis public, though, and may be handed anything.The user can define their own checks in implants that inherit from
Implant.- Parameters:
stim (
Stimulussource type) – A valid source type for theStimulusobject (e.g., scalar, NumPy array, pulse train).- Raises:
DimensionMismatchError – If an electrical check was requested and
stimis 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 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 implant, e.g.
implant['A1']orimplant[0], and ask how many there are withlen(implant).
- property encoder
Stimulus encoder used for image or video input.
Must be an
ImplantEncoder. Model-aware encoders such asTraceEncoderare called directly instead. If None, dimensionless image/video stimuli are not encoded automatically.Assigning an unbound encoder (
encoder.implant is None) binds it to this implant. An encoder bound to a different implant is rejected with a ValueError.
- family = None
Named device family, if applicable, e.g.
'PRIMA'. .. versionadded:: 0.11.0
- 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
electrode_array.n_electrodes.
- plot(annotate=False, autoscale=True, ax=None, stim=None, stim_cmap=False)[source]
Plot the device in its local coordinate frame.
Use
model.plot(show_implant=True)to show model-side placement.- Parameters:
annotate (bool, optional) – Whether to label electrodes.
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 (
Stimulussource type, optional) –What is presented to the device. Prepared through
prepare_stim(), so the colors show what the electrodes actually deliver. Required bystim_cmap.Added in version 0.11.0.
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
- prepare_stim(source)[source]
Turn a source into stimulation the implant can deliver.
Preparation applies preprocessing, converts the source to a
Stimulus, encodes dimensionless visual input when an encoder is present, reshapes it to the electrode array, removes deactivated electrodes, applies threshold calibration, and runs safety checks. The input is not modified and the result is not stored.Prepared stimuli use the implant’s
stimulus_unit(electrical current for most devices; irradiance for PRIMA).Images and videos require an encoder unless preprocessing already converts them to the implant’s
stimulus_unit.Added in version 0.11.0: Replaces the stateful
stimproperty.- Parameters:
source (
Stimulussource type) – Any source accepted byStimulus, including electrical stimulation and image or video input for the implant encoder.- Returns:
stim – Stimulation delivered by the implant, or None for an empty source.
- Return type:
Stimulusor None
Examples
>>> from pulse2percept.implants import DiskElectrode, Implant >>> from pulse2percept.stimuli import BiphasicPulse >>> implant = Implant(DiskElectrode(0, 0, 0, 100)) >>> stim = implant.prepare_stim(BiphasicPulse(30, 0.45))
Stimulate Electrode B7 in Argus II with 13 uA:
>>> from pulse2percept.implants.retina import ArgusII >>> stim = ArgusII().prepare_stim({'B7': 13})
Argus II includes an encoder, so it can prepare an image directly:
>>> from pulse2percept.stimuli import samples >>> ArgusII().prepare_stim(samples.logo_bvl()).unit uA
- preprocess_stim(stim)[source]
Preprocess the stimulus
This method is executed every time a stimulus is prepared.
No preprocessing is performed by default, but the user can define their own method in implants that inherit from return stim
Implant.A custom method must return a
Stimulusobject with the correct number of electrodes for the implant.
- property raster
Raster pattern used to schedule stimulation across electrodes.
Assigning a raster binds it to this implant.
- property scene_input_frame
Coordinate frame used to register scene input.
'eye'means gaze changes which scene content reaches the implant;'head'means scene input is fixed relative to the head.Defaults to
default_scene_input_frame. Setting toNonerestores that default.Added in version 0.11.0.
- technology = None
Stimulation technology, e.g.
'photovoltaic'. .. versionadded:: 0.11.0
- property thresholds
Perceptual threshold current (uA) for each electrode.
Assign a single current for the whole array, a per-electrode dict, or None to clear the calibration. Threshold-relative pulse trains are calibrated against whatever is in force at the moment
prepare_stim()runs.Added in version 0.10.0.
Changed in version 0.11.0: Changing thresholds affects the next stimulus prepared, rather than rewriting one the implant was holding.
- class pulse2percept.implants.retina.alpha.AlphaAMS(z=0, eye='right', preprocess=True, safe_mode=False)[source]
Alpha-AMS
This class creates an Alpha-AMS array with 1600 photovoltaic pixels (each 30um in diameter) as described in [Stingl2017]. Electrode coordinates are device-local, centered on
(0, 0).The device consists of 1600 30um-wide round pixels, arranged on a 40x40 rectangular grid with 70um pixel pitch.
The array is oriented upright in the visual field, such that an array with center (0,0) has the top three rows lie in the lower retina (upper visual field), as shown below:
An electrode can be addressed by name, row/column index, or integer index (into the flattened array).
Note
Column order is reversed in a left-eye implant.
- Parameters:
z (float, list, or Quantity, optional) – Electrode height (um) above the array’s own plane: a scalar applies to every electrode, a list of 1600 entries gives each its own. May be given as unitful quantities (e.g.
z=100 * um); seepulse2percept.units.eye ({'right', 'left'}, optional) – Eye in which array is implanted.
preprocess (bool or callable, optional) – Either True/False to indicate whether to execute the implant’s default preprocessing method whenever a stimulus is prepared, or a custom function (callable).
safe_mode (bool, optional) – If safe mode is enabled, only charge-balanced stimuli are allowed.
Examples
Create an AlphaAMS array:
>>> from pulse2percept.implants.retina import AlphaAMS >>> AlphaAMS() AlphaAMS(electrode_array=ElectrodeGrid, eye='right', preprocess=True, safe_mode=False, shape=(40, 40))
Get access to the third electrode in the top row (by name or by row/column index):
>>> alpha_ims = AlphaAMS() >>> alpha_ims['A3'] DiskElectrode(activated=True, name='A3', radius=15.0, x=-1225.0, y=-1365.0, z=0.0) >>> alpha_ims[0, 2] DiskElectrode(activated=True, name='A3', radius=15.0, x=-1225.0, y=-1365.0, z=0.0)
- placement = 'subretinal'
Where the device sits relative to the tissue it stimulates, where the literature is unambiguous about it; None where it is not, or where the class describes a family rather than a device.
- property eye
Implanted eye
A
RetinalImplantcan be implanted either in a left eye (‘left’) or right eye (‘right’). Models such asAxonMapModelwill 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.retina import ArgusII >>> implant = ArgusII(eye='left')
- property electrode_array
Electrode array
- check_stim(stim)[source]
Quality-check the stimulus
This method is executed every time a stimulus is prepared (see
prepare_stim()).If
safe_modeis set to True, this function will only allow stimuli that are charge-balanced. Ifmax_currentis 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
DimensionMismatchErroron one. In the ordinary flow this cannot happen:prepare_stim()has already checked the stimulus againststimulus_unit.check_stimis public, though, and may be handed anything.The user can define their own checks in implants that inherit from
Implant.- Parameters:
stim (
Stimulussource type) – A valid source type for theStimulusobject (e.g., scalar, NumPy array, pulse train).- Raises:
DimensionMismatchError – If an electrical check was requested and
stimis 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 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 implant, e.g.
implant['A1']orimplant[0], and ask how many there are withlen(implant).
- property encoder
Stimulus encoder used for image or video input.
Must be an
ImplantEncoder. Model-aware encoders such asTraceEncoderare called directly instead. If None, dimensionless image/video stimuli are not encoded automatically.Assigning an unbound encoder (
encoder.implant is None) binds it to this implant. An encoder bound to a different implant is rejected with a ValueError.
- family = None
Named device family, if applicable, e.g.
'PRIMA'. .. versionadded:: 0.11.0
- 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
electrode_array.n_electrodes.
- plot(annotate=False, autoscale=True, ax=None, stim=None, stim_cmap=False)[source]
Plot the device in its local coordinate frame.
Use
model.plot(show_implant=True)to show model-side placement.- Parameters:
annotate (bool, optional) – Whether to label electrodes.
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 (
Stimulussource type, optional) –What is presented to the device. Prepared through
prepare_stim(), so the colors show what the electrodes actually deliver. Required bystim_cmap.Added in version 0.11.0.
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
- prepare_stim(source)[source]
Turn a source into stimulation the implant can deliver.
Preparation applies preprocessing, converts the source to a
Stimulus, encodes dimensionless visual input when an encoder is present, reshapes it to the electrode array, removes deactivated electrodes, applies threshold calibration, and runs safety checks. The input is not modified and the result is not stored.Prepared stimuli use the implant’s
stimulus_unit(electrical current for most devices; irradiance for PRIMA).Images and videos require an encoder unless preprocessing already converts them to the implant’s
stimulus_unit.Added in version 0.11.0: Replaces the stateful
stimproperty.- Parameters:
source (
Stimulussource type) – Any source accepted byStimulus, including electrical stimulation and image or video input for the implant encoder.- Returns:
stim – Stimulation delivered by the implant, or None for an empty source.
- Return type:
Stimulusor None
Examples
>>> from pulse2percept.implants import DiskElectrode, Implant >>> from pulse2percept.stimuli import BiphasicPulse >>> implant = Implant(DiskElectrode(0, 0, 0, 100)) >>> stim = implant.prepare_stim(BiphasicPulse(30, 0.45))
Stimulate Electrode B7 in Argus II with 13 uA:
>>> from pulse2percept.implants.retina import ArgusII >>> stim = ArgusII().prepare_stim({'B7': 13})
Argus II includes an encoder, so it can prepare an image directly:
>>> from pulse2percept.stimuli import samples >>> ArgusII().prepare_stim(samples.logo_bvl()).unit uA
- preprocess_stim(stim)[source]
Preprocess the stimulus
This method is executed every time a stimulus is prepared.
No preprocessing is performed by default, but the user can define their own method in implants that inherit from return stim
Implant.A custom method must return a
Stimulusobject with the correct number of electrodes for the implant.
- property raster
Raster pattern used to schedule stimulation across electrodes.
Assigning a raster binds it to this implant.
- property scene_input_frame
Coordinate frame used to register scene input.
'eye'means gaze changes which scene content reaches the implant;'head'means scene input is fixed relative to the head.Defaults to
default_scene_input_frame. Setting toNonerestores that default.Added in version 0.11.0.
- technology = None
Stimulation technology, e.g.
'photovoltaic'. .. versionadded:: 0.11.0
- property thresholds
Perceptual threshold current (uA) for each electrode.
Assign a single current for the whole array, a per-electrode dict, or None to clear the calibration. Threshold-relative pulse trains are calibrated against whatever is in force at the moment
prepare_stim()runs.Added in version 0.10.0.
Changed in version 0.11.0: Changing thresholds affects the next stimulus prepared, rather than rewriting one the implant was holding.