Esempio n. 1
0
    def show(self):
        self.win = pg.GraphicsWindow()
        
        p5 = self.win.addPlot(title='stim')
        p5.plot(self.stim['left'][0].time * 1000., self.stim['left'][0].sound)

        p1 = self.win.addPlot(title='Bushy Vm', row=1, col=0)
        for k, ear in enumerate(self.ears.keys()):
            p1.plot(self['t'], self['vm_bu_%s' % ear], pen=(k, 15))
        
        p2 = self.win.addPlot(title='SGC-BU xmtr left', row=0, col=1)
        for i in range(30):
            p2.plot(self['t'], self['xmtr%d_left'%i], pen=(i, 15))
        p2.setXLink(p1)
        p2r = self.win.addPlot(title='SGC-BU xmtr right', row=1, col=1)
        for i in range(30):
            p2r.plot(self['t'], self['xmtr%d_right'%i], pen=(i, 15))
        p2r.setXLink(p1)        
        
        p3 = self.win.addPlot(title='MSO Vm', row=2, col=0)
        p3.plot(self['t'], self['vm_mso'])
        p3.setXLink(p1)
        
        p4 = self.win.addPlot(title='BU-MSO xmtr', row=2, col=1)
        for k, ear in enumerate(self.ears.keys()):
            for i in range(30):
                p2.plot(self['t'], self['mso_xmtr%d_%s'%(i, ear)], pen=(i, 15))
        p4.setXLink(p1)        

        p4 = self.win.addPlot(title='AN spikes', row=3, col=0)
        ntrain = len(self.sgc_cells['left'])
        for k in range(ntrain):
            yr = [k/float(ntrain), (k+0.8)/float(ntrain)]
            vt = pg.VTickGroup(self.sgc_cells['left'][k]._spiketrain, yrange = yr, pen=(k, 15))
            p4.addItem(vt)
        p4.setXLink(p1)
        p5.setXLink(p1)
        
        # phaselocking calculations
        phasewin = [self.stimdelay + 0.2*self.stimdur, self.stimdelay + self.stimdur]
        msospk = PU.findspikes(self['t'], self['vm_mso'], -30.)

        spkin = msospk[np.where(msospk > phasewin[0]*1e3)]
        spikesinwin = spkin[np.where(spkin <= phasewin[1]*1e3)[0]]

        # set freq for VS calculation
        f0 = self.f0
        fb = self.beatfreq
        vs = PU.vector_strength(spikesinwin, f0)

        print 'MSO Vector Strength at %.1f: %7.3f, d=%.2f (us) Rayleigh: %7.3f  p = %.3e  n = %d' % (f0, vs['r'], vs['d']*1e6, vs['R'], vs['p'], vs['n'])
        if fb > 0:
            vsb = PU.vector_strength(spikesinwin, fb)
            print 'MSO Vector Strength to beat at %.1f: %7.3f, d=%.2f (us) Rayleigh: %7.3f  p = %.3e  n = %d' % (fb, vsb['r'], vsb['d']*1e6, vsb['R'], vsb['p'], vsb['n'])
        (hist, binedges) = np.histogram(vs['ph'])
        p6 = self.win.addPlot(title='VS', row=3, col=1)
        p6.plot(binedges, hist, stepMode=True, fillBrush=(100, 100, 255, 150), fillLevel=0)
        p6.setXRange(0., 2*np.pi)
        
        self.win.show()
Esempio n. 2
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()
Esempio n. 3
0
    def show(self):
        self.win = pg.GraphicsWindow()
        self.win.setBackground('w')
        Fs = self.Fs
        p1 = self.win.addPlot(title='Stimulus',
                              row=0,
                              col=0,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'V'
                              })
        p1.plot(self.stim.time * 1000,
                self.stim.sound,
                pen=pg.mkPen('k', width=0.75))
        p1.setXLink(p1)

        p2 = self.win.addPlot(title='AN spikes',
                              row=1,
                              col=0,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'AN spikes (first trial)'
                              })
        for nr in range(self.nrep):
            xan = []
            yan = []
            for k in range(len(self.pre_cells[nr])):
                r = self.pre_cells[nr][k]._spiketrain
                xan.extend(r)
                yr = k + np.zeros_like(r) + 0.2
                yan.extend(yr)
            c = pg.PlotCurveItem()
            xp = np.repeat(np.array(xan), 2)
            yp = np.repeat(np.array(yan), 2)
            yp[1::2] = yp[::2] + 0.6
            c.setData(xp.flatten(),
                      yp.flatten(),
                      connect='pairs',
                      pen=pg.mkPen(pg.intColor(nr, self.nrep),
                                   hues=self.nrep,
                                   width=1.0))
            p2.addItem(c)
        p2.setXLink(p1)

        p3 = self.win.addPlot(title='%s Spikes' % self.cell,
                              row=2,
                              col=0,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'Trial #'
                              })
        xcn = []
        ycn = []
        xspks = []
        for k in range(self.nrep):
            bspk = PU.findspikes(self.time[k], self.vms[k], -35.)
            xcn.extend(bspk)
            yr = k + np.zeros_like(bspk) + 0.2
            ycn.extend(yr)
        d = pg.PlotCurveItem()
        xp = np.repeat(np.array(xcn), 2)
        yp = np.repeat(np.array(ycn), 2)
        yp[1::2] = yp[::2] + 0.6
        d.setData(xp.flatten(),
                  yp.flatten(),
                  connect='pairs',
                  pen=pg.mkPen('k', width=1.5))
        p3.addItem(d)
        p3.setXLink(p1)

        p4 = self.win.addPlot(title='%s Vm' % self.cell,
                              row=3,
                              col=0,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'Vm (mV)'
                              })
        for nr in range(self.nrep):
            p4.plot(self.time[nr],
                    self.vms[nr],
                    pen=pg.mkPen(pg.intColor(nr, self.nrep),
                                 hues=self.nrep,
                                 width=1.0))
        p4.setXLink(p1)

        p5 = self.win.addPlot(title='xmtr',
                              row=0,
                              col=1,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'gSyn'
                              })
        if synapseType == 'multisite':
            for nr in [0]:
                syn = self.synapses[nr]
                j = 0
                for k in range(self.n_sgc):
                    synapse = syn[k]
                    for i in range(synapse.terminal.n_rzones):
                        p5.plot(self.time[nr],
                                self.xmtrs[nr]['xmtr%04d' % j],
                                pen=pg.mkPen(pg.intColor(nr, self.nrep),
                                             hues=self.nrep,
                                             width=1.0))
                        j = j + 1
        p5.setXLink(p1)

        p6 = self.win.addPlot(title='AN PSTH',
                              row=1,
                              col=1,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'Sp/ms/trial'
                              })
        bins = np.arange(0, 200, 1)
        (hist, binedges) = np.histogram(xan, bins)
        curve6 = p6.plot(binedges,
                         hist,
                         stepMode=True,
                         fillBrush=(0, 0, 0, 255),
                         brush=pg.mkBrush('k'),
                         fillLevel=0)

        p7 = self.win.addPlot(title='%s PSTH' % self.cell,
                              row=2,
                              col=1,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'Sp/ms/trial'
                              })
        bins = np.arange(0, 200, 1)
        (hist, binedges) = np.histogram(xcn, bins)
        curve7 = p7.plot(binedges,
                         hist,
                         stepMode=True,
                         fillBrush=(0, 0, 0, 255),
                         brush=pg.mkBrush('k'),
                         fillLevel=0)

        self.win.show()
    def show(self):
        self.win = pg.GraphicsWindow()
        p1 = self.win.addPlot(title='stim', row=0, col=0)
        p1.plot(self.stim.time * 1000, self.stim.sound)
        p1.setXLink(p1)

        p2 = self.win.addPlot(title='AN spikes', row=1, col=0)
        vt = pg.VTickGroup(self.pre_cells[0]._spiketrain)
        p2.addItem(vt)
        p2.setXLink(p1)

        p3 = self.win.addPlot(title='%s Spikes' % self.cell, row=2, col=0)
        bspk = PU.findspikes(self['t'], self['vm'], -30.)
        bspktick = pg.VTickGroup(bspk)
        p3.addItem(bspktick)
        p3.setXLink(p1)

        p4 = self.win.addPlot(title='%s Vm' % self.cell, row=3, col=0)
        p4.plot(self['t'], self['vm'])
        p4.setXLink(p1)

        p5 = self.win.addPlot(title='xmtr', row=0, col=1)
        j = 0
        for k in range(self.n_sgc):
            synapse = self.synapses[k]
            for i in range(synapse.terminal.n_rzones):
                p5.plot(self['t'], self['xmtr%03d'%j], pen=(i, 15))
                j = j + 1
        p5.setXLink(p1)
        
        p6 = self.win.addPlot(title='AN phase', row=1, col=1)
        phasewin = [self.pip_start[0] + 0.25*self.pip_duration, self.pip_start[0] + self.pip_duration]
        prespk = self.pre_cells[0]._spiketrain  # just sample one...
        spkin = prespk[np.where(prespk > phasewin[0]*1e3)]
        spikesinwin = spkin[np.where(spkin <= phasewin[1]*1e3)]
        print "\nCell type: %s" % self.cell
        print "Stimulus: "

        # set freq for VS calculation
        if self.stimulus == 'tone':
            f0 = self.f0
            print "Tone: f0=%.3f at %3.1f dbSPL, cell CF=%.3f" % (self.f0, self.dbspl, self.cf)
        if self.stimulus == 'SAM':
            f0 = self.fMod
            print ("SAM Tone: f0=%.3f at %3.1f dbSPL, fMod=%3.1f  dMod=%5.2f, cell CF=%.3f" %
                 (self.f0, self.dbspl, self.fMod, self.dMod, self.cf))
        if self.stimulus == 'clicks':
            f0 = 1./self.click_rate
            print "Clicks: interval %.3f at %3.1f dbSPL, cell CF=%.3f " % (self.click_rate, self.dbspl, self.cf)
        vs = PU.vector_strength(spikesinwin, f0)
        
        print 'AN Vector Strength at %.1f: %7.3f, d=%.2f (us) Rayleigh: %7.3f  p = %.3e  n = %d' % (f0, vs['r'], vs['d']*1e6, vs['R'], vs['p'], vs['n'])
        (hist, binedges) = np.histogram(vs['ph'])
        p6.plot(binedges, hist, stepMode=True, fillBrush=(100, 100, 255, 150), fillLevel=0)
        p6.setXRange(0., 2*np.pi)

        p7 = self.win.addPlot(title='%s phase' % self.cell, row=2, col=1)
        spkin = bspk[np.where(bspk > phasewin[0]*1e3)]
        spikesinwin = spkin[np.where(spkin <= phasewin[1]*1e3)]
        vs = PU.vector_strength(spikesinwin, f0)
        print '%s Vector Strength: %7.3f, d=%.2f (us) Rayleigh: %7.3f  p = %.3e  n = %d' % (self.cell, vs['r'], vs['d']*1e6, vs['R'], vs['p'], vs['n'])
        (hist, binedges) = np.histogram(vs['ph'])
        p7.plot(binedges, hist, stepMode=True, fillBrush=(100, 100, 255, 150), fillLevel=0)
        p7.setXRange(0., 2*np.pi)
        p7.setXLink(p6)

        self.win.show()
Esempio n. 5
0
    def show(self):
        self.win = pg.GraphicsWindow()
        self.win.setBackground('w')
        Fs = self.Fs
        p1 = self.win.addPlot(title='Stimulus',
                              row=0,
                              col=0,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'V'
                              })
        p1.plot(self.stim.time * 1000,
                self.stim.sound,
                pen=pg.mkPen('k', width=0.75))
        p1.setXLink(p1)

        p2 = self.win.addPlot(title='AN spikes',
                              row=1,
                              col=0,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'AN spikes (first trial)'
                              })
        for nr in range(self.nrep):
            xan = []
            yan = []
            for k in range(len(self.pre_cells[nr])):
                r = self.pre_cells[nr][k]._spiketrain
                xan.extend(r)
                yr = k + np.zeros_like(r) + 0.2
                yan.extend(yr)
            c = pg.PlotCurveItem()
            xp = np.repeat(np.array(xan), 2)
            yp = np.repeat(np.array(yan), 2)
            yp[1::2] = yp[::2] + 0.6
            c.setData(xp.flatten(),
                      yp.flatten(),
                      connect='pairs',
                      pen=pg.mkPen(pg.intColor(nr, self.nrep),
                                   hues=self.nrep,
                                   width=1.0))
            p2.addItem(c)
        p2.setXLink(p1)

        p3 = self.win.addPlot(title='%s Spikes' % self.cell,
                              row=2,
                              col=0,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'Trial #'
                              })
        xcn = []
        ycn = []
        xspks = []
        for k in range(self.nrep):
            bspk = PU.findspikes(self.time[k], self.vms[k], -35.)
            xcn.extend(bspk)
            yr = k + np.zeros_like(bspk) + 0.2
            ycn.extend(yr)
        d = pg.PlotCurveItem()
        xp = np.repeat(np.array(xcn), 2)
        yp = np.repeat(np.array(ycn), 2)
        yp[1::2] = yp[::2] + 0.6
        d.setData(xp.flatten(),
                  yp.flatten(),
                  connect='pairs',
                  pen=pg.mkPen('k', width=1.5))
        p3.addItem(d)
        p3.setXLink(p1)

        p4 = self.win.addPlot(title='%s Vm' % self.cell,
                              row=3,
                              col=0,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'Vm (mV)'
                              })
        for nr in range(self.nrep):
            p4.plot(self.time[nr],
                    self.vms[nr],
                    pen=pg.mkPen(pg.intColor(nr, self.nrep),
                                 hues=self.nrep,
                                 width=1.0))
        p4.setXLink(p1)

        p5 = self.win.addPlot(title='xmtr',
                              row=0,
                              col=1,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'gSyn'
                              })
        if synapseType == 'multisite':
            for nr in [0]:
                syn = self.synapses[nr]
                j = 0
                for k in range(self.n_sgc):
                    synapse = syn[k]
                    for i in range(synapse.terminal.n_rzones):
                        p5.plot(self.time[nr],
                                self.xmtrs[nr]['xmtr%04d' % j],
                                pen=pg.mkPen(pg.intColor(nr, self.nrep),
                                             hues=self.nrep,
                                             width=1.0))
                        j = j + 1
        p5.setXLink(p1)

        p6 = self.win.addPlot(title='AN PSTH',
                              row=1,
                              col=1,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'Sp/ms/trial'
                              })
        bins = np.arange(0, 200, 1)
        (hist, binedges) = np.histogram(xan, bins)
        curve6 = p6.plot(binedges,
                         hist,
                         stepMode=True,
                         fillBrush=(0, 0, 0, 255),
                         brush=pg.mkBrush('k'),
                         fillLevel=0)

        p7 = self.win.addPlot(title='%s PSTH' % self.cell,
                              row=2,
                              col=1,
                              labels={
                                  'bottom': 'T (ms)',
                                  'left': 'Sp/ms/trial'
                              })
        bins = np.arange(0, 200, 1)
        (hist, binedges) = np.histogram(xcn, bins)
        curve7 = p7.plot(binedges,
                         hist,
                         stepMode=True,
                         fillBrush=(0, 0, 0, 255),
                         brush=pg.mkBrush('k'),
                         fillLevel=0)

        # p6 = self.win.addPlot(title='AN phase', row=1, col=1)
        # phasewin = [self.pip_start[0] + 0.25*self.pip_duration, self.pip_start[0] + self.pip_duration]
        # prespk = self.pre_cells[0]._spiketrain  # just sample one...
        # spkin = prespk[np.where(prespk > phasewin[0]*1e3)]
        # spikesinwin = spkin[np.where(spkin <= phasewin[1]*1e3)]
        # print "\nCell type: %s" % self.cell
        # print "Stimulus: "
        #
        # # set freq for VS calculation
        # if self.stimulus == 'tone':
        #     f0 = self.f0
        #     print "Tone: f0=%.3f at %3.1f dbSPL, cell CF=%.3f" % (self.f0, self.dbspl, self.cf)
        # if self.stimulus == 'SAM':
        #     f0 = self.fMod
        #     print ("SAM Tone: f0=%.3f at %3.1f dbSPL, fMod=%3.1f  dMod=%5.2f, cell CF=%.3f" %
        #          (self.f0, self.dbspl, self.fMod, self.dMod, self.cf))
        # if self.stimulus == 'clicks':
        #     f0 = 1./self.click_rate
        #     print "Clicks: interval %.3f at %3.1f dbSPL, cell CF=%.3f " % (self.click_rate, self.dbspl, self.cf)
        # vs = PU.vector_strength(spikesinwin, f0)
        #
        # print 'AN Vector Strength: %7.3f, d=%.2f (us) Rayleigh: %7.3f  p = %.3e  n = %d' % (vs['r'], vs['d']*1e6, vs['R'], vs['p'], vs['n'])
        # (hist, binedges) = np.histogram(vs['ph'])
        # curve = p6.plot(binedges, hist, stepMode=True, fillBrush=(100, 100, 255, 150), fillLevel=0)
        # p6.setXRange(0., 2*np.pi)
        #
        # p7 = self.win.addPlot(title='%s phase' % self.cell, row=2, col=1)
        # spkin = bspk[np.where(bspk > phasewin[0]*1e3)]
        # spikesinwin = spkin[np.where(spkin <= phasewin[1]*1e3)]
        # vs = PU.vector_strength(spikesinwin, f0)
        # print '%s Vector Strength: %7.3f, d=%.2f (us) Rayleigh: %7.3f  p = %.3e  n = %d' % (self.cell, vs['r'], vs['d']*1e6, vs['R'], vs['p'], vs['n'])
        # (hist, binedges) = np.histogram(vs['ph'])
        # curve = p7.plot(binedges, hist, stepMode=True, fillBrush=(100, 100, 255, 150), fillLevel=0)
        # p7.setXRange(0., 2*np.pi)
        # p7.setXLink(p6)

        self.win.show()