def do_unit_ISI_plot(session, area, unit,
    INFOXPOS = 70, LABELSIZE=8, NBINS=20, FMAX = 250):
    cla()
    spikes = []
    for trial in get_good_trials(session):
        spikes.append(cgid.spikes.get_spikes_event(
            session,area,unit,trial,6,-1000,0))
        spikes.append(cgid.spikes.get_spikes_event(
            session,area,unit,trial,8,-1000,0))
    ISI_events = array(list(flatten(map(diff,spikes))))
    SNR        = get_unit_SNR(session,area,unit)
    histc,edges = histogram(ISI_events, bins = linspace(0,FMAX,NBINS+1))
    dx         = diff(edges)[0]
    bar(edges[:-1]+dx*0.1,histc,width=dx*0.8,color=GATHER[-1],edgecolor=(0,)*4)
    allisi = array(ISI_events)
    K   = 20
    x,y = kdepeak(log(K+allisi[allisi>0]))
    x   = exp(x)-K
    y   = y/(K+x)
    y   = y*len(allisi)*dx
    plot(x,y,color=RUST,lw=1.5)
    mean_rate           = sum(map(len,spikes))/float(len(get_good_trials(session))*2)
    ISI_cv              = std(allisi)/mean(allisi)
    burstiness          = sum(allisi<5)/float(len(allisi))*100
    ll                  = 1./mean(allisi)
    expected_short_isi  = (1.0-exp(-ll*10))*100
    mode                = modefind(allisi)
    residual_burstiness = burstiness-expected_short_isi
    LH = LABELSIZE+4
    text(INFOXPOS,ylim()[1]-pixels_to_yunits(20   ),'Mean rate = %d Hz'%mean_rate,
        horizontalalignment='left',
        verticalalignment  ='bottom',fontsize=LABELSIZE)
    text(INFOXPOS,ylim()[1]-pixels_to_yunits(20+LH*1),'ISI CV = %0.2f'%ISI_cv,
        horizontalalignment='left',
        verticalalignment  ='bottom',fontsize=LABELSIZE)
    text(INFOXPOS,ylim()[1]-pixels_to_yunits(20+LH*2),'SNR = %0.1f'%SNR,
        horizontalalignment='left',
        verticalalignment  ='bottom',fontsize=LABELSIZE)
    text(INFOXPOS,ylim()[1]-pixels_to_yunits(20+LH*3),'Mode freq. = %0.1f'%mode,
        horizontalalignment='left',
        verticalalignment  ='bottom',fontsize=LABELSIZE)
    axvline(mode,lw=2,color=TURQUOISE)
    xlabel('ms',fontsize=LABELSIZE)
    ylabel('No. Events',fontsize=LABELSIZE)
    fudgey(10)
    fudgex(5)
    xlim(0,FMAX)
    nicex()
    nicey()
    title('Monkey %s area %s\nsession %s unit %s'%(session[0],area,session[-2:],unit),loc='center',fontsize=7)
    return mean_rate,ISI_cv,SNR,mode
def unit_ISI_plot(session,area,unit,epoch=((6,-1000,0),(8,-1000,0)),INFOXPOS=70,LABELSIZE=8,NBINS=20,TMAX=300,INFOYSTART=0,BURST=10):
    cla()
    spikes = []
    for trial in get_good_trials(session):
        try:
            e,a,b = epoch
            spikes.append(cgid.spikes.get_spikes_event(session,area,unit,trial,e,a,b))
        except:
            for e,a,b in epoch:
                spikes.append(cgid.spikes.get_spikes_event(session,area,unit,trial,e,a,b))
    ISI_events = array(list(flatten(map(diff,spikes))))
    SNR        = cgid.spikes.get_unit_SNR(session,area,unit)
    histc,edges = histogram(ISI_events, bins = linspace(0,TMAX,NBINS+1))
    dx         = diff(edges)[0]
    bar(edges[:-1]+dx*0.1,histc,width=dx*0.8,color=GATHER[-1],edgecolor=(0,)*4)
    allisi = array(ISI_events)
    K   = 20
    x,y = kdepeak(log(K+allisi[allisi>0]))
    x   = exp(x)-K
    y   = y/(K+x)
    y   = y*len(allisi)*dx
    plot(x,y,color=RUST,lw=1.5)
    mean_rate           = sum(map(len,spikes))/float(len(get_good_trials(session))*2)
    noburst = allisi[allisi>BURST]
    ISI_cv              = std(noburst)/mean(noburst)
    burstiness          = sum(allisi<BURST)/float(len(allisi))*100
    ll                  = 1./mean(allisi)
    expected_short_isi  = (1.0-exp(-ll*10))*100
    residual_burstiness = burstiness-expected_short_isi
    LH = LABELSIZE+4
    text(INFOXPOS,ylim()[1]-pixels_to_yunits(INFOYSTART   ),'Mean rate = %d Hz'%mean_rate,
        horizontalalignment='left',
        verticalalignment  ='bottom',fontsize=LABELSIZE)
    text(INFOXPOS,ylim()[1]-pixels_to_yunits(INFOYSTART+LH*1),'ISI CV = %0.2f'%ISI_cv,
        horizontalalignment='left',
        verticalalignment  ='bottom',fontsize=LABELSIZE)
    text(INFOXPOS,ylim()[1]-pixels_to_yunits(INFOYSTART+LH*2),'SNR = %0.1f'%SNR,
        horizontalalignment='left',
        verticalalignment  ='bottom',fontsize=LABELSIZE)
    xlabel('ms',fontsize=LABELSIZE)
    ylabel('No. Events',fontsize=LABELSIZE)
    fudgey(10)
    fudgex(5)
    xlim(0,TMAX)
    nicex()
    nicey()
    simpleaxis()
    title('Monkey %s area %s\nsession %s unit %s'%(session[0],area,session[-2:],unit),loc='center',fontsize=7)