pulse2percept.implants.ensemble
Classes
|
- class pulse2percept.implants.ensemble.EnsembleImplant(implants, preprocess=False, safe_mode=False)[source]
- classmethod from_visual_field_map(implant_type, visual_field_map, locs=None, xrange=None, yrange=None, step=None, region=None)[source]
Create an ensemble implant from a visual field map.
An implant of type
implant_typeis created for each visual field location specified either bylocsor byxrange,yrangeandstep, and centered at the tissue coordinates the map transforms that location to.The map may be retinal, cortical, or any other 2D
VisualFieldMap. 3D maps are not supported, because placing an implant on a folded surface needs more than the(x, y)anchor this method passes on; seefrom_neuropythy().Added in version 0.11.0: Replaces
from_cortical_map, which knew about cortex specifically.- Parameters:
implant_type (type) – Type of implant to create for the ensemble. Must subclass p2p.implants.Implant
visual_field_map (
VisualFieldMap) – Visual field map to create the implant from.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.
region (str, optional) – Region of tissue to create the implant in, e.g.
'ret'or'v1'. Required unless the map has exactly one region.
- Returns:
ensemble – Ensemble implant created from the 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)). Contrastfrom_coords(), which places implants by their physical position in microns. Seepulse2percept.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) iflocsis not given.yrange (tuple of floats, optional) – Range of x and y coordinates (um) to create implants at. Required (together with
step) iflocsis not given.step (float or (x_step, y_step), optional) – Spacing (um) between implant centers.
- Raises:
ValueError – If neither
locsnor all three ofxrange,yrangeandstepare given.
Notes
Lengths may be given as plain numbers of microns or as unitful quantities (e.g.
xrange=(-1 * mm, 1 * mm)). Seepulse2percept.units.
Changed in version 0.10.0: The grid arguments no longer have defaults. They used to fall back on
(-3, 3)and1, which are the degrees of visual anglefrom_visual_field_map()works in; here they are microns, so the default laid every implant out inside a 6 um square.
- property implants
Dict of implants
- prepare_stim(source)[source]
Prepare stimulation for an ensemble implant.
sourcemay address the combined electrode array directly, or be a dict keyed by constituent implant keys. Per-implant sources are prepared by each constituent implant, merged, then passed through ensemble-level preprocessing and safety checks. Missing implant keys contribute zeros.Changed in version 0.11.0: Replaces
merge_stimuliand the stimuli previously stored on constituent implants.- Parameters:
source (dict or
Stimulussource type) – One source for the whole ensemble, or{implant_key: source}.- Returns:
stim – Merged stimulation for the ensemble.
- Return type:
Stimulusor None
Examples
>>> import numpy as np >>> from pulse2percept.implants import EnsembleImplant >>> from pulse2percept.implants.cortex import Orion >>> ensemble = EnsembleImplant.from_coords( ... Orion, locs=np.array([(0, 0), (-35000, 0)])) >>> ensemble.prepare_stim({0: np.ones(60), ... 1: 2 * np.ones(60)}).data.shape (120, 1)
- 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_array
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 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.
- placement = None
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.
- 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
- 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.