Ejemplo n.º 1
0
def plot_neuron(neuron_numb,
                cell_path,
                params_cell,
                inh_syn_coords=None,
                exc_syn_coords=None):
    import sim_cell as temp_sim
    ax = plt.gca()

    all_neurons = hl.find_files(cell_path, ext='json')
    for next_neuron in range(neuron_numb):
        # choose random neuron to plot
        selected = random.choice(all_neurons)
        selected = os.path.join(cell_path, selected)

        with file(selected, 'r') as fid:
            params_selected = json.load(fid)

            seg_coords = temp_sim.init_cell(params_cell, params_selected)
            shift_cell = params_selected['cell_coords']
            seg_coords = temp_sim.shift_cell(params_selected, seg_coords)
            draw_soma(ax,
                      x0=shift_cell[0] + 10,
                      x1=shift_cell[0] - 10,
                      y0=shift_cell[1] + 10,
                      y1=shift_cell[1] - 10,
                      color='k')
            keep_segs = ['apic', 'dend', 'soma']
            cleaned_seg_coords = cs.choose_subset_of_segs(
                seg_coords, keep_segs)
            if exc_syn_coords is not None:
                plot_synapses(exc_syn_coords, marker_size=6, color='y')
            if inh_syn_coords is not None:
                plot_synapses(inh_syn_coords, marker_size=6, color='m')

            graph.plot_neuron(cleaned_seg_coords, autolim=False)
Ejemplo n.º 2
0
def plot_cell_structure(seg_coords,
                        layer_info=None,
                        write_names=True,
                        set_one_color='k',
                        x_range=[-500, 500]):
    '''plot the structure of the given neuron
    :param seg_coords: coords of the given cell
    :param layer_info: layer info should be either none if the neuron is not to be colored or
            it might be colored according to the different layers or segemnts, then this parameter should cosnsist
            of the following params:
            all_layers > can be None, not used by this funct
            colors > color for each seg_coords,
            layer_names > if write_names = True then this will be used for the legend to set the meaning for each color,
                    (as many layer_names as layer_colors)
            layer_ranges > if layers are to be colored it should specify ranges for each of the layers, otherwise it
                    may be set to None
            layer_colors > colors for each layer or for each segment type
    :param write_names: boolean. Either the legend for different colors is set or not
    :param set_one_color: if only one color is to be set; (layer_info must then remain None)
    :param x_range: x_range for the plot
    :return:
    '''
    # extract layer info
    if layer_info is not None:
        all_layers, colors, layer_names, layer_ranges, layer_colors = layer_info

        if all_layers is not None:  # coloring by layer
            # adds horizontal lines for the layers
            [
                plt.hlines(x, x_range[0], x_range[1], 'b', linestyle='--')
                for x, y in layer_ranges[1:]
            ]
            if write_names:
                # writes names for each of the layer
                [
                    plt.text(x_range[0] + 50,
                             np.mean(layer_ranges[idx]),
                             layer_names[idx],
                             color=layer_colors[idx])
                    for idx in range(len(layer_ranges))
                ]
        elif write_names:  # coloring by segment
            # writes legend for the colors
            1
    else:  # one color for all
        colors = np.array([set_one_color for x in range(len(seg_coords))])

    graph.plot_neuron(seg_coords, colors=colors,
                      autolim=True)  # show structure of neuron(s)
Ejemplo n.º 3
0
          "all" : "k",
          "iseg" : "g",
          "hill" : "m"}

# Calculation of field
v_dend = field.estimate_lsa(pos, coords[dend], I[:, dend])
v_soma = field.estimate_lsa(pos, coords[soma], I[:, soma])
v_axon = field.estimate_lsa(pos, coords[axon], I[:, axon])
v_iseg = field.estimate_lsa(pos, coords[iseg], I[:, iseg])
v_hill = field.estimate_lsa(pos, coords[hill], I[:, hill])

# PLOTS
fig = plt.figure()
fig.subplots_adjust(hspace=0.15, wspace=0.2, left=0.05, right=0.95)
ax1= fig.add_subplot(1,2,1, frameon=False)
l_dend = graph.plot_neuron(coords[dend], colors=colors['dend'])
l_axon = graph.plot_neuron(coords[axon], colors=colors['axon'])
l_iseg = graph.plot_neuron(coords[iseg], colors=colors['iseg'])
l_hill = graph.plot_neuron(coords[hill], colors=colors['hill'])
l_soma = graph.plot_neuron(coords[soma], colors=colors['soma'])
plt.legend((l_dend, l_axon, l_iseg, l_hill, l_soma), 
           ('dendrites', 'axon', 'AIS','hill', 'soma'),
           frameon=False,
           bbox_transform=ax1.transAxes,
           bbox_to_anchor=(0.15, 0.1, 0.3, 0.3))

xp, yp = -300, 350
w, h = 100, 100
plt.plot([xp, xp], [yp, yp+h], 'k-')
plt.plot([xp, xp+h], [yp, yp], 'k-')
plt.text(xp-10, yp+h/2., u"100 µm", ha='right', va='center',
Ejemplo n.º 4
0
# Simulation
cell.load_model('models/Mainen/demo_ext.hoc',
                'models/Mainen/%s/.libs/libnrnmech.so' % ARCH)
cell.initialize(dt=dt)
t, I = cell.integrate(tstop)
coords = cell.get_seg_coords()

# Plots
fig = plt.figure(figsize=(6,6), facecolor=(0.7, 0.7, 0.7))
fig.subplots_adjust(left=0.05, right=0.95)
ax = plt.subplot(111, frameon=False)
S = np.pi*coords['diam']*coords['L'] #segment surface
p2p = np.abs(I).max(0)-np.abs(I).min(0)
norm = colors.LogNorm(vmin=p2p.min(), vmax=p2p.max())
col = graph.plot_neuron(coords, p2p, norm=norm)
plt.xticks([])
plt.yticks([])
plt.ylim((-200, 610))
plt.xlim((-550, 250))

# scalebar
xp, yp = -500, -100
w, h = 100, 100
plt.plot([xp, xp], [yp, yp+h], 'k-')
plt.plot([xp, xp+h], [yp, yp], 'k-')
plt.text(xp-10, yp+h/2., u"100 µm", ha='right', va='center',
         transform=ax.transData)
plt.text(xp+h/2., yp-10, u"100 µm", ha='center', va='top',
         transform=ax.transData)
Ejemplo n.º 5
0
# Simulation
cell.load_model('models/Mainen/demo_ext.hoc',
                'models/Mainen/%s/.libs/libnrnmech.so' % ARCH)
cell.initialize(dt=dt)
t, I = cell.integrate(tstop)

# Calculation of field
coords = cell.get_seg_coords()
v_ext = field.estimate_lsa(pos, coords, I)

# PLOTS
fig = plt.figure()
fig.subplots_adjust(left=0.05, wspace=0)
ax1 = fig.add_subplot(1, 2, 1, frameon=False)
graph.plot_neuron(coords)
plt.plot([pos[0]], [pos[1]], 'ro')
ax1.text(0.05, 0.9, 'A', weight='bold', transform=ax1.transAxes)

## scalebar
xp, yp = -1500, -2000
w, h = 1000, 1000
ax1.plot([xp, xp], [yp, yp + h], 'k-')
ax1.plot([xp, xp + h], [yp, yp], 'k-')
ax1.text(xp - 100,
         yp + h / 2.,
         "1 mm",
         ha='right',
         va='center',
         transform=ax1.transData)
ax1.text(xp + h / 2.,
Ejemplo n.º 6
0
                  yrange[0]:yrange[1]:n_waveforms*1j]

xx_sp, yy_sp = spikes
xx_sp, yy_sp = xx_sp.flatten(), yy_sp.flatten()
xx_sp, yy_sp = xx_sp[:, np.newaxis], yy_sp[:, np.newaxis]
v_samples = field.estimate_on_grid(coords, I, xx_sp, yy_sp)

for i in range(v_samples.shape[1]):
    v_samples[:,i,0] = filter(v_samples[:,i,0]) 

# PLOTS
fig = plt.figure()

ax = plt.subplot(111, frameon=False)
## plot neuron shape
graph.plot_neuron(coords, colors='0.4')

#get potential values
#p2p = v_ext.max(0) - v_ext.min(0)
p2p = v_ext[pt_idx, :, :]

## contour plot of the field
cs = plt.contour(xx, yy, p2p)

for label, line in zip(cs.levels, cs.collections):
    line.set_label("%g" % label)

plt.legend(loc=2, frameon=False, 
           bbox_transform=ax.transAxes, 
           bbox_to_anchor=(1.1,1))
Ejemplo n.º 7
0
# Simulation
cell.load_model('models/Mainen/demo_ext.hoc',
                'models/Mainen/%s/.libs/libnrnmech.so' % ARCH)
cell.initialize(dt=dt)
t, I = cell.integrate(tstop)

# Calculation of field
coords = cell.get_seg_coords()
v_ext = field.estimate_lsa(pos, coords, I) 

# PLOTS
fig = plt.figure()
fig.subplots_adjust(left=0.05, wspace=0)
ax1= fig.add_subplot(1,2,1, frameon=False)
graph.plot_neuron(coords)
plt.plot([pos[0]], [pos[1]], 'ro')
ax1.text(0.05, 0.9, 'A', weight='bold',
         transform=ax1.transAxes)

## scalebar
xp, yp =  -1500, -2000
w, h = 1000, 1000
ax1.plot([xp, xp], [yp, yp+h], 'k-')
ax1.plot([xp, xp+h], [yp, yp], 'k-')
ax1.text(xp-100, yp+h/2., "1 mm", ha='right', va='center',
         transform=ax1.transData)
ax1.text(xp+h/2., yp-100, "1 mm", ha='center', va='top',
         transform=ax1.transData)

plt.xlim([-3000, 3000])
Ejemplo n.º 8
0
    t = data['t']
    I = data['I']

# Plots
fig = plt.figure(figsize=(6,6), facecolor=bg_color)
fig.subplots_adjust(left=0.05, right=0.95)
ax = plt.subplot(111, frameon=False)

#contour
plot_contour(x_range, y_range, 5)

#neuron
S = np.pi*coords['diam']*coords['L'] #segment surface
p2p = I.max(0) - I.min(0)
norm = colors.LogNorm(vmin=p2p.min(), vmax=p2p.max())
col = graph.plot_neuron(coords, p2p, norm=norm, show_diams=True, width_min=1., width_max=6, cmap=cmap)
plt.xticks([])
plt.yticks([])
plt.xlim(x_range)
plt.ylim(y_range)

# scalebar
xp, yp = -500, -100
w, h = 100, 100
plt.plot([xp, xp], [yp, yp+h], 'k-')
plt.plot([xp, xp+h], [yp, yp], 'k-')
plt.text(xp-10, yp+h/2., u"100 µm", ha='right', va='center',
         transform=ax.transData)
plt.text(xp+h/2., yp-10, u"100 µm", ha='center', va='top',
         transform=ax.transData)
Ejemplo n.º 9
0
    "iseg": "g",
    "hill": "m"
}

# Calculation of field
v_dend = field.estimate_lsa(pos, coords[dend], I[:, dend])
v_soma = field.estimate_lsa(pos, coords[soma], I[:, soma])
v_axon = field.estimate_lsa(pos, coords[axon], I[:, axon])
v_iseg = field.estimate_lsa(pos, coords[iseg], I[:, iseg])
v_hill = field.estimate_lsa(pos, coords[hill], I[:, hill])

# PLOTS
fig = plt.figure()
fig.subplots_adjust(hspace=0.15, wspace=0.2, left=0.05, right=0.95)
ax1 = fig.add_subplot(1, 2, 1, frameon=False)
l_dend = graph.plot_neuron(coords[dend], colors=colors['dend'])
l_axon = graph.plot_neuron(coords[axon], colors=colors['axon'])
l_iseg = graph.plot_neuron(coords[iseg], colors=colors['iseg'])
l_hill = graph.plot_neuron(coords[hill], colors=colors['hill'])
l_soma = graph.plot_neuron(coords[soma], colors=colors['soma'])
plt.legend((l_dend, l_axon, l_iseg, l_hill, l_soma),
           ('dendrites', 'axon', 'AIS', 'hill', 'soma'),
           frameon=False,
           bbox_transform=ax1.transAxes,
           bbox_to_anchor=(0.15, 0.1, 0.3, 0.3))

xp, yp = -300, 350
w, h = 100, 100
plt.plot([xp, xp], [yp, yp + h], 'k-')
plt.plot([xp, xp + h], [yp, yp], 'k-')
plt.text(xp - 10,
Ejemplo n.º 10
0
def plot_memb_current_for_cell(time_pt,
                               params,
                               plot_morpho=False,
                               plot_field=True,
                               plot_synapses=False,
                               plot_current=False,
                               ax=None):

    # this is used for frames of the movie

    v_ext, xx, yy, seg_coords, x_range, y_range, dt = params
    #v_ext, xx, yy, seg_coords, x_range, y_range, inh_syn_coords, exc_syn_coords, dt = params

    max_field = np.max(v_ext)
    if max_field >= 1000:
        # convert to microvolts
        v_ext = v_ext / 10e2  # change to microvolts
        scale_type = 'micro'
        max_field /= 10e2
    else:
        scale_type = 'nano'

    #v_ext = v_ext / 10e2 # change nano to micro volts
    import matplotlib.colors as colors

    if ax == None:
        ax = plt.subplot(1, 1, 1)

    # draw field
    mycmap, colormap_range_ceil, aspect, one_forth_colormap, colormap_range = helper_provide_imshow_details(
        v_ext, x_range, y_range)

    if plot_field:
        pcm = plt.imshow(
            v_ext[time_pt, :, :],
            interpolation="nearest",
            #norm=colors.SymLogNorm(linthresh=0.01 * np.max(v_ext),
            #                       linscale=1.0,
            #                       vmin=colormap_range_ceil[0], vmax=colormap_range_ceil[1]),
            origin='lower',
            aspect=0.8,
            extent=(x_range[0], x_range[1], y_range[0], y_range[1]),
            cmap=mycmap)
        plt.clim(colormap_range[0], colormap_range[1])

    if plot_morpho:
        # draw morpho
        import pdb
        pdb.set_trace()
        col = graph.plot_neuron(seg_coords, colors='k', autolim=True)

        soma_idcs, = np.where(seg_coords['name'] == 'soma')

        draw_soma(ax,
                  x0=seg_coords[soma_idcs[0]]['x0'],
                  x1=seg_coords[soma_idcs[-1]]['x1'],
                  y0=seg_coords[soma_idcs[0]]['y0'],
                  y1=seg_coords[soma_idcs[-1]]['y1'],
                  color='k')
        plt.xlim(x_range)
        plt.ylim(y_range)

    x_tic_label, xtics, y_tic_label, ytics = helper_define_tick_space(
        x_range, y_range)
    ax.set_yticks(ytics)
    ax.set_yticklabels(y_tic_label)
    ax.set_xticks(xtics)
    ax.set_xticklabels(x_tic_label)

    if plot_field:
        cbar = plt.colorbar(pcm, extend='both', drawedges=False)  # ax=ax[0],
        cbar.set_ticks([
            colormap_range[0], -one_forth_colormap, 0, one_forth_colormap,
            colormap_range[1]
        ])
        cbar.set_ticklabels([
            str(colormap_range[0]),
            str(-one_forth_colormap), '0',
            str(one_forth_colormap), colormap_range[1]
        ])

    if scale_type == 'micro':
        cbar.set_label(r"voltage ($\mu$V)", fontsize=18)
    elif scale_type == 'nano':
        cbar.set_label(r"voltage (nV)", fontsize=18)

#cbar.set_label(r"voltage ($\mu$V)", fontsize=18)
#cbar.set_label(r"voltage (nV)", fontsize=18)
    cbar.ax.tick_params(labelsize=16)

    if plot_current:
        # draw streamplots
        U = -np.diff(v_ext[time_pt, :, :], axis=0)[:, :-1]
        V = -np.diff(v_ext[time_pt, :, :], axis=1)[:-1, :]

        plt.streamplot(xx[0, :-1], yy[:-1, 0], V, U, density=1.0, color='g')

    plt.title('time: ' + str(("%0.2f" % (time_pt * dt))) + 'ms')

    ax.set_xlabel(r"space ($\mu$m)")
    ax.set_ylabel(r"space ($\mu$m)")

    clean_plot(ax)
    plt.tight_layout()
    return mycmap, colormap_range
Ejemplo n.º 11
0
seg_coords = cell.get_seg_coords()
n_samp = 40
x_range = [-210, 430]
y_range = [-255, 725]

# define grid
xx, yy = field.calc_grid(x_range, y_range, n_samp)

# join the currents together
I = I_cell.swapaxes(0, 1).reshape(I_cell.shape[1], -1)

v_ext = field.estimate_on_grid(seg_coords, I, xx, yy)

# PLOTS
synapses = [s for s in cell.get_point_processes()]

# plot neurons shape
graph.plot_neuron(seg_coords, colors='0.4')

# plot field potential
plt.imshow((v_ext[time_to_plot, :, :]),
           interpolation="nearest",
           extent=(x_range[0], x_range[1], y_range[0], y_range[1]),
           origin='lower')

cbar = plt.colorbar()
plt.xlabel(r'$\mu m$')
plt.ylabel(r'$\mu m$')
cbar.ax.set_ylabel('nV')
plt.show()
Ejemplo n.º 12
0
c_amp = np.sign(v_ext) * np.log(np.abs(v_ext) + 1)
levs = np.linspace(c_amp.min(), c_amp.max(), 10)
for i in range(n_frames):
    ampl = c_amp[i * shift, :, :]

    ## contour plot of the field
    ax = plt.subplot(3, 3, i + 1, frameon=False)
    plt.contour(xx, yy, ampl, colors='k', levels=levs)
    #graph.logcontour(xx, yy, np.abs(ampl))
    plt.xticks([])
    plt.yticks([])

    transAxesToFigure = (ax.transAxes + fig.transFigure.inverted())
    b = transforms.Bbox.from_bounds(0, 0.9, 0.3, 0.3)

    ax_inset = fig.add_axes(b.transformed(transAxesToFigure), frameon=False)

    ax_inset.plot(t, v_ext[:, Nsamp / 2., Nsamp / 2.])
    ax_inset.axvline(t[i * shift], color='b')
    ax_inset.set_xticks([])
    ax_inset.set_yticks([])

    if i == 0:
        ax_inset.set_xticks(win)
        ax_inset.xaxis.set_ticks_position('bottom')
        plt.sca(ax)
        graph.plot_neuron(coords, colors='r')

print __doc__.format(**vars())
plt.savefig('fig_field_timeframes.pdf')