示例#1
0
def cb(y, P, counter, current):
    solution = np.empty(len(y))
    for i, (v, w, f, l) in enumerate(P):
        solution[f:f + l] = (v if i else max(v, 0)) / w * g**np.arange(l)
    color = y.copy()
    ax1.plot(solution, c='k', zorder=-11, lw=1.3, clip_on=False)
    ax1.scatter(np.arange(len(y)), solution, s=40, cmap=plt.cm.Spectral,
                c=color, clip_on=False, zorder=11)
    ax1.scatter([np.arange(len(y))[current]], [solution[current]],
                s=120, lw=2.5, marker='+', color='b', clip_on=False, zorder=11)
    for a in P[::2]:
        ax1.axvspan(a[2], a[2] + a[3], alpha=0.1, color='k', zorder=-11)
    for x in np.where(trueSpikes)[0]:
        ax1.plot([x, x], [0, 2.3], lw=1.5, c='r', zorder=-12)
    ax1.set_xlim((0, len(y) - .5))
    ax1.set_ylim((0, 2.3))
    simpleaxis(ax1)
    ax1.set_xticks([])
    ax1.set_yticks([])
    ax1.set_ylabel('Fluorescence')
    for i, s in enumerate(np.r_[[0], solution[1:] - g * solution[:-1]]):
        ax2.plot([i, i], [0, s], c='k', zorder=-11, lw=1.4, clip_on=False)
    ax2.scatter(np.arange(len(y)), np.r_[[0], solution[1:] - g * solution[:-1]],
                s=40, cmap=plt.cm.Spectral, c=color, clip_on=False, zorder=11)
    ax2.scatter([np.arange(len(y))[current]],
                [np.r_[[0], solution[1:] - g * solution[:-1]][current]],
                s=120, lw=2.5, marker='+', color='b', clip_on=False, zorder=11)
    for a in P[::2]:
        ax2.axvspan(a[2], a[2] + a[3], alpha=0.1, color='k', zorder=-11)
    for x in np.where(trueSpikes)[0]:
        ax2.plot([x, x], [0, 1.55], lw=1.5, c='r', zorder=-12)
    ax2.set_xlim((0, len(y) - .5))
    ax2.set_ylim((0, 1.55))
    simpleaxis(ax2)
    ax2.set_xticks([])
    ax2.set_yticks([])
    ax2.set_xlabel('Time', labelpad=35, x=.5)
    ax2.set_ylabel('Spikes')
    plt.subplots_adjust(left=0.032, right=.995, top=.995, bottom=0.19, hspace=0.22)
    if save_figs:
        plt.savefig('video/%03d.pdf' % counter)
    plt.pause(1e-9)
    ax1.clear()
    ax2.clear()
示例#2
0
def cb(y, P, counter, current):
    solution = np.empty(len(y))
    for v, w, f, l in P:
        solution[f:f + l] = max(v, 0) / w * g**np.arange(l)
    plt.figure(figsize=(3, 3))
    color = y.copy()
    plt.plot(solution, c='k', zorder=-11, lw=1.2)
    plt.scatter(np.arange(len(y)), solution, s=60, cmap=plt.cm.Spectral,
                c=color, clip_on=False, zorder=11)
    plt.scatter([np.arange(len(y))[current]], [solution[current]],
                s=200, lw=2.5, marker='+', color='b', clip_on=False, zorder=11)
    for a in P[::2]:
        plt.axvspan(a[2], a[2] + a[3], alpha=0.1, color='k', zorder=-11)
    for x in np.where(trueSpikes)[0]:
        plt.plot([x, x], [0, 1.65], lw=1.5, c='r', zorder=-12)
    plt.xlim((0, len(y) - .5))
    plt.ylim((0, 1.65))
    simpleaxis(plt.gca())
    plt.xticks([])
    plt.yticks([])
    if save_figs:
        plt.savefig('fig/%d.pdf' % counter)
    plt.show()
示例#3
0
文件: fig3.py 项目: j-friedrich/OASIS
def plot_trace(n=0, lg=False):
    plt.plot(trueC[n], c=col[2], clip_on=False, zorder=5, label='Truth')
    plt.plot(solution, c=col[0], clip_on=False, zorder=7, label='Estimate')
    plt.plot(y,
             c=col[7],
             alpha=.7,
             lw=1,
             clip_on=False,
             zorder=-10,
             label='Data')
    if lg:
        plt.legend(frameon=False, ncol=3, loc=(.1, .62), columnspacing=.8)
    spks = np.append(0, solution[1:] - g * solution[:-1])
    plt.text(800,
             2.2,
             'Correlation: %.3f' % (np.corrcoef(trueSpikes[n], spks)[0, 1]),
             size=24)
    plt.gca().set_xticklabels([])
    simpleaxis(plt.gca())
    plt.ylim(0, 2.85)
    plt.xlim(0, 1500)
    plt.yticks([0, 2], [0, 2])
    plt.xticks([300, 600, 900, 1200], ['', '', '', ''])
示例#4
0
def plotTrace(lg=False):
    fig = plt.figure(figsize=(10, 9))
    fig.add_axes([.13, .7, .86, .29])
    plt.plot(c, c=col[0], label='L1')
    plt.plot(c_t, c=col[1], label='Thresh.')
    plt.plot(trueC[0], c=col[2], lw=3, label='Truth', zorder=-5)
    plt.plot(y, c=col[7], lw=1.5, alpha=.7, zorder=-10, label='Data')
    if lg:
        plt.legend(frameon=False, ncol=4, loc=(.05, .82))
    plt.gca().set_xticklabels([])
    simpleaxis(plt.gca())
    plt.yticks([0, int(y.max())], [0, int(y.max())])
    plt.xticks(range(150, 500, 150), [''] * 3)
    plt.ylabel('Fluor.')
    plt.xlim(0, 452)

    fig.add_axes([.13, .39, .86, .29])
    for i, ss in enumerate(s[:500]):
        if ss > 1e-2:
            plt.plot([i, i], [2.5, 2.5 + ss], c=col[0], zorder=10)
        plt.plot([0, 450], [2.5, 2.5], c=col[0], zorder=10)
    for i, ss in enumerate(s_t[:500]):
        if ss > 1e-2:
            plt.plot([i, i], [1.25, 1.25 + ss], c=col[1], zorder=10)
        plt.plot([0, 450], [1.25, 1.25], c=col[1], zorder=10)
    for i, ss in enumerate(trueSpikes[0, :500]):
        if ss > 1e-2:
            plt.plot([i, i], [0, ss], c=col[2], clip_on=False, zorder=10)
        plt.plot([0, 450], [0, 0], c=col[2], clip_on=False, zorder=10)
    plt.gca().set_xticklabels([])
    simpleaxis(plt.gca())
    plt.yticks([0, 1.25, 2.5], ['Truth', 'Thresh.', 'L1'])
    for tick in plt.gca().yaxis.get_major_ticks():
        tick.label1.set_verticalalignment('bottom')
    plt.xticks(range(150, 500, 150), [''] * 3)
    plt.ylim(0, 3.5)
    plt.xlim(0, 452)

    fig.add_axes([.13, .08, .86, .29])
    for i, r in enumerate(res):
        for rr in r:
            plt.plot([rr, rr], [.1 * i - .04, .1 * i + .04], c='k')
    for rr in np.where(trueSpikes[0])[0]:
        plt.plot([rr, rr], [-.08, -.16], c='r')
    plt.gca().set_xticklabels([])
    simpleaxis(plt.gca())
    plt.yticks([0, .5, 1], [0, 0.5, 1.0])
    plt.xticks(range(0, 500, 150), [0, 5, 10, ''])
    plt.ylim(-.2, 1.1)
    plt.xlim(0, 452)
    plt.ylabel(r'$s_{\min}$')
    plt.xlabel('Time [s]', labelpad=-10)
    plt.show()
示例#5
0
g = .95
sn = .3
Y, trueC, trueSpikes = gen_data()
N, T = Y.shape
result_oasis = oasisAR1(Y[0], g=g, lam=2.4)
result_foopsi = foopsi(Y[0], g=[g], lam=2.4)

fig = plt.figure(figsize=(20, 5.5))
fig.add_axes([.038, .57, .96, .42])
plt.plot(result_oasis[0], c=col[0], label='OASIS')
plt.plot(result_foopsi[0], '--', c=col[6], label='CVXPY')
plt.plot(trueC[0], c=col[2], label='Truth', zorder=-5)
plt.plot(Y[0], c=col[7], alpha=.7, zorder=-10, lw=1, label='Data')
plt.legend(frameon=False, ncol=4, loc=(.275, .82))
plt.gca().set_xticklabels([])
simpleaxis(plt.gca())
plt.ylim(Y[0].min(), Y[0].max())
plt.yticks([0, int(Y[0].max())], [0, int(Y[0].max())])
plt.xticks(range(750, 3000, 750), [''] * 3)
plt.ylabel('Fluor.')
plt.xlim(0, 2000)
fig.add_axes([.038, .13, .96, .42])
plt.plot(result_oasis[1], c=col[0])
plt.plot(result_foopsi[1], '--', c=col[6])
plt.plot(trueSpikes[0], c=col[2], lw=1.5, zorder=-10)
plt.gca().set_xticklabels([])
simpleaxis(plt.gca())
plt.yticks([0, 1], [0, 1])
plt.xticks([600, 1200, 1800, 2400], ['', 40, '', 80])
plt.xticks(range(0, 3000, 750), range(0, 100, 25))
plt.ylim(0, 1.)