def test_plot_implant_on_axon_map(): ax = plot_implant_on_axon_map(ArgusII()) npt.assert_equal(isinstance(ax, Subplot), True) # Check axis limits: for xlim, ylim in zip([None, (-2000, 1500)], [(-3000, 1300), None]): ax = plot_implant_on_axon_map(ArgusII(), xlim=xlim, ylim=ylim) if xlim is None: xlim = (-4000, 4500) if ylim is None: ylim = (-2500, 3000) npt.assert_almost_equal(ax.get_xlim(), xlim) npt.assert_almost_equal(ax.get_ylim(), ylim) # Check optic disc center in both eyes: model = AxonMapSpatial() for eye in ['RE', 'LE']: for loc_od in [(15.5, 1.5), (17.9, -0.01)]: od = (-loc_od[0], loc_od[1]) if eye == 'LE' else loc_od ax = plot_implant_on_axon_map(ArgusII(eye=eye), loc_od=od) npt.assert_equal(len(ax.patches), 1) npt.assert_almost_equal(ax.patches[0].center, model.dva2ret(od)) close(ax.figure) # Electrodes and quadrants can be annotated: for ann_el, n_el in [(True, 60), (False, 0)]: for ann_q, n_q in [(True, 4), (False, 0)]: ax = plot_implant_on_axon_map(ArgusII(), annotate_implant=ann_el, annotate_quadrants=ann_q) npt.assert_equal(len(ax.texts), n_el + n_q) npt.assert_equal(len(ax.collections[0]._paths), 60) close(ax.figure) # Stimulating electrodes are marked: ax = plot_implant_on_axon_map(ArgusII(stim=np.ones(60))) # Setting upside_down flips y axis: ax = plot_implant_on_axon_map(ArgusII(), upside_down=True) npt.assert_almost_equal(ax.get_xlim(), (-4000, 4500)) npt.assert_almost_equal(ax.get_ylim(), (3000, -2500)) with pytest.raises(TypeError): plot_implant_on_axon_map(DiskElectrode(0, 0, 0, 100)) with pytest.raises(ValueError): plot_implant_on_axon_map(ArgusII(), n_bundles=0)
def test_plot_implant_on_axon_map(): fig, ax = plot_implant_on_axon_map(ArgusII()) npt.assert_equal(isinstance(fig, Figure), True) npt.assert_equal(isinstance(ax, Subplot), True) # Check axis limits: xmin, xmax, ymin, ymax = dva2ret([-20, 20, -15, 15]) npt.assert_equal(ax.get_xlim(), (xmin, xmax)) npt.assert_equal(ax.get_ylim(), (ymin, ymax)) # Check optic disc center in both eyes: for eye in ['RE', 'LE']: for loc_od in [(15.5, 1.5), (17.9, -0.01)]: od = (-loc_od[0], loc_od[1]) if eye == 'LE' else loc_od _, ax = plot_implant_on_axon_map(ArgusII(eye=eye), loc_od=od) npt.assert_equal(len(ax.patches), 1) npt.assert_almost_equal(ax.patches[0].center, dva2ret(od)) # Electrodes and quadrants can be annotated: for ann_el, n_el in [(True, 60), (False, 0)]: for ann_q, n_q in [(True, 4), (False, 0)]: _, ax = plot_implant_on_axon_map(ArgusII(), annotate_implant=ann_el, annotate_quadrants=ann_q) npt.assert_equal(len(ax.texts), n_el + n_q) # Stimulating electrodes are marked: fig, ax = plot_implant_on_axon_map(ArgusII(stim=np.ones(60))) # Setting upside_down flips y axis: _, ax = plot_implant_on_axon_map(ArgusII(), upside_down=True) npt.assert_equal(ax.get_xlim(), (xmin, xmax)) npt.assert_equal(ax.get_ylim(), (ymax, ymin)) with pytest.raises(TypeError): plot_implant_on_axon_map(DiskElectrode(0, 0, 0, 100)) with pytest.raises(ValueError): plot_implant_on_axon_map(ArgusII(), n_bundles=0)
# Please note that an electrode array is only one part of a # :py:class:`~pulse2percept.implants.ProsthesisSystem`. Other parts include the # stimulus to be applied to each electrode, stimulus preprocessing methods, # and safety checks. # # However, for the purpose of this tutorial, all we need to do is wrap the # electrode array in a prosthesis system: from pulse2percept.implants import ProsthesisSystem implant = ProsthesisSystem(earray) ############################################################################## # We can then visualize the array as follows: import matplotlib.pyplot as plt from pulse2percept.viz import plot_implant_on_axon_map plot_implant_on_axon_map(implant) ############################################################################## # Extending the CircleElectrodeArray class # ---------------------------------------- # # Similar to extending :py:class:`~pulse2percept.implants.ElectrodeArray` for # our purposes, we can extend ``CircleElectrodeArray``. # # To add new functionality, we could simply edit the above constructor. # However, nobody stops us from creating our own hierarchy of classes. # # For example, we could build a ``FlexibleCircleElectrodeArray`` that allows us to # remove individual electrodes from the array:
import pulse2percept as p2p import numpy as np import matplotlib as plt from prima import Prima from pulse2percept.viz import plot_implant_on_axon_map # Array Shape plotting implant = Prima(x=-50, y=50, rot=np.deg2rad(0)) plt, _ = plot_implant_on_axon_map(implant, annotate_implant=False, marker_style='hw') # plt, _ = plot_implant_on_axon_map( # implant, annotate_implant=False) plt.savefig("array_shape.svg") # Plot a pulse train on one electrode # argus = Prima() # stim = p2p.stimuli.PulseTrain(0.005/1000.0) # sim = p2p.Simulation(argus, engine='serial') # sim.set_ganglion_cell_layer('Nanduri2012') # sim.set_optic_fiber_layer(sampling=250, decay_const=2) # percept = sim.pulse2percept({"A1": stim, "B2": stim}, layers=["OFL", "GCL"]) # plt.pcolor(percept.data[:, :, 50000]) # plt.savefig("blargh.png")
disk_grid[:] ############################################################################## # .. note:: # # You can also specify a list of radii, one value for each electrode in # the grid. # # We can visualize the grid by wrapping it in a # :py:class:`~pulse2percept.implants.ProsthesisSystem` object and passing it # to :py:func:`~pulse2percept.viz.plot_implant_on_axon_map`: from pulse2percept.implants import ProsthesisSystem from pulse2percept.viz import plot_implant_on_axon_map plot_implant_on_axon_map(ProsthesisSystem(disk_grid)) ############################################################################## # Creating a hexagonal grid # ------------------------- # # To create a hexagonal grid instead, all we need to do is change the grid type # from 'rect' (default) to 'hex': hex_grid = ElectrodeGrid((3, 5), 800, type='hex', etype=DiskElectrode, r=100) plot_implant_on_axon_map(ProsthesisSystem(hex_grid)) ############################################################################## # The following example centers the grid on (x,y) = (-1000um, 200 um), # z=150um away from the retinal surface, and rotates it clockwise by 45 degrees
# # In the following, we will create an # :py:class:`~pulse2percept.implants.ArgusII` implant. By default, the implant # will be centered over the fovea (at x=0, y=0) and aligned with the horizontal # meridian (rot=0): from pulse2percept.implants import ArgusII implant = ArgusII() ############################################################################## # You can inspect the location of the implant with respect to the underlying # nerve fiber bundles using the # :py:meth:`~pulse2percept.viz.plot_implant_on_axon_map`: from pulse2percept.viz import plot_implant_on_axon_map plot_implant_on_axon_map(implant) ############################################################################## # .. note:: # # You can also plot just the axon map with # :py:meth:`~pulse2percept.viz.plot_axon_map`. # # The easiest way to assign a stimulus to the implant is to pass a NumPy array # that specifies the current amplitude to be applied to every electrode in the # implant. # # For example, the following sends 1 microamp to all 60 electrodes of the # implant: import numpy as np