예제 #1
0
def showplots(name):
    """
    Show traces from sound stimulation - without current injection
    """
    f = open(name, 'r')
    d = pickle.load(f)
    f.close()
    ncells = len(d['results'])
    stiminfo = d['stim']
    dur = stiminfo['rundur'] * 1000.
    print 'dur: ', dur
    print 'stim info: '
    print '  fmod: ', stiminfo['fmod']
    print '  dmod: ', stiminfo['dmod']
    print '  f0:   ', stiminfo['f0']
    print '  cf:   ', stiminfo['cf']
    varsg = np.linspace(0.25, 2.0,
                        int((2.0 - 0.25) / 0.25) + 1)  # was not stored...
    fig, ax = mpl.subplots(ncells + 1, 2, figsize=(8.5, 11.))
    spikelists = [[]] * ncells
    prespikes = [[]] * ncells
    xmin = 50.
    for i in range(ncells):
        vdat = d['results'][i]['v']
        idat = d['results'][i]['i']
        tdat = d['results'][i]['t']
        pdat = d['results'][i]['pre']
        PH.noaxes(ax[i, 0])
        # if i == 0:
        #     PH.calbar(ax[0, 0], calbar=[120., -120., 25., 20.], axesoff=True, orient='left',
        #         unitNames={'x': 'ms', 'y': 'mV'}, fontsize=9, weight='normal', font='Arial')
        for j in range(len(vdat)):
            if j == 2:
                ax[i, 0].plot(tdat - xmin, vdat[j], 'k', linewidth=0.5)
            if j == 0:
                ax[i, 0].annotate('%.2f' % varsg[i], (180., 20.))

        ax[i, 0].set_xlim([0, dur - xmin])
        ax[i, 0].set_ylim([-75, 50])
        PH.referenceline(ax[i, 0],
                         reference=-62.0,
                         limits=None,
                         color='0.33',
                         linestyle='--',
                         linewidth=0.5,
                         dashes=[3, 3])

        for j in range(len(vdat)):
            detected = PU.findspikes(tdat, vdat[j], -20.)
            detected = clean_spiketimes(detected)
            spikelists[i].extend(detected)
            if j == 0:
                n, bins = np.histogram(detected,
                                       np.linspace(0., dur, 201),
                                       density=False)
            else:
                m, bins = np.histogram(detected,
                                       np.linspace(0., dur, 201),
                                       density=False)
                n += m
        prespikes[i].extend(pdat)
        if j == 0:
            n, bins = np.histogram(pdat,
                                   np.linspace(0., dur, 201),
                                   density=False)
        else:
            m, bins = np.histogram(pdat,
                                   np.linspace(0., dur, 201),
                                   density=False)
            n += m

        ax[i, 1].bar(bins[:-1] - xmin,
                     n,
                     width=bins[1],
                     facecolor='k',
                     alpha=0.75)
        ax[i, 1].set_xlim([0, dur - xmin])
        ax[i, 1].set_ylim([0, 30])
        vs = PU.vector_strength(spikelists[i], stiminfo['fmod'])
        pre_vs = PU.vector_strength(prespikes[i], stiminfo['fmod'])
        # print 'pre: ', pre_vs
        # print 'post: ', vs


#         apos = ax[i,1].get_position()
#         ax[i, 1].set_title('VS = %4.3f' % pre_vs['r'])
# #        vector_plot(fig, vs['ph'], np.ones(len(vs['ph'])), yp = apos)
#         phase_hist(fig, vs['ph'], yp=apos)
#        phase_hist(fig, pre_vs['ph'], yp=apos)
    prot = Variations(runtype, runname)
    #   stim_info = {'nreps': nrep, 'cf': cf, 'f0': f0, 'rundur': rundur, 'pipdur': pipdur, 'dbspl': dbspl, 'fmod': fmod, 'dmod': dmod}
    if stiminfo['dmod'] > 0:
        stimulus = 'SAM'
    else:
        stimulus = 'tone'
    prot.make_stimulus(stimulus=stimulus,
                       cf=stiminfo['cf'],
                       f0=stiminfo['f0'],
                       simulator=None,
                       rundur=stiminfo['rundur'],
                       pipdur=stiminfo['pipdur'],
                       dbspl=stiminfo['dbspl'],
                       fmod=stiminfo['fmod'],
                       dmod=stiminfo['dmod'])
    ax[-1, 1].plot(prot.stim.time * 1000. - xmin,
                   prot.stim.sound,
                   'k-',
                   linewidth=0.75)
    ax[-1, 1].set_xlim([0, (dur - xmin)])

    PH.noaxes(ax[-1, 0])
    ax[-1, 0].set_xlim([0, dur - xmin])
    ax[-1, 0].set_ylim([-75, 50])
    #    PH.referenceline(ax[-1, 0], reference=-62.0, limits=None, color='0.33', linestyle='--' ,linewidth=0.5, dashes=[3, 3])
    PH.calbar(ax[-1, 0],
              calbar=[20., 0., 25., 20.],
              axesoff=True,
              orient='left',
              unitNames={
                  'x': 'ms',
                  'y': 'mV'
              },
              fontsize=9,
              weight='normal',
              font='Arial')

    PH.cleanAxes(ax.ravel().tolist())

    mpl.show()
예제 #2
0
파일: IVPlots.py 프로젝트: pbmanis/VCNModel
    def plotResults(self, res, runInfo, somasite=['postsynapticV', 'postsynapticI', 'dendriteV']):
        clist={'axon': 'r', 'heminode': 'g', 'stalk':'y', 'branch': 'g', 'neck': 'b',
                'swelling': 'm', 'tip': 'k', 'parentaxon': '', r'synapse': 'c', 'Soma': 'k',
                'dendrite': 'c', 'dend': 'c'}
        dx = np.array([x for k,x in res['distanceMap'].items()])
        dlen = res['monitor']['postsynapticV'].shape[0]
        dxmax = np.max(dx)

        
        if self.plotmode == 'pg':
            self.plots['Soma'].setLabel('left', 'V')
            self.plots['Soma'].plot(res['monitor']['time'][:dlen], res['monitor']['postsynapticV'],
                pen=pg.mkPen(clist['Soma'], width=0.5), )
            if 'dendriteV' in somasite and self.plots['Dendrite'] is not None and len(res['monitor']['dendriteV']) > 0:
                self.plots['Dendrite'].plot(res['monitor']['time'][:dlen], 
                    res['monitor']['dendriteV'], pen=pg.mkPen(clist['dendrite'], width=0.5), )
                self.plots['Dendrite'].setLabel('left', 'V (mV)')
            if 'vec' in res.keys()and self.plots['p4'] is not None:
                for v in res['vec']:
                    self.plots['p4'].plot(res['monitor']['time'], res['vec'][v],
                                 pen=pg.mkPen(pg.intColor(int(255.*res['distanceMap'][v]/dxmax))),
                                 width=1.5)
            if 'postsynapticI' in somasite and self.plots['Iinj'] is not None:
                vlen = len(res['monitor']['postsynapticI'])
                self.plots['Iinj'].plot(res['monitor']['time'][0:vlen], res['monitor']['postsynapticI'],
                    pen = pg.mkPen('b', width=0.5))
                self.plots['Iinj'].setLabel('left', 'I (inj, nA)')
            if 'vec' in res.keys() and self.plots['p4'] is not None:
                for v in res['vec']:
                    self.plots['p4'].plot(res['monitor']['time'], res['vec'][v],
                                 pen=pg.mkPen(pg.intColor(int(255.*res['distanceMap'][v]/dxmax))),
                                 width=0.5)
            #for c in res['ICa']:
            #     self.plots['Dendrite'].plot(res['monitor']['time'], res['ICa'][c]*1e12, pen=pg.mkPen('b', width=1.5))
            #     self.plots['Iinj'].plot(res['vec']['time'], res['Cai'][c]*1e6, pen=pg.mkPen('g', width=1.5))

                    #p2.set_ylim(-5e-12, 1e-12)
            self.plots['Soma'].setXRange(0., 120., padding=0.2)
            self.plots['Dendrite'].setXRange(0., 120., padding=0.2)
            if self.plots['Iinj'] is not None:
                self.plots['Iinj'].setXRange(0., 120., padding=0.2)
            
            pgPH.cleanAxes([self.plots['Soma'], self.plots['Dendrite'], self.plots['Iinj'], self.plots['p4']])
            pgPH.nice_plot(self.plots['Soma'])
            pgPH.calbar(self.plots['Soma'], [110, -50, 20, 50])
           # pgPH.nice_plot(self.plots['Dendrite'])
        #    pgPH.calbar(self.plots['Dendrite'], [110, 0.1, 20, 1])
            if self.plots['Iinj'] is not None:
                pgPH.nice_plot(self.plots['Iinj'])
                pgPH.calbar(self.plots['Iinj'], [110, -0.1, 20, 1])


        elif self.plotmode == 'mpl':
            self.plots['Soma'].set_ylabel('V')
            self.plots['Soma'].plot(res['monitor']['time'][:dlen], res['monitor']['postsynapticV'],
            color=clist['Soma'], linewidth=0.5)
            if 'dendriteV' in somasite and self.plots['Dendrite'] is not None and len(res['monitor']['dendriteV']) > 0:
                self.plots['Dendrite'].plot(res['monitor']['time'][:dlen], 
                    res['monitor']['dendriteV'], color=clist['dendrite'], linewidth=0.5)
                self.plots['Dendrite'].set_ylabel('V (mV)')
            if 'vec' in res.keys()and self.plots['p4'] is not None:
                for v in res['vec']:
                    self.plots['p4'].plot(res['monitor']['time'], res['vec'][v],
                                 color=[[int(255.*res['distanceMap'][v]/dxmax)]*3],
                                 linewidth=0.75)
            if 'postsynapticI' in somasite and self.plots['Iinj'] is not None:
                vlen = len(res['monitor']['postsynapticI'])
                self.plots['Iinj'].plot(res['monitor']['time'][0:vlen], res['monitor']['postsynapticI'],
                    color='b', linewidth=0.5)
                self.plots['Iinj'].set_ylabel('I (inj, nA)')
            if 'vec' in res.keys() and self.plots['p4'] is not None:
                for v in res['vec']:
                    self.plots['p4'].plot(res['monitor']['time'], res['vec'][v],
                                 color=[[int(255.*res['distanceMap'][v]/dxmax)]*3],
                                 linewidth=0.75)
            #for c in res['ICa']:
            #     self.plots['Dendrite'].plot(res['monitor']['time'], res['ICa'][c]*1e12, pen=pg.mkPen('b', width=1.5))
            #     self.plots['Iinj'].plot(res['vec']['time'], res['Cai'][c]*1e6, pen=pg.mkPen('g', width=1.5))

                    #p2.set_ylim(-5e-12, 1e-12)
            self.plots['Soma'].set_xlim(0., 120.)
            self.plots['Dendrite'].set_xlim(0., 120.)
            if self.plots['Iinj'] is not None:
                self.plots['Iinj'].set_xlim(0., 120.)
            
            PH.cleanAxes([self.plots['Soma'], self.plots['Dendrite'], self.plots['Iinj']])
            PH.nice_plot(self.plots['Soma'])
            PH.calbar(self.plots['Soma'], [110, -50, 20, 50])
            PH.nice_plot(self.plots['Dendrite'])
            PH.calbar(self.plots['Dendrite'], [110, -50, 20, 50])
           # pgPH.nice_plot(self.plots['Dendrite'])
        #    pgPH.calbar(self.plots['Dendrite'], [110, 0.1, 20, 1])
            if self.plots['Iinj'] is not None:
                PH.nice_plot(self.plots['Iinj'])
                PH.calbar(self.plots['Iinj'], [110, -0.1, 20, 1])        
예제 #3
0
def run_democlamp(cell, dend, vsteps=[-60,-70,-60], tsteps=[10,50,100]):
    """
    Does some stuff.
    
    """
    f1 = pylab.figure(1)
    gs = GS.GridSpec(2, 2,
                       width_ratios=[1, 1],
                       height_ratios=[1, 1])

    # note numbering for insets goes from 1 (upper right) to 4 (lower right)
    # counterclockwise
    pA = f1.add_subplot(gs[0])
    pAi = INSETS.inset_axes(pA, width="66%", height="40%", loc=2)
    pB = f1.add_subplot(gs[1])
    pBi = INSETS.inset_axes(pB, width="66%", height="40%", loc=4)
    pC = f1.add_subplot(gs[2])
    pCi = INSETS.inset_axes(pC, width="66%", height="40%", loc=2)
    pD = f1.add_subplot(gs[3])
    pDi = INSETS.inset_axes(pD, width="66%", height="40%", loc=1)
    #h.topology()
    
    Ld = 0.5
    Ld2 = 1.0
    
    VClamp = h.SEClamp(0.5, cell)
    VClamp.dur1 = tsteps[0]
    VClamp.amp1 = vsteps[0]
    VClamp.dur2 = tsteps[1]
    VClamp.amp2 = vsteps[1]
    VClamp.dur3 = tsteps[2]
    VClamp.amp3 = vsteps[2]
    Rs0 = 10.
    VClamp.rs = Rs0
    compensation = [0., 70., 95.]
    cms = [cell.cm*(100.-c)/100. for c in compensation]
    
    vrec = h.iStim(Ld, sec=dend[0])
    vrec.delay = 0
    vrec.dur = 1e9 # these actually do not matter...
    vrec.iMax = 0.0
    vrec2 = h.iStim(Ld2, sec=dend[0])
    vrec2.delay = 0
    vrec2.dur = 1e9 # these actually do not matter...
    vrec2.iMax = 0.0

    stim = {}
    stim['NP'] = 1
    stim['Sfreq'] = 20 # stimulus frequency
    stim['delay'] = tsteps[0]
    stim['dur'] = tsteps[1]
    stim['amp'] = vsteps[1]
    stim['PT'] = 0.0
    stim['hold'] = vsteps[0]
#    (secmd, maxt, tstims) = make_pulse(stim)
    tend = 79.5
    linetype = ['-', '-', '-']
    linethick = [0.5, 0.75, 1.25]
    linecolor = [[0.66, 0.66, 0.66], [0.4, 0.4, 0.3], 'k'] 
    n = 0
    vcmds = [-70, -20]
    vplots = [(pA, pAi, pC, pCi), (pB, pBi, pD, pDi)]
    for m,  VX in enumerate(vcmds):
        stim['amp'] = VX
        pl = vplots[m]
        print m, VX
        (secmd, maxt, tstims) = make_pulse(stim)
        for n, rsc in enumerate(compensation):
            vec={}
            for var in ['VCmd', 'i_inj', 'time', 'Vsoma', 'Vdend',
                        'Vdend2', 'VCmdR']:
                vec[var] = h.Vector()
            VClamp.rs = Rs0*(100.-rsc)/100.
            cell.cm = cms[n]
           # print VClamp.rs, cell.cm, VClamp.rs*cell.cm
            vec['VCmd'] = h.Vector(secmd)
            vec['Vsoma'].record(cell(0.5)._ref_v, sec=cell)
            vec['Vdend'].record(dend[0](Ld)._ref_v, sec=dend[0])
            vec['time'].record(h._ref_t)
            vec['i_inj'].record(VClamp._ref_i, sec=cell)

            vec['VCmdR'].record(VClamp._ref_vc, sec=cell)
            VClamp.amp2 = VX
            #            vec['VCmd'].play(VClamp.amp2, h.dt, 0, sec=cell)

            h.tstop = tend
            h.init()
            h.finitialize(-60)
            h.run()
            vc = np.asarray(vec['Vsoma'])
            tc = np.asarray(vec['time'])
            
            # now plot the data, raw and as insets
            for k in [0, 1]:
                pl[k].plot(vec['time'], vec['i_inj'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n])
                yl = pl[k].get_ylim()
                if k == 0:
                    pass
                    #pl[k].set_ylim([1.5*yl[0], -1.5*yl[1]])
                else:
                    pass
            
            for k in [2,3]:
                pl[k].plot(vec['time'], vec['Vsoma'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n])
                pl[k].plot(vec['time'], vec['VCmdR'], color=linecolor[n], linestyle = '--', linewidth=1, dashes=(1,1))
                pl[k].plot(vec['time'], vec['Vdend'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n], dashes=(3,3))
                if VX < vsteps[0]:
                    pl[k].set_ylim([-72, -40])
                else:
                    pl[k].set_ylim([-62,VX+30])

    ptx = 10.8
    pBi.set_xlim([9.8, ptx])
    pAi.set_xlim([9.8, ptx])
    PH.setX(pAi, pCi)
    PH.setX(pBi, pDi)
    pD.set_ylim([-65, 10])
#    PH.setY(pC, pCi) # match Y limits
    PH.cleanAxes([pA, pAi, pB, pBi, pC, pCi, pD, pDi])
    PH.formatTicks([pA, pB, pC, pD], axis='x', fmt='%d')
    PH.formatTicks([pC, pD], axis='y', fmt='%d')
    PH.calbar(pAi, [ptx-1, 0, 0.2, 2.])
    PH.calbar(pCi, [ptx-1, -50., 0.2, 10])
    PH.calbar(pBi, [ptx-1, 0, 0.2, 10])
    PH.calbar(pDi, [ptx-1, -50., 0.2, 20])
    pylab.draw()
    pylab.show()