MEA plotting

This notebook shows some plotting routines implemented in the MEAutility package.

import MEAutility as MEA
import matplotlib.pylab as plt
import numpy as np
%matplotlib notebook

2D plotting

As usual, let’s first define some MEA objects:

sqmea = MEA.return_mea('SqMEA-10-15um')
neuronexus = MEA.return_mea('Neuronexus-32')
neuropixels = MEA.return_mea('Neuropixels-128')

The plot_probe() function plots the probe in 2D. The axis is returned and an existing axis can be passed with the ax argument. Here are some examples:

MEA.plot_probe(neuropixels)
<matplotlib.axes._subplots.AxesSubplot at 0x7f4d5a79f630>
fig, ax1 = plt.subplots()
ax1 = MEA.plot_probe(neuronexus, ax=ax1, type='shank')
_ = ax1.axis('off')

plot_probe() always plots the probe along its main axes:

neuronexus.rotate([1,0,0], 45)
ax1 = MEA.plot_probe(neuronexus, type='shank')
_ = ax1.axis('off')
_ = MEA.plot_probe(sqmea, type='planar', xlim=[-400,400], ylim=[-200,200])

To visualize the stimulating currents, one can use the color_currents parameter:

sqmea.set_random_currents()
ax = MEA.plot_probe(sqmea, color_currents=True)
# colormap can be changed
ax = MEA.plot_probe(sqmea, color_currents=True, cmap='hot')

3D plotting

The function plot_probe_3d allows to plot MEA objects in 3d axes. The plots reflect the current position and rotation of the MEA.

neuronexus = MEA.return_mea('Neuronexus-32')
_ = MEA.plot_probe_3d(neuronexus)
neuronexus.rotate([1,0,0], 45)
_ = MEA.plot_probe_3d(neuronexus)
neuronexus.set_random_currents()
_ = MEA.plot_probe_3d(neuronexus, color_currents=True, cmap='jet')
ax = MEA.plot_probe_3d(neuronexus, color_currents=True, cmap='jet',
                       xlim=[-100,100], ylim=[-100,100], zlim=[-100,100])
_ = ax.axis('off')

Electric potential images

The functions plot_v_image() and plot_v_surf() allows the user to plot potential images on a plane. The plane can be defined with the plane argument and boundaries can be given with x_bound, y_bound, and z_bound arguments (e.g. if plane is xz, x_bound and z_bound are required). The offset on the other direciotn (i.e. y when plane is xz) is controlled by the offet parameter.

sqmea = MEA.return_mea('SqMEA-10-15um')
sqmea.points_per_electrode = 1
sqmea.reset_currents()
sqmea[0][0].current = 10000
sqmea[5][0].current = 10000
sqmea[0][7].current = 10000
_ = MEA.plot_v_image(sqmea, y_bound=[-100, 100], z_bound=[-100, 100], plane='yz', offset=10)

With plot_v_image we can show the effect of electrodes of finite sizes:

print(sqmea[0][0].position)
[  0.  -67.5 -67.5]
fig, axes = plt.subplots(1, 2)
# points per electrode = 1
sqmea.points_per_electrode = 1
_, v1 = MEA.plot_v_image(sqmea, y_bound=[-55, -80], z_bound=[-55, -80], offset=2,
                         npoints=30, plane='yz', ax=axes[0])

# points per electrode = 100
sqmea.points_per_electrode = 100
_, v100 = MEA.plot_v_image(sqmea, y_bound=[-55, -80], z_bound=[-55, -80], offset=2,
                           npoints=30, plane='yz', ax=axes[1])

The finite size results in a squarer electric potential in proximity of the electrode!

fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1, projection='3d')
ax2 = fig.add_subplot(1, 2, 2, projection='3d')

sqmea.points_per_electrode = 1
_ = MEA.plot_v_surf(sqmea, v_plane=v1, y_bound=[-55, -80], z_bound=[-55, -80], offset=10,
                           npoints=30, plane='yz', ax=ax1)

_ = MEA.plot_v_surf(sqmea, v_plane=v100, y_bound=[-55, -80], z_bound=[-55, -80], offset=10,
                           npoints=30, plane='yz', ax=ax2)
sqmea.points_per_electrode = 1
sqmea[0][0].current = 10000
ax, v = MEA.plot_v_surf(sqmea, y_bound=[-100, 100], z_bound=[-100, 100],
                        plane='yz', plot_plane='yz', offset=30, distance=200)
MEA.plot_probe_3d(sqmea, ax=ax, xlim=[-500, 500], color_currents=True)
<matplotlib.axes._subplots.Axes3DSubplot at 0x7f4d5829be48>
sqmea.rotate([0,1,0], 90)
print(sqmea.main_axes)
[[0. 1. 0.]
 [1. 0. 0.]]
ax, v = MEA.plot_v_surf(sqmea, x_bound=[-100, 100], y_bound=[-100, 100],
                        plane='xy', plot_plane='xy', offset=30, distance=30)
MEA.plot_probe_3d(sqmea, ax=ax, xlim=[-100, 100], zlim=[-100, 300], color_currents=True, type='planar')
<matplotlib.axes._subplots.Axes3DSubplot at 0x7f4d4aed14e0>
sqmea.rotate([0,1,0], -90)
sqmea.rotate([0,0,1], -90)
print(sqmea.main_axes)
[[1. 0. 0.]
 [0. 0. 1.]]
ax, v = MEA.plot_v_surf(sqmea, x_bound=[-100, 100], z_bound=[-100, 100],
                        plane='xz', plot_plane='xz', offset=30, distance=100)
MEA.plot_probe_3d(sqmea, ax=ax, color_currents=True,)
<matplotlib.axes._subplots.Axes3DSubplot at 0x7f4d582e0710>

Plot signal traces

# fake noise signal
signals = np.random.randn(sqmea.number_electrodes, 10000)
_ = MEA.plot_mea_recording(signals, sqmea, lw=0.1)

Animations

# %matplotlib notebook
# from IPython.display import HTML

# anim = MEA.play_mea_recording(signals, sqmea, 1000, interval =100, lw=0.1)
# HTML(anim.to_jshtml())