コード例 #1
0
ファイル: syncmeasure.py プロジェクト: tommct/neuronpy
 def plot_spikes(self):
     self.raster_ax.clear()
     sp = spikeplot.SpikePlot(fig=self.fig, savefig=False)
     sp.set_markercolor('red')
     sp.set_markeredgewidth(2.)
     sp.plot_spikes(
         [self.ref],
         label='ref',
         draw=False,
     )
     sp.set_markercolor('blue')
     sp.plot_spikes([self.comp + self.t],
                    label='comp',
                    cell_offset=1,
                    draw=False)
     coincidences, mask_a, mask_b, ratio = \
             spiketrain.get_sync_traits( self.ref, self.comp+self.t, window=5)
     idx = 0
     for i in mask_a:
         if i == 1:
             self.raster_ax.plot([self.ref[idx]], [.6],
                                 marker='o',
                                 color='red')
         idx += 1
     idx = 0
     for i in mask_b:
         if i == 1:
             self.raster_ax.plot([self.comp[idx] + self.t], [2.4],
                                 marker='o',
                                 color='blue')
         idx += 1
     self.raster_ax.set_yticks([1, 2])
     self.raster_ax.set_yticklabels(['', '%+.1f ms' % self.t])
     self.raster_ax.set_xlim(self.axlim)
コード例 #2
0
    def plot(self):
        # spiketrains should be all the times of the spikes in a list separated by neuron, a list of lists
        spiketrains = self.get_spiketrains()

        sp = spikeplot.SpikePlot()
        sp.set_markerscale(0.5)

        sp.plot_spikes(spiketrains)
コード例 #3
0
    def plot_one_neuron(self, neuron):
        if neuron in self.recordings:
            spiketrain = self.recordings[neuron]

        sp = spikeplot.SpikePlot()
        sp.set_markerscale(0.5)

        sp.plot_spikes(spiketrain)
コード例 #4
0
ファイル: SNN.py プロジェクト: Amri95/snn-thesis
def show_plots(time, v_plts, currents, spikes):
    plt.figure('A')
    plt.plot(time, v_plts[0], 'g-')
    plt.plot(time, currents[0], 'r-')
    plt.figure('B')
    plt.plot(time, v_plts[1], 'b-')
    plt.plot(time, currents[1], 'y-')
    plt.figure('X')
    plt.plot(time, v_plts[2], 'k-')
    plt.plot(time, currents[2], 'm-')
    plt.figure('All')
    plt.plot(time, v_plts[0], 'g-')
    plt.plot(time, currents[0], 'r-')
    plt.plot(time, v_plts[1], 'b-')
    plt.plot(time, currents[1], 'y-')
    plt.plot(time, v_plts[2], 'k-')
    plt.plot(time, currents[2], 'm-')
    sp = spikeplot.SpikePlot()
    sp.plot_spikes(spikes)
    plt.show()
コード例 #5
0
ax1.legend(field, ['field'])
ax1.set_ylabel('mV')
ax1.set_xlabel('time (ms)')

#----------------------------------------------------------------------------
# Raster plot
#----------------------------------------------------------------------------
labels = ['PY', 'IN', 'TC', 'RE']
y = [50, 150, 250, 350]
fig_handle = pyplot.figure(figsize=(8, 4))
ax = fig_handle.add_subplot(111)
ax.set_title('Raster plot')
ax.set_xlabel('$t$ (ms)')  # Note LaTeX
ax.set_yticks([])

sp = spikeplot.SpikePlot(fig=fig_handle)
sp.set_markerscale(2)
sp.set_marker('.')

PYspikes = spiketrain.netconvecs_to_listoflists(PYtimevec, PYidvec)
sp.set_markercolor('black')
sp.plot_spikes(PYspikes, draw=False, label='PY')

INspikes = spiketrain.netconvecs_to_listoflists(INtimevec, INidvec)
sp.set_markercolor('blue')
sp.plot_spikes(INspikes, cell_offset=len(PYspikes), label='IN')

TCspikes = spiketrain.netconvecs_to_listoflists(TCtimevec, TCidvec)
sp.set_markercolor('red')
sp.plot_spikes(TCspikes, cell_offset=len(PYspikes) + len(INspikes), label='TC')
コード例 #6
0
tau_inh = 5
tau_ADP = 200
A_inh = -4
A_ADP = 10
V_ADP = 0 
V_inh = 0
k_inh = math.exp(-1.0/tau_inh)
k_adp = math.exp(-1.0/tau_ADP)

spiketrain = []

for time in range(2000):
    
    V_ADP = V_ADP*k_ADP
    V_inh = V_inh*k_inh
    
    V = V_rest + V_ADP + V_inh
    
    if V > V_thresh:
        V = V_rest
        V_inh = V_inh + A_inh
        V_ADP = A_ADP
        spiketrain.append(time)
    
sp = spikeplot.SpikePlot()
sp.set_markerscale(0.5)

sp.plot_spikes(spiketrain)

コード例 #7
0
    #                           i, i+1, gap_w, 0)

    soma_v_vec = [[] for y in range(myN)]
    dend_v_vec = [[] for y in range(myN)]
    t_vec = [[] for y in range(myN)]
    for i in range(myN):
        soma_v_vec[i], dend_v_vec[i], t_vec[i] = \
        simrun.set_recording_vectors(ring.cells[i])

    simrun.simulate(tstop=100)

    for i in [5, 15, 25, 35, 45]:
        simrun.show_output(soma_v_vec[i], dend_v_vec[i], t_vec[i])
    pyplot.show()

    #Uncomment shape3D() above to make this worthwhile
    #shape_window = h.PlotShape()
    #shape_window.exec_menu('Show Diam')

    spikes = ring.get_spikes()
    if len(spikes) > 1:
        from neuronpy.graphics import spikeplot
        filename = 'spikeplot' + str(nSim) + '.png'
        sp = spikeplot.SpikePlot(savefig=False)
        sp.set_fig_name(fig_name=filename)
        sp.set_marker('.')
        sp.set_markerscale(1.5)
        sp.set_markercolor('red')
        #sp.set_markeredgewidth(7)
        sp.plot_spikes(spikes)
コード例 #8
0
def raster(pair=[0,4], cluster_width=5, fi=.005, xlim=(1000,2000)):
#    pos1 = (10+pair[0]*20, cluster_width, 1, pair)
#    pos2 = (10+pair[1]*20, cluster_width, 1, pair)
#    stim_odor_mags = numpy.ones(5)*.55

    fig = pyplot.figure(figsize=(9.5,5.7))
    raster_ax = fig.add_axes([.1,.1,.8,.27])
    schematic_ax = fig.add_axes([.1,.85,.8,.1])
    syn_ax = fig.add_axes([.1,.45,.8,.225])

    draw_cell(pair[0], schematic_ax, color='red')
    draw_cell(pair[1], schematic_ax, color='blue')
    draw_weights(pair, schematic_ax, color='black')

    # Analyze an output file in some_dir
    bulb_spikes = BulbSpikes(sim_time=sim_var['tstop'])
    bulb_spikes.read_file(os.path.join(homedir,'spikeout.spk'))
    breath_events = numpy.loadtxt(os.path.join(homedir, 'breathevents.txt'))

    wts = read_weightevents()
    delays = read_delayevents()
    
    dt = 1
    tstop = xlim[1]
    x = numpy.arange(0,tstop,dt)
    y0 = numpy.zeros(tstop/dt)
    y1 = numpy.zeros(tstop/dt)
    EXP = numpy.exp(numpy.multiply(x,-1./200.))-numpy.exp( \
            numpy.multiply(x,-1./20.))
    
    idx = 0
    for b in breath_events:
        if b >= tstop:
            break
        else:
            dtidx = int((b+delays[pair[0]][idx])/dt)
            y0[dtidx:] += EXP[:-dtidx]*wts[pair[0]][idx]
            dtidx = int((b+delays[pair[1]][idx])/dt)
            y1[dtidx:] += EXP[:-dtidx]*wts[pair[1]][idx]
        idx += 1
    redplt = syn_ax.plot(x,y0, color='red')
    blueplt = syn_ax.plot(x,y1, color='blue')
    for breath in breath_events:
        breathplt = syn_ax.plot([breath, breath], [0,2], linestyle='--', \
                color='gray', linewidth=2)
    syn_ax.set_xlim(xlim)
    syn_ax.set_ylim(0,1.6)
    syn_ax.set_yticks([])
    syn_ax.set_xticks([])
    syn_ax.set_ylabel('EPSC onto tuft')
    leg = syn_ax.legend([breathplt, redplt, blueplt], \
            ['sniff event', 'input onto red', 'input onto blue'], \
            bbox_to_anchor=(0, 1.15, 1., .102), loc=1, ncol=3, mode="expand", \
            borderaxespad=0., handletextpad=.2)
    # Mark sniff interval
    for i in range(len(breath_events)):
        if breath_events[i] > xlim[0]:
            span = syn_ax.annotate('', xy=(breath_events[i], .28),  xycoords='data',
                               xytext=(breath_events[i+1], .28), \
                               textcoords='data', \
                               arrowprops=dict(arrowstyle="|-|", linewidth=2)
                               )
    
            syn_ax.text((breath_events[i]+breath_events[i+1])/2., .53, \
                    'sniff every\n150 - 250 ms', \
                    horizontalalignment='center', verticalalignment='top', \
                    backgroundcolor='white')
            break

    # Mark amplitude interval
    span = syn_ax.annotate('', xy=(1190, 1.28),  xycoords='data',
                       xytext=(1190, 1.12), \
                       textcoords='data', \
                       arrowprops=dict(arrowstyle="|-|", linewidth=2)
                       )

    syn_ax.text(1215, 1.21, \
            '+/- 5%', \
            horizontalalignment='left', verticalalignment='center')
    
    # Mark delay interval
    for i in range(len(breath_events)):
        if breath_events[i] > 1400:
            span = syn_ax.annotate('', xy=(breath_events[i]-2, .5),  xycoords='data',
                               xytext=(breath_events[i]+17, .5), \
                               textcoords='data', \
                               arrowprops=dict(arrowstyle="|-|", linewidth=2)
                               )
    
            syn_ax.text(breath_events[i]+7.5, .28, \
                    'delay 0-15 ms', \
                    horizontalalignment='center', verticalalignment='top', \
                    backgroundcolor='white')
            break
    

    spikes = bulb_spikes.get_mitral_spikes()
    ref=spikes[pair[0]]
    comp=spikes[pair[1]]
    gcspikes = bulb_spikes.get_granule_spikes()
    mididx = 10+pair[0]*20
    gcleft = gcspikes[mididx-int(cluster_width/2.):mididx+int(cluster_width/2.)+1]
    mididx = 10+pair[1]*20
    gcright = gcspikes[mididx-int(cluster_width/2.):mididx+int(cluster_width/2.)+1]

    sp = spikeplot.SpikePlot(fig=fig, savefig=False)
    sp.set_markercolor('blue')
    sp.set_markeredgewidth(2.)
    sp.set_markerscale(4)
    sp.plot_spikes([comp], label='comp', cell_offset=cluster_width*2+5, \
            draw=False )
    sp.set_markercolor('red')
    sp.plot_spikes([ref], label='ref', cell_offset=cluster_width*2+2, \
            draw=False)
    sp.set_markerscale(1.3)

    sp.set_markeredgewidth(1.5)
    sp.set_markercolor('blue')
    sp.plot_spikes(gcright, label='gcright', cell_offset=cluster_width, \
            draw=False)
    sp.set_markercolor('red')
    sp.plot_spikes(gcleft, label='gcleft', cell_offset=0, \
            draw=False)

    coincidences, mask_a, mask_b, ratio = \
            spiketrain.get_sync_traits(ref, comp, window=5)
#        idx = 0
#        for i in mask_a:
#            if i == 1:
#                raster_ax.plot([ref[idx]],[cluster_width*2+1.9], marker='o', color='red')
#            idx += 1
    idx = 0
    for i in mask_b:
        if i == 1:
            if comp[idx] >= xlim[0] and comp[idx] < xlim[1]:
                raster_ax.text(comp[idx],cluster_width*2+8.5, '*', \
                    color='purple', fontweight='bold', \
                    horizontalalignment='center', verticalalignment='center')
            #raster_ax.plot([comp[idx]],[cluster_width*2+7], marker='o', color='blue')
        idx += 1

    raster_ax.text(2000,cluster_width*2+8.5, '(synchronized)', color='purple', \
            horizontalalignment='center', verticalalignment='center',
            fontsize=11)

    raster_ax.set_yticks([])
    ylim = (0.5, cluster_width*2+7.5)
    for breath in breath_events:
        raster_ax.plot([breath, breath], [ylim[0], ylim[1]], linestyle='--', color='gray', linewidth=2)

    sp.update_xlim(xlim)
    raster_ax.set_ylim(ylim)
    raster_ax.set_xlabel('time (ms)')
    raster_ax.set_ylabel('spike output\n  granule      mitral\n\n', horizontalalignment='center')

    pos = schematic_ax.get_position()
    schematic_ax.text(.025, pos.ymax+.02, 'A)', transform=fig.transFigure, 
          verticalalignment='baseline')
    pos = syn_ax.get_position()
    syn_ax.text(.025, pos.ymax+.07, 'B)', transform=fig.transFigure, 
          verticalalignment='baseline')            
    pos = raster_ax.get_position()
    raster_ax.text(.025, pos.ymax+.02, 'C)', transform=fig.transFigure, 
          verticalalignment='baseline')            

#    fig.savefig(os.path.join(analysis_path, 'raster_w%d_(%d-%d)_%.3f.pdf') %(cluster_width, pair[0], pair[1], fi))
    fig.savefig(os.path.join(analysis_path, 'fig1.pdf'))
コード例 #9
0
    for a in range(Ncells):
        cells[a].soma.el_clarke =\
        (cells[a].soma.ina_clarke + cells[a].soma.ikrect_clarke\
        + cells[a].soma.icaN_clarke + cells[a].soma.icaL_clarke\
        + cells[a].soma.ikca_clarke + cells[a].soma.inap_clarke\
        + cells[a].soma.gl_clarke*cells[a].soma.v) / cells[a].soma.gl_clarke

        cells[a].dend.e_pas =\
        (cells[a].dend.g_pas * cells[a].dend.v) / cells[a].dend.g_pas


#    print 'hello from inside init'

h.celsius = 37
net = ClarkeNetwork()
h.v_init = -65
fih = h.FInitializeHandler(2, (tweak_leak, (net.cells, len(net.cells))))
shape_window = h.PlotShape()
shape_window.exec_menu('Show Diam')
soma_v_vec, soma_m_vec, soma_h_vec, soma_n_vec,\
     soma_inap_vec, soma_idap_vec, soma_ical_vec,\
     soma_ican_vec, soma_ikca_vec, soma_ina_vec, soma_ikrect_vec,\
    dend_v_vec, t_vec\
    = simrun.set_recording_vectors(net.cells[0])

simrun.simulate(tstop=10000)
simrun.show_output(soma_v_vec, dend_v_vec, t_vec)
pyplot.show()
spikes = net.get_spikes()
sp = spikeplot.SpikePlot(savefig=True)
sp.plot_spikes(spikes)