def plot_preds(cellid, results, source, fname):
    fig = plt.figure(figsize=(18, 9))
    fig.set_facecolor('white')
    plt.suptitle('Experiment: %s: %s Source' % (cellid, source))
    cols = len(results)
    legend = True
    for i, [t, dat] in enumerate(results.iteritems()):
        #dat = results[t]
        pred = dat['pred']
        mn = dat['mn']
        std = dat['std']
        crr_pred = dat['crr_pred']
        crr_exp = dat['crr_exp']

        plot_mean_std(None, mn, std, '%s - Corr Trials to Mean: %.2f' %
                            (t, crr_exp), [2, cols, 1 + i], legend=legend)
        plot_prediction(pred, mn, 'Prediction Corr to Mean: %.2f' % (crr_pred),
                        [2, cols, cols + 1 + i], legend=legend)
        legend = False
    plt.subplots_adjust(left=0.05, bottom=0.06, right=0.97,
                        top=0.87, wspace=0.3, hspace=0.6)

    #plt.show()
    fig.savefig(fname + '.eps')
    fig.savefig(fname + '.png')
    plt.close(fig)
def plot_preds_fourier(cellid, results, fname):
    fig = plt.figure(figsize=(18, 9))
    fig.set_facecolor('white')
    plt.suptitle('Experiment: %s  Fourier Source' % (cellid))
    cols = len(results)
    legend = True
    for i, [t, dat] in enumerate(results.iteritems()):
        #dat = results[t]
        pred = dat['pred']
        mn = dat['mn']
        std = dat['mn']
        crr_pred = dat['crr_pred']
        crr_exp = dat['crr_exp']
        weights = dat['coefs'].mean(0)
        plot_params = dat['plot_params']

        plot_mean_std(None,
                      mn,
                      std,
                      '%s - Corr Trials to Mean: %.2f' % (t, crr_exp),
                      [3, cols, 1 + i],
                      legend=legend)
        plot_prediction(pred,
                        mn,
                        'Prediction Corr to Mean: %.2f' % (crr_pred),
                        [3, cols, cols + 1 + i],
                        legend=legend)
        legend = False
        all_weights = None
        inds = [0, 0]
        for f in plot_params['idx_four']:
            four_weights = weights[f].reshape(plot_params['four_shape'][0])
            ff = reverse_fft(four_weights)
            if all_weights is None:
                nx = int(np.sqrt(len(plot_params['idx_four'])))
                x = plot_params['four_shape'][0][0]
                xx = x * nx
                all_weights = np.zeros([xx, xx])
            all_weights[inds[0]:inds[0] + x, inds[1]:inds[1] + x] = ff
            inds[1] += x
            if inds[1] == xx:
                inds[0] += x
                inds[1] = 0
        plot_four(all_weights, [0, all_weights.max()],
                  [3, cols, 2 * cols + 1 + i],
                  interpolation='bilinear')
    plt.subplots_adjust(left=0.05,
                        bottom=0.06,
                        right=0.97,
                        top=0.87,
                        wspace=0.3,
                        hspace=0.6)

    #plt.show()
    fig.savefig(fname + '.eps')
    fig.savefig(fname + '.png')
    plt.close(fig)
def plot_preds_fourier(cellid, results, fname):
    fig = plt.figure(figsize=(18, 9))
    fig.set_facecolor('white')
    plt.suptitle('Experiment: %s  Fourier Source' % (cellid))
    cols = len(results)
    legend = True
    for i, [t, dat] in enumerate(results.iteritems()):
        #dat = results[t]
        pred = dat['pred']
        mn = dat['mn']
        std = dat['mn']
        crr_pred = dat['crr_pred']
        crr_exp = dat['crr_exp']
        weights = dat['coefs'].mean(0)
        plot_params = dat['plot_params']

        plot_mean_std(None, mn, std, '%s - Corr Trials to Mean: %.2f' %
                            (t, crr_exp), [3, cols, 1 + i], legend=legend)
        plot_prediction(pred, mn, 'Prediction Corr to Mean: %.2f' % (crr_pred),
                        [3, cols, cols + 1 + i], legend=legend)
        legend = False
        all_weights = None
        inds = [0, 0]
        for f in plot_params['idx_four']:
            four_weights = weights[f].reshape(plot_params['four_shape'][0])
            ff = reverse_fft(four_weights)
            if all_weights is None:
                nx = int(np.sqrt(len(plot_params['idx_four'])))
                x = plot_params['four_shape'][0][0]
                xx = x * nx
                all_weights = np.zeros([xx, xx])
            all_weights[inds[0]: inds[0] + x,
                        inds[1]: inds[1] + x] = ff
            inds[1] += x
            if inds[1] == xx:
                inds[0] += x
                inds[1] = 0
        plot_four(all_weights, [0, all_weights.max()],
                  [3, cols, 2 * cols + 1 + i],
                      interpolation='bilinear')
    plt.subplots_adjust(left=0.05, bottom=0.06, right=0.97,
                        top=0.87, wspace=0.3, hspace=0.6)

    #plt.show()
    fig.savefig(fname + '.eps')
    fig.savefig(fname + '.png')
    plt.close(fig)
def plot_preds(cellid, results, source, fname):
    fig = plt.figure(figsize=(18, 9))
    fig.set_facecolor('white')
    plt.suptitle('Experiment: %s: %s Source' % (cellid, source))
    cols = len(results)
    legend = True
    for i, [t, dat] in enumerate(results.iteritems()):
        #dat = results[t]
        pred = dat['pred']
        mn = dat['mn']
        std = dat['std']
        crr_pred = dat['crr_pred']
        crr_exp = dat['crr_exp']

        plot_mean_std(None,
                      mn,
                      std,
                      '%s - Corr Trials to Mean: %.2f' % (t, crr_exp),
                      [2, cols, 1 + i],
                      legend=legend)
        plot_prediction(pred,
                        mn,
                        'Prediction Corr to Mean: %.2f' % (crr_pred),
                        [2, cols, cols + 1 + i],
                        legend=legend)
        legend = False
    plt.subplots_adjust(left=0.05,
                        bottom=0.06,
                        right=0.97,
                        top=0.87,
                        wspace=0.3,
                        hspace=0.6)

    #plt.show()
    fig.savefig(fname + '.eps')
    fig.savefig(fname + '.png')
    plt.close(fig)
             sigs.append(len(trl))
             if len(trl) == 0:
                 trl = [0]
             ys.append(np.mean(trl))
             stds.append(np.std(trl))
         xs = np.array(xs)
         ys = np.array(ys)
         stds = np.array(stds)
         if (ys + stds).max() > mx:
             mx = (ys + stds).max()
         sigs = np.array(sigs)
         plt.figure(fig1.number)
         axs.append(
             plot_mean_std(xs,
                           ys,
                           stds,
                           title, [a, b, cnt],
                           legend=False,
                           line='-o'))
         plt.xlim(shifts.min() - 0.5, shifts.max() + 0.5)
         plt.xticks(xaxis_time)
         plt.figure(fig2.number)
         plot_mean_std(xs,
                       sigs,
                       np.zeros_like(sigs),
                       title, [a, b, cnt],
                       legend=False,
                       line='-o')
         plt.xlim(shifts.min() - 0.5, shifts.max() + 0.5)
         plt.ylim(0, n)
 plt.figure(fig1.number)
 plt.subplots_adjust(left=0.03,
                 crr_sum[k][str(shift)] = [len(trl[trl != 0]),
                                         trl.tolist()]
             trl = trl[trl != 0]
             sigs.append(len(trl))
             if len(trl) == 0:
                 trl = [0]
             ys.append(np.mean(trl))
             stds.append(np.std(trl))
         xs = np.array(xs)
         ys = np.array(ys)
         stds = np.array(stds)
         if (ys + stds).max() > mx:
             mx = (ys + stds).max()
         sigs = np.array(sigs)
         plt.figure(fig1.number)
         axs.append(plot_mean_std(xs, ys, stds, title, [a, b, cnt],
                                  legend=False, line='-o'))
         plt.xlim(shifts.min() - 0.5, shifts.max() + 0.5)
         plt.xticks(xaxis_time)
         plt.figure(fig2.number)
         plot_mean_std(xs, sigs, np.zeros_like(sigs), title, [a, b, cnt],
                       legend=False, line='-o')
         plt.xlim(shifts.min() - 0.5, shifts.max() + 0.5)
         plt.ylim(0, n)
 plt.figure(fig1.number)
 plt.subplots_adjust(left=0.03, bottom=0.05, right=0.97, top=0.95,
                    wspace=0.23, hspace=0.1)
 stim_types = sorted(stim_types)
 stim_types_short = []
 for s in stim_types:
     stim_types_short.append(s[:s.find('_')])
 mx *= 1.1