Example #1
0
def plot_varygk_vthr(gkbarli,
                     indir,
                     vname='v_ais',
                     iname='icap_ais',
                     figpath=None,
                     binwidth=None):
    print vname
    plt.figure()
    for gkbar in gkbarli:
        gklab = labeldir.gkbar_lab(gkbar)
        gkdir = labeldir.gkbar_dir(gkbar)
        subdir = os.path.join(indir, gkdir)
        with open(os.path.join(subdir, 'fifos.p')) as f:
            fifos = pickle.load(f)
        vthrli = get_vthr_list(fifos, vname, iname)
        print np.mean(vthrli)

        if binwidth:
            bins = np.arange(min(vthrli), max(vthrli) + binwidth, binwidth)
            plt.hist(vthrli, label=gklab, alpha=0.7, bins=bins)
        else:
            plt.hist(vthrli, label=gklab, alpha=0.7)

    plt.xlabel('Voltage at threshold (mV)')
    plt.ylabel('# spikes')
    plt.legend(prop={'size': 12}, fancybox=True, framealpha=0.5)

    plt.tight_layout()
    if figpath:
        plt.savefig(figpath)
Example #2
0
def plot_gains(gkbarli,
               indir,
               figpath,
               normalized=False,
               cutoff=False,
               statlab=False):
    plt.figure()
    for gkbar in gkbarli:
        gkdir = labeldir.gkbar_dir(gkbar)
        subdir = os.path.join(indir, gkdir)
        transfdir = os.path.join(subdir, 'transfer')
        lab = labeldir.gkbar_lab(gkbar)
        if statlab:
            lab = lab + plotgain.get_statlab(indir)
        plotgain.plot_gain(transfdir, normalized, cutoff, label=lab)

    plt.xlabel('Frequency (Hz)')
    if normalized:
        plt.ylabel('Normalized gain')
        plt.ylim(bottom=0.01)
        if cutoff:
            plt.axhline(1 / np.sqrt(2),
                        color='black',
                        linewidth=3,
                        linestyle='dashed',
                        alpha=0.4)
    else:
        plt.ylabel('Gain (Hz/nA)')
        plt.ylim(bottom=100)
        if cutoff:
            plotgain.plot_cutoff(transfdir)
    plt.legend(loc=1, prop={'size': 12}, fancybox=True, framealpha=0.5)
    plt.tight_layout()
    plt.savefig(figpath)
Example #3
0
def plot_bifurc(gkbar_list, indir, color_li):

    for i, gkbar in enumerate(gkbar_list):
        gkdir = labeldir.gkbar_dir(gkbar)
        subdir = os.path.join(indir, gkdir)
        curtvec = np.load(os.path.join(subdir, 'curtvec.npy'))
        fpli = np.load(os.path.join(subdir, 'fpli.npy'))
        lab = labeldir.gkbar_lab(gkbar)
        color = color_li[i]
        plot_bifdiag(curtvec,
                     fpli,
                     label=lab,
                     newfig=False,
                     color=color,
                     ms=2.,
                     alpha=0.7)

    plt.xlabel('$I_{inpq}$ (nA)')
    # plt.xlim((0, 0.2))
    plt.ylabel('Membrane voltage at AIS (mV)')
    # plt.ylim((0, 80))
    plt.legend(loc=4, fancybox=True, framealpha=0.5)
    plt.minorticks_on()
    plt.tight_layout()
    plt.savefig('%s/bifurc.pdf' % indir)
    plt.show()
Example #4
0
def plot_gains(gkbarli, indir, figpath, normalized=False, statlab=False):

    plt.figure(figsize=(8, 4))

    for gkbar in gkbarli:
        gkdir = labeldir.gkbar_dir(gkbar)
        subdir = os.path.join(indir, gkdir)
        transfdir = os.path.join(subdir, 'transfer')

        transf = np.load(os.path.join(transfdir, 'transf.npy'))
        fvec = np.load(os.path.join(transfdir, 'fvec.npy'))
        gain = np.absolute(transf)
        phase = np.angle(transf)
        phase = np.negative(
            phase
        )  ## this is used before changing phase to negative in transfer.py

        lab = labeldir.gkbar_lab(gkbar)
        if statlab:
            statfile = os.path.join(subdir, 'spkstat.json')
            if not os.path.isfile(statfile):
                spkstat.get_spkstat_from_file(subdir)
            stat = jspar.load(statfile)
            stat_lab = '(frt:%.1f cv:%.2f lv:%.2f)' % (stat['frt'], stat['cv'],
                                                       stat['lv'])
            lab = lab + ' ' + stat_lab

        if normalized:
            gain = gain / gain[1]

        plt.subplot(121)
        plt.semilogx(fvec, gain, label=lab)

        plt.subplot(122)
        plt.semilogx(fvec, phase, label=lab)

    plt.subplot(121)
    plt.xlabel('Frequency (Hz)')
    if normalized:
        plt.ylabel('Gain')
    else:
        plt.ylabel('Gain (Hz/nA)')
    # plt.ylim(5e5, 2e6)
    plt.legend(loc=1, prop={'size': 8}, fancybox=True, framealpha=0.5)

    plt.subplot(122)
    plt.xlabel('Frequency (Hz)')
    plt.ylabel('Phase')
    # plt.legend(prop={'size':8}, loc=4)
    plt.legend(loc=1, prop={'size': 8}, fancybox=True, framealpha=0.5)
    plt.tight_layout()

    if figpath:
        plt.savefig(figpath)
Example #5
0
def plot_hists(indir, figpath, gkbarli, nbin=20):
    plt.figure()
    for gkbar in gkbarli:
        gkdir = labeldir.gkbar_dir(gkbar)
        subdir = os.path.join(indir, gkdir)
        spktimes = np.load(os.path.join(subdir, 'spktimes.npy'))
        gklab = labeldir.gkbar_lab(gkbar)
        ssg.plot_hist(spktimes, nbin, log=True, label=gklab)
    plt.xlabel('ISI (ms)')
    plt.ylabel('# ISI / total # ISI')
    plt.legend(loc=1, prop={'size': 14}, fancybox=True, framealpha=0.5)
    plt.savefig(figpath)
Example #6
0
def plot_thresh_hists(gkbarli, figpath):
    plt.figure(figsize=(23, 5))
    for gkbar in gkbarli:
        gklab = labeldir.gkbar_lab(gkbar)
        vthrli, ivslopeli, mvslopeli, indli = varygk_ivslope(gkbar, ppsubdir)

        gkdir = labeldir.gkbar_dir(gkbar)
        indir = os.path.join(ppsubdir, gkdir)
        with open(os.path.join(indir, 'fifos.p')) as f:
            fifos = pickle.load(f)
        mtslopeli = get_slope_list(fifos, 'time', 'nav_m', 'icap_ais')

        print gkbar
        print 'nspk', len(vthrli)
        print 'v', np.mean(vthrli)
        print 'didv', np.mean(ivslopeli)
        print 'dmdv', np.mean(mvslopeli)
        print 'dmdt', np.mean(mtslopeli)
        print 't2spk', 40 - np.mean(indli) * 0.025

        plt.subplot(141)
        plt.hist(vthrli, alpha=0.7, label=gklab)
        plt.subplot(142)
        plt.hist(ivslopeli, alpha=0.7, label=gklab)
        plt.subplot(143)
        plt.hist(mvslopeli, alpha=0.7, label=gklab)
        plt.subplot(144)
        plt.hist(mtslopeli, alpha=0.7, label=gklab)

    plt.subplot(141)
    plt.xlabel('Voltage at threshold (mV)')
    plt.ylabel('# spikes')
    plt.legend(prop={'size': 12}, fancybox=True, framealpha=0.5)

    plt.subplot(142)
    plt.xlabel('dI/dV (nA/mV)')
    plt.ylabel('# spikes')
    plt.legend(prop={'size': 12}, fancybox=True, framealpha=0.5)

    plt.subplot(143)
    plt.xlabel('dm/dV (/mV)')
    plt.ylabel('# spikes')
    plt.legend(prop={'size': 12}, fancybox=True, framealpha=0.5)

    plt.subplot(144)
    plt.xlabel('dm/dt (/ms)')
    plt.ylabel('# spikes')
    plt.legend(prop={'size': 12}, fancybox=True, framealpha=0.5)

    plt.tight_layout()
    plt.savefig(figpath)
Example #7
0
def plot_srcrs(indir, figpath, gkbarli, norder=10):
    plt.figure()
    for gkbar in gkbarli:
        gkdir = labeldir.gkbar_dir(gkbar)
        subdir = os.path.join(indir, gkdir)
        spktimes = np.load(os.path.join(subdir, 'spktimes.npy'))
        gklab = labeldir.gkbar_lab(gkbar)
        ssg.plot_srcr(spktimes, norder, label=gklab)
    plt.xlabel('Order')
    plt.ylabel('Spearman Rank Coefficient')
    plt.ylim((-0.025, 0.15))
    plt.legend(loc=1, prop={'size': 14}, fancybox=True, framealpha=0.5)
    plt.tight_layout()
    plt.savefig(figpath)
Example #8
0
def plot_ficurves(gkbarli,
                  indir,
                  marker='o-',
                  labapd='',
                  colorli=None,
                  **kwargs):
    for i, gkbar in enumerate(gkbarli):
        gkdir = labeldir.gkbar_dir(gkbar)
        lab = labeldir.gkbar_lab(gkbar)
        if labapd:
            lab = lab + labapd
        subdir = os.path.join(indir, gkdir)
        if colorli:
            color = colorli[i]
            kwargs['color'] = color

        plotficurve.plot_ficurve(subdir, marker, label=lab, **kwargs)
Example #9
0
def plot_ficurve(gkbarli, indir):
    for gkbar in gkbarli:
        gkdir = labeldir.gkbar_dir(gkbar)
        subdir = os.path.join(indir, gkdir)
        curtvec = np.load(os.path.join(subdir, 'curtvec.npy'))
        frtvec = np.load(os.path.join(subdir, 'frtvec.npy'))
        lab = labeldir.gkbar_lab(gkbar)
        plt.plot(curtvec, frtvec, 'o-', label=lab, ms=2., alpha=0.7)

    plt.xlabel('I (nA)')
    # plt.xlim((0, 0.2))
    plt.ylabel('Firing rate (Hz)')
    # plt.ylim((0, 80))
    plt.legend(loc=4, prop={'size': 7}, fancybox=True, framealpha=0.5)
    plt.minorticks_on()

    plt.savefig(os.path.join(indir, 'fi_curve.pdf'))
    plt.show()
Example #10
0
def plot_transfs(gkbarli, indir, figpath, statlab=False):
    plt.figure(figsize=(8, 4))
    for gkbar in gkbarli:
        gkdir = labeldir.gkbar_dir(gkbar)
        subdir = os.path.join(indir, gkdir)
        transfdir = os.path.join(subdir, 'transfer')
        lab = labeldir.gkbar_lab(gkbar)
        if statlab:
            lab = lab + plotgain.get_statlab(indir)
        plotgain.plot_transf(transfdir, label=lab)

    plt.subplot(121)
    plt.xlabel('Frequency (Hz)')
    plt.ylabel('Gain (Hz/nA)')
    plt.legend(loc=1, prop={'size': 12}, fancybox=True, framealpha=0.5)
    plt.subplot(122)
    plt.xlabel('Frequency (Hz)')
    plt.ylabel('Phase')
    plt.legend(loc=1, prop={'size': 12}, fancybox=True, framealpha=0.5)
    plt.tight_layout()
    plt.savefig(figpath)
Example #11
0
    frttarg = 5
    cvtarg = 1.
    tfcsubdir = labeldir.opt_subdir(tau, frttarg, cvtarg)
    optsubdir = os.path.join(optdir, tfcsubdir)
    threxsubdir = os.path.join(threxdir, tfcsubdir)

    # gkbar = 0
    # gkdir = labeldir.gkbar_dir(gkbar)
    # outdir = os.path.join(threxsubdir, gkdir)
    # # plot_traj_thresh(outdir, 'time', 'nav_m')
    # plot_align_from_file(outdir, 'nav_m')
    # plt.show()

    gkbarli = [0, 5e-3, 15e-3]
    trajcolorli = ['#1f77b4', '#ff7f0e', '#2ca02c']
    thrcolorli = ['darkblue', 'chocolate', 'darkgreen']

    for i, gkbar in enumerate(gkbarli):
        trajcolor = trajcolorli[i]
        thrcolor = thrcolorli[i]
        gkdir = labeldir.gkbar_dir(gkbar)
        outdir = os.path.join(threxsubdir, gkdir)
        # plot_traj_thresh(outdir, 'time', 'nav_m')
        gklab = labeldir.gkbar_lab(gkbar)
        plot_align_thresh(outdir, 'nav_m', trajcolor, thrcolor, label=gklab)
    plt.xlabel('time to spike (ms)')
    plt.ylabel('Nav gating variable $m$')
    plt.legend()
    plt.savefig(os.path.join(threxsubdir, 'mt.pdf'))
    plt.show()