def compute_slope(data):
    """Compute the slope of the function relating changes in grating frequency
    to changes in the most effective noise frequency."""

    #compute slopes for observers
    all_dips = np.full((3, 8), np.nan)
    grating_freqs = [grating_frequencies[gf] for gf in
                        np.unique(data.grating_freq)]
    grating_freqs.sort()
    for i, vp_data in enumerate(data.by_field('vp')):
        for j, freq_data in enumerate(vp_data.by_field('grating_freq')):
            if freq_data.vp[0] == 'n4' and freq_data.grating_freq[0]==.2:
                continue
            fit = fit_gaussian(freq_data, constrained=True)
            try:
                all_dips[j, i] = fit.best_values['center']
            except KeyError:
                pass
    all_dips = np.ma.MaskedArray(all_dips, np.isnan(all_dips))
    slope_low = (all_dips[1] / all_dips[0]).mean() / (grating_freqs[1] /
            grating_freqs[0])
    slope_high = (all_dips[2] / all_dips[1]).mean() / (grating_freqs[2] /
            grating_freqs[1])
    # bootstrap slopes
    slope_dist_low = np.full(10000, np.nan)
    slope_dist_high = np.full(10000, np.nan)
    for i in xrange(10000):
        ratio_low = (all_dips[1] / all_dips[0]).compressed()
        ratio_high = (all_dips[2] / all_dips[1]).compressed()
        slope_dist_low[i] = np.random.choice(ratio_low, len(ratio_low)).mean()
        slope_dist_high[i] = np.random.choice(ratio_high, len(ratio_high)).mean()
    slope_dist_low /= (grating_freqs[1] / grating_freqs[0])
    slope_dist_high /= (grating_freqs[2] / grating_freqs[1])



    # compute slope for models
    model_dips = np.full((2, 2), np.nan)
    biwam = evaluate_models.get_model_data('biwam')
    flodog = evaluate_models.get_model_data('flodog')
    for i, model_data in enumerate([biwam, flodog]):
        model_data = model_data[model_data.grating_freq!=.2]
        for j, freq_data in enumerate(model_data.by_field('grating_freq')):
            fit = evaluate_models.fit_gaussian(freq_data, constrained=True)
            try:
                model_dips[j, i] = fit.best_values['center']
            except KeyError:
                pass
    slope_biwam = model_dips[1, 0] / model_dips[0, 0] / (grating_freqs[2] /
                        grating_freqs[1])
    slope_flodog = model_dips[1, 1] / model_dips[0, 1] / (grating_freqs[2] /
                        grating_freqs[1])

    return (slope_low, slope_high, slope_dist_low, slope_dist_high,
            slope_biwam, slope_flodog)
Пример #2
0
def compute_slope(data):
    """Compute the slope of the function relating changes in grating frequency
    to changes in the most effective noise frequency."""

    #compute slopes for observers
    all_dips = np.full((3, 8), np.nan)
    grating_freqs = [
        grating_frequencies[gf] for gf in np.unique(data.grating_freq)
    ]
    grating_freqs.sort()
    for i, vp_data in enumerate(data.by_field('vp')):
        for j, freq_data in enumerate(vp_data.by_field('grating_freq')):
            if freq_data.vp[0] == 'n4' and freq_data.grating_freq[0] == .2:
                continue
            fit = fit_gaussian(freq_data, constrained=True)
            try:
                all_dips[j, i] = fit.best_values['center']
            except KeyError:
                pass
    all_dips = np.ma.MaskedArray(all_dips, np.isnan(all_dips))
    slope_low = (all_dips[1] / all_dips[0]).mean() / (grating_freqs[1] /
                                                      grating_freqs[0])
    slope_high = (all_dips[2] / all_dips[1]).mean() / (grating_freqs[2] /
                                                       grating_freqs[1])
    # bootstrap slopes
    slope_dist_low = np.full(10000, np.nan)
    slope_dist_high = np.full(10000, np.nan)
    for i in xrange(10000):
        ratio_low = (all_dips[1] / all_dips[0]).compressed()
        ratio_high = (all_dips[2] / all_dips[1]).compressed()
        slope_dist_low[i] = np.random.choice(ratio_low, len(ratio_low)).mean()
        slope_dist_high[i] = np.random.choice(ratio_high,
                                              len(ratio_high)).mean()
    slope_dist_low /= (grating_freqs[1] / grating_freqs[0])
    slope_dist_high /= (grating_freqs[2] / grating_freqs[1])

    # compute slope for models
    model_dips = np.full((2, 2), np.nan)
    biwam = evaluate_models.get_model_data('biwam')
    flodog = evaluate_models.get_model_data('flodog')
    for i, model_data in enumerate([biwam, flodog]):
        model_data = model_data[model_data.grating_freq != .2]
        for j, freq_data in enumerate(model_data.by_field('grating_freq')):
            fit = evaluate_models.fit_gaussian(freq_data, constrained=True)
            try:
                model_dips[j, i] = fit.best_values['center']
            except KeyError:
                pass
    slope_biwam = model_dips[1, 0] / model_dips[0, 0] / (grating_freqs[2] /
                                                         grating_freqs[1])
    slope_flodog = model_dips[1, 1] / model_dips[0, 1] / (grating_freqs[2] /
                                                          grating_freqs[1])

    return (slope_low, slope_high, slope_dist_low, slope_dist_high,
            slope_biwam, slope_flodog)
def grating_freq_vs_dip_freq(data):
    """Plot the most effective noise frequency against grating frequency"""
    #colors = ['#deebf7', '#c6dbef', '#9ecae1', '#6baed6', '#4292c6', '#2171b5',
    #            '#08519c', '#08306b']
    colors = ['#9ecae1'] * 8
    model_colors = ['#e41a1c', '#4daf4a']
    data = data[data.noise_type=='global']
    fig, ax = plt.subplots(figsize=(3,3))
    all_dips = np.full((3, 8), np.nan)
    for i, vp_data in enumerate(data.by_field('vp')):
        grating_freqs = [grating_frequencies[gf] for gf in
                            np.unique(vp_data.grating_freq)]
        grating_freqs.sort()
        dip_frequencies = np.full(len(np.unique(vp_data.grating_freq)), np.nan)
        for j, freq_data in enumerate(vp_data.by_field('grating_freq')):
            fit = fit_gaussian(freq_data, constrained=True)
            try:
                dip_frequencies[j] = fit.best_values['center']
                all_dips[j, i] = fit.best_values['center']
            except KeyError:
                pass
        ax.plot(grating_freqs, dip_frequencies, marker='o', ms=3, ls='-',
                lw=1, color=colors[i], mec='none', clip_on=False, zorder=100)
    ax.plot(grating_freqs, np.nanmean(all_dips, 1), marker='o', ms=6, ls='-',
            lw=2, color='#08519c', mec='none', clip_on=False, zorder=101)
    ax.text(1, np.nanmean(all_dips[2,:]), 'observers',
            fontname='Helvetica', fontsize=12, color='#08519c')
    # include model results
    biwam = evaluate_models.get_model_data('biwam')
    flodog = evaluate_models.get_model_data('flodog')
    for i, model_data in enumerate([biwam, flodog]):
        model_data = model_data[model_data.grating_freq!=.2]
        grating_freqs = [grating_frequencies[gf] for gf in
                            np.unique(model_data.grating_freq)]
        grating_freqs.sort()
        dip_frequencies = np.full(len(np.unique(model_data.grating_freq)), np.nan)
        for j, freq_data in enumerate(model_data.by_field('grating_freq')):
            fit = evaluate_models.fit_gaussian(freq_data, constrained=True)
            try:
                dip_frequencies[j] = fit.best_values['center']
            except KeyError:
                pass
        ax.plot(grating_freqs, dip_frequencies, marker='o', ms=6, ls='-',
                lw=2, color=model_colors[i], mec='none', clip_on=False, zorder=100)
        ax.text(1, dip_frequencies[1], ['BIWAM', 'FLODOG'][i],
                fontname='Helvetica', fontsize=12, color=model_colors[i])

    # plot diagonal lines with constant spacing
    for x in (.1 * 2 ** np.arange(0, 7)):
        ax.plot((x, x * 100), (.1, 10.1), ls="-", c=".7", lw=.5)
        ax.plot((.1, 10.1), (x, x * 100), ls="-", c=".7", lw=.5)
    ax.set_ylim((.1, 10))
    ax.set_xlim((.1, 10))
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['left'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['bottom'].set_position(('outward', 5))
    ax.spines['left'].set_position(('outward', 5))
    ax.get_xaxis().tick_bottom()
    ax.get_yaxis().tick_left()
    ax.set_xscale('log')
    ax.set_xticklabels(['', '.1', '1', '10'], fontname='Helvetica')
    ax.tick_params(axis='both', which='major', labelsize=10)
    ax.set_yscale('log')
    ax.set_yticklabels(['', '.1', '1', '10'], fontname='Helvetica')
    ax.set_ylabel(r'Noise mask center SF ($cpd$)', fontname='Helvetica',
            fontsize=12)
    ax.set_xlabel(r'Grating spatial frequency ($cpd$)', fontname='Helvetica',
            fontsize=12)
    fig.savefig('../figures/grating_freq_vs_dip_freq.pdf',
            bbox_inches='tight')
    plt.close(fig)
Пример #4
0
def grating_freq_vs_dip_freq(data):
    """Plot the most effective noise frequency against grating frequency"""
    #colors = ['#deebf7', '#c6dbef', '#9ecae1', '#6baed6', '#4292c6', '#2171b5',
    #            '#08519c', '#08306b']
    colors = ['#9ecae1'] * 8
    model_colors = ['#e41a1c', '#4daf4a']
    data = data[data.noise_type == 'global']
    fig, ax = plt.subplots(figsize=(3, 3))
    all_dips = np.full((3, 8), np.nan)
    for i, vp_data in enumerate(data.by_field('vp')):
        grating_freqs = [
            grating_frequencies[gf] for gf in np.unique(vp_data.grating_freq)
        ]
        grating_freqs.sort()
        dip_frequencies = np.full(len(np.unique(vp_data.grating_freq)), np.nan)
        for j, freq_data in enumerate(vp_data.by_field('grating_freq')):
            fit = fit_gaussian(freq_data, constrained=True)
            try:
                dip_frequencies[j] = fit.best_values['center']
                all_dips[j, i] = fit.best_values['center']
            except KeyError:
                pass
        ax.plot(grating_freqs,
                dip_frequencies,
                marker='o',
                ms=3,
                ls='-',
                lw=1,
                color=colors[i],
                mec='none',
                clip_on=False,
                zorder=100)
    ax.plot(grating_freqs,
            np.nanmean(all_dips, 1),
            marker='o',
            ms=6,
            ls='-',
            lw=2,
            color='#08519c',
            mec='none',
            clip_on=False,
            zorder=101)
    ax.text(1,
            np.nanmean(all_dips[2, :]),
            'observers',
            fontname='Helvetica',
            fontsize=12,
            color='#08519c')
    # include model results
    biwam = evaluate_models.get_model_data('biwam')
    flodog = evaluate_models.get_model_data('flodog')
    for i, model_data in enumerate([biwam, flodog]):
        model_data = model_data[model_data.grating_freq != .2]
        grating_freqs = [
            grating_frequencies[gf]
            for gf in np.unique(model_data.grating_freq)
        ]
        grating_freqs.sort()
        dip_frequencies = np.full(len(np.unique(model_data.grating_freq)),
                                  np.nan)
        for j, freq_data in enumerate(model_data.by_field('grating_freq')):
            fit = evaluate_models.fit_gaussian(freq_data, constrained=True)
            try:
                dip_frequencies[j] = fit.best_values['center']
            except KeyError:
                pass
        ax.plot(grating_freqs,
                dip_frequencies,
                marker='o',
                ms=6,
                ls='-',
                lw=2,
                color=model_colors[i],
                mec='none',
                clip_on=False,
                zorder=100)
        ax.text(1,
                dip_frequencies[1], ['BIWAM', 'FLODOG'][i],
                fontname='Helvetica',
                fontsize=12,
                color=model_colors[i])

    # plot diagonal lines with constant spacing
    for x in (.1 * 2**np.arange(0, 7)):
        ax.plot((x, x * 100), (.1, 10.1), ls="-", c=".7", lw=.5)
        ax.plot((.1, 10.1), (x, x * 100), ls="-", c=".7", lw=.5)
    ax.set_ylim((.1, 10))
    ax.set_xlim((.1, 10))
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['left'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['bottom'].set_position(('outward', 5))
    ax.spines['left'].set_position(('outward', 5))
    ax.get_xaxis().tick_bottom()
    ax.get_yaxis().tick_left()
    ax.set_xscale('log')
    ax.set_xticklabels(['', '.1', '1', '10'], fontname='Helvetica')
    ax.tick_params(axis='both', which='major', labelsize=10)
    ax.set_yscale('log')
    ax.set_yticklabels(['', '.1', '1', '10'], fontname='Helvetica')
    ax.set_ylabel(r'Noise mask center SF ($cpd$)',
                  fontname='Helvetica',
                  fontsize=12)
    ax.set_xlabel(r'Grating spatial frequency ($cpd$)',
                  fontname='Helvetica',
                  fontsize=12)
    fig.savefig('../figures/grating_freq_vs_dip_freq.pdf', bbox_inches='tight')
    plt.close(fig)