pulse2percept.implants.base
ProsthesisSystem,
RectangleImplant
Classes
|
Visual prosthesis system |
|
A generic rectangular implant |
- class pulse2percept.implants.base.ProsthesisSystem(earray, stim=None, eye='RE', preprocess=False, safe_mode=False, raster=None, max_current=None)[source]
Visual prosthesis system
A visual prosthesis combines an electrode array and (optionally) a stimulus. This is the base class for prosthesis systems such as
ArgusIIandAlphaIMS.Added in version 0.6.
- Parameters:
earray (
ElectrodeArrayor) –ElectrodeThe electrode array used to deliver electrical stimuli to the retina.stim (
Stimulussource type) – A valid source type for theStimulusobject (e.g., scalar, NumPy array, pulse train).eye ('LE' or 'RE') – A string indicating whether the system is implanted in the left (‘LE’) or right eye (‘RE’)
preprocess (bool or callable, optional) – Either True/False to indicate whether to execute the implant’s default preprocessing method whenever a new stimulus is assigned, or a custom function (callable).
safe_mode (bool, optional) – If safe mode is enabled, only charge-balanced stimuli are allowed. Safety is an electrical property, so this also requires the stimulus to be measured in units of current.
raster (
Raster, optional) –How the stimulator takes turns between electrodes that it cannot drive at the same time. If None, every electrode may fire at once.
Added in version 0.10.0.
max_current (float, optional) –
The total current (uA) the stimulator can source at any one instant, summed over all electrodes. If given, assigning a stimulus that exceeds it raises. If None, no such check is performed.
May be given as a plain number of microamps or as a unitful quantity (e.g.
0.1 * mA); seepulse2percept.units.Added in version 0.10.0.
Examples
A system in the left eye made from a single
DiskElectrodewith radius r=100um sitting at x=200um, y=-50um, z=10um:>>> from pulse2percept.implants import DiskElectrode, ProsthesisSystem >>> implant = ProsthesisSystem(DiskElectrode(200, -50, 10, 100), eye='LE')
Note
A stimulus can also be assigned later (see
stim).- 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.
- property max_current
Total instantaneous current (uA) the stimulator can source
- check_stim(stim)[source]
Quality-check the stimulus
This method is executed every time a new value is assigned to
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. An implant that asks for neither does not run either check, which is why a dimensionless stimulus may still be assigned to one –preprocesshas 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 (
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.
- 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
Stimulusobject with the correct number of electrodes for the implant.
- 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
- property earray
Electrode array
- property stim
Stimulus
A stimulus can be created from many source types, such as scalars, NumPy arrays, and dictionaries (see
Stimulusfor a complete list).A stimulus can be assigned either in the
ProsthesisSystemconstructor 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})
- property eye
Implanted eye
A
ProsthesisSystemcan be implanted either in a left eye (‘LE’) or right eye (‘RE’). 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 import ArgusII >>> implant = ArgusII(eye='LE')
- property n_electrodes
Number of electrodes in the array
This is equivalent to calling
earray.n_electrodes.
- 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']orimplant[0].
- 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
- class pulse2percept.implants.base.RectangleImplant(x=0, y=0, z=0, rot=0, shape=(15, 15), r=75.0, spacing=400.0, eye='RE', stim=None, preprocess=True, safe_mode=False)[source]
A generic rectangular implant
- Parameters:
x (float, optional) – The x, y, z coordinates (um) of the center of the implant
y (float, optional) – The x, y, z coordinates (um) of the center of the implant
z (float, optional) – The x, y, z coordinates (um) of the center of the implant
rot (float, optional) – The rotation of the implant in degrees
shape (tuple, optional) – The number of rows and columns in the implant
r (float, optional) – The electrode radius (um)
spacing (float, optional) – The distance (um) between electrodes in the implant
eye (str, optional) – The eye in which the implant is implanted
stim (
Stimulussource type) – A valid source type for a stimuluspreprocess (bool, optional) – Whether to preprocess the stimulus
safe_mode (bool, optional) – Whether to enforce charge balance
Notes
Lengths may be given as plain numbers of microns or as unitful quantities (e.g.
spacing=0.4 * mm). Seepulse2percept.units.
- check_stim(stim)[source]
Quality-check the stimulus
This method is executed every time a new value is assigned to
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. An implant that asks for neither does not run either check, which is why a dimensionless stimulus may still be assigned to one –preprocesshas 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 (
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 prosthesis system object, e.g.
implant['A1']orimplant[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
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
Stimulusobject with the correct number of electrodes for the implant.
- 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.
- property earray
Electrode array
- property stim
Stimulus
A stimulus can be created from many source types, such as scalars, NumPy arrays, and dictionaries (see
Stimulusfor a complete list).A stimulus can be assigned either in the
ProsthesisSystemconstructor 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})
- property eye
Implanted eye
A
ProsthesisSystemcan be implanted either in a left eye (‘LE’) or right eye (‘RE’). 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 import ArgusII >>> implant = ArgusII(eye='LE')