예제 #1
0
def plot_results_of_watson_test(df_all_animals, cell_type='grid', animal='mouse', xlim=False):
    if xlim is True:
        tag = 'zoomed'
    else:
        tag = ''
    good_cluster = df_all_animals.false_positive == False
    if cell_type == 'grid':
        grid = df_all_animals.grid_score >= 0.4
        not_hd = df_all_animals.hd_score < 0.5
        cells_to_analyze = grid & not_hd
    elif cell_type == 'hd':
        not_grid = df_all_animals.grid_score < 0.4
        hd = df_all_animals.hd_score >= 0.5
        cells_to_analyze = not_grid & hd
    else:
        not_grid = df_all_animals.grid_score < 0.4
        not_hd = df_all_animals.hd_score < 0.5
        cells_to_analyze = not_grid & not_hd

    watson_test_stats = df_all_animals.watson_test_hd[good_cluster & cells_to_analyze]
    watson_test_stats = watson_test_stats[~np.isnan(watson_test_stats)]

    print('\n' + animal)
    print(cell_type)
    print('all cells: ' + str(len(watson_test_stats)))
    print('significant: ' + str(len(watson_test_stats > 0.268)))

    fig, ax = plt.subplots()
    if xlim == True:
        plt.xlim(0, 1)
    plt.hist(watson_test_stats, bins=30, color='navy', normed=True, alpha=0.7)
    ax.xaxis.set_tick_params(labelsize=20)
    ax.yaxis.set_tick_params(labelsize=20)
    plt.axvline(x=0.268, linewidth=3, color='red')  # p < 0.01 based on r docs for watson two test
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.set_xlabel('Watson $U^2$', size=30)
    ax.set_ylabel('Proportion', size=30)
    plt.savefig(save_output_path + animal + '_two_sample_watson_stats_hist_all_spikes_' + cell_type + '_cells_' + tag + '.png', bbox_inches="tight")

    plt.close()
    fig, ax = plt.subplots()
    ax = plot_utility.format_bar_chart(ax, 'Watson $U^2$', 'Cumulative probability')
    plt.xscale('log')
    plt.yticks([0, 1])
    plt.xlim(0.1, 100)
    plt.axvline(x=0.268, linewidth=3, color='red')  # p < 0.01 based on r docs for watson two test
    values, base = np.histogram(watson_test_stats, bins=40)
    # evaluate the cumulative
    cumulative = np.cumsum(values / len(watson_test_stats))
    # plot the cumulative function
    plt.plot(base[:-1], cumulative, c='navy', linewidth=5)
    plt.savefig(save_output_path + animal + '_two_sample_watson_stats_hist_all_spikes_' + cell_type + '_cells_cumulative' + tag + '.png', bbox_inches="tight")
    plt.close()
예제 #2
0
def plot_speed_dependence(spatial_firing, animal, tag, color='navy'):
    # plt.hist(spatial_firing.speed_score, alpha=0.5, normed=True, color='gray')
    plt.cla()
    fig, ax = plt.subplots()
    ax = plot_utility.format_bar_chart(ax, 'Speed score',
                                       'Number of ' + tag + ' cells')
    plt.hist(spatial_firing.speed_score, alpha=0.8, color=color)
    plt.xlim(-1, 1)
    plt.savefig(save_output_path + animal + '_' + tag +
                '_cell_speed_scores.png')
    plt.close()
예제 #3
0
def plot_speed_vs_firing_rate_grid(position: pd.DataFrame,
                                   spatial_firing: pd.DataFrame,
                                   sampling_rate_conversion: int,
                                   video_sampling_rate: int,
                                   save_path: str) -> None:
    sigma = 250 / video_sampling_rate
    speed = scipy.ndimage.filters.gaussian_filter(position.speed, sigma)
    spatial_firing = OverallAnalysis.analyze_speed.add_cell_types_to_data_frame(
        spatial_firing)
    for index, cell in spatial_firing.iterrows():
        if cell['cell type'] == 'grid':
            firing_times = cell.firing_times
            firing_hist, edges = np.histogram(
                firing_times,
                bins=len(speed),
                range=(0,
                       max(position.synced_time) * sampling_rate_conversion))
            firing_hist *= video_sampling_rate
            smooth_hist = scipy.ndimage.filters.gaussian_filter(
                firing_hist.astype(float), sigma)
            speed, smooth_hist = array_utility.remove_nans_from_both_arrays(
                speed, smooth_hist)
            median_x, median_y, percentile_25, percentile_75 = calculate_median_for_scatter_binned(
                speed, smooth_hist)
            plt.cla()
            fig, ax = plt.subplots()
            ax = plot_utility.format_bar_chart(ax, 'Speed (cm/s)',
                                               'Firing rate (Hz)')
            plt.scatter(speed[::10],
                        smooth_hist[::10],
                        color='gray',
                        alpha=0.7)
            plt.plot(median_x, percentile_25, color='black', linewidth=5)
            plt.plot(median_x, percentile_75, color='black', linewidth=5)
            plt.scatter(median_x, median_y, color='black', s=100)
            plt.title('speed score: ' + str(np.round(cell.speed_score, 4)))
            plt.xlim(0, 50)
            plt.ylim(0, None)
            plt.savefig(save_path + cell.session_id + str(cell.cluster_id) +
                        '_speed.png')
            plt.close()
예제 #4
0
def plot_speed_vs_firing_rate(position: pd.DataFrame,
                              spatial_firing: pd.DataFrame,
                              sampling_rate_conversion: int, gauss_sd: float,
                              prm: object) -> None:
    sampling_rate_video = int(1 / position['synced_time'].diff().mean())
    sigma = gauss_sd / sampling_rate_video

    speed = scipy.ndimage.filters.gaussian_filter(position.speed, sigma)
    save_path = prm.get_output_path() + '/Figures/firing_properties'
    for index, cell in spatial_firing.iterrows():
        firing_times = cell.firing_times
        firing_hist, edges = np.histogram(firing_times,
                                          bins=len(speed),
                                          range=(0, max(position.synced_time) *
                                                 sampling_rate_conversion))
        firing_hist *= sampling_rate_video
        smooth_hist = scipy.ndimage.filters.gaussian_filter(
            firing_hist.astype(float), sigma)
        speed, smooth_hist = array_utility.remove_nans_from_both_arrays(
            speed, smooth_hist)
        median_x, median_y, percentile_25, percentile_75 = calculate_median_for_scatter_binned(
            speed, smooth_hist)
        plt.cla()
        fig, ax = plt.subplots()
        ax = plot_utility.format_bar_chart(ax, 'Speed (cm/s)',
                                           'Firing rate (Hz)')
        plt.scatter(speed[::10], smooth_hist[::10], color='gray', alpha=0.7)
        plt.plot(median_x, percentile_25, color='black', linewidth=5)
        plt.plot(median_x, percentile_75, color='black', linewidth=5)
        plt.scatter(median_x, median_y, color='black', s=100)
        plt.title('Speed score: ' + str(np.round(cell.speed_score, 4)),
                  fontsize=24)
        plt.xlim(0, 50)
        plt.ylim(0, None)
        plt.savefig(save_path + '/' + cell.session_id + '_' +
                    str(cell.cluster_id) + '_speed_vs_firing_rate.png',
                    dpi=300,
                    bbox_inches='tight',
                    pad_inches=0)
        plt.close()
예제 #5
0
def make_combined_plot_of_distributions(shuffled_field_data,
                                        tag='grid',
                                        shuffle_type='occupancy'):
    tail, percentile_95, percentile_99 = find_tail_of_shuffled_distribution_of_rejects(
        shuffled_field_data)

    number_of_rejects_shuffled = shuffled_field_data.number_of_different_bins_shuffled
    flat_shuffled = []
    for field in number_of_rejects_shuffled:
        flat_shuffled.extend(field)
    fig, ax = plt.subplots()
    plt.hist(flat_shuffled, normed=True, color='black', alpha=0.5)

    number_of_rejects_real = shuffled_field_data.number_of_different_bins
    plt.hist(number_of_rejects_real, normed=True, color='navy', alpha=0.5)

    # plt.axvline(x=tail, color='red', alpha=0.5, linestyle='dashed')
    # plt.axvline(x=percentile_95, color='red', alpha=0.5, linestyle='dashed')
    # plt.axvline(x=percentile_99, color='red', alpha=0.5, linestyle='dashed')

    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.xaxis.set_tick_params(labelsize=20)
    ax.yaxis.set_tick_params(labelsize=20)
    ax.set_xlabel('Rejected bars / field', size=30)
    ax.set_ylabel('Proportion', size=30)
    ax.set_xlim(0, 20)
    plt.savefig(analysis_path + 'distribution_of_rejects_combined_all_' +
                shuffle_type + tag + '.png',
                bbox_inches="tight")
    plt.close()

    fig, ax = plt.subplots()
    plt.yticks([0, 1])
    plt.ylim(0, 1.01)
    ax = plot_utility.format_bar_chart(ax, 'Pearson correlation coef.',
                                       'Cumulative probability')
    ax.set_xlim(0, 20)
    values, base = np.histogram(flat_shuffled, bins=40)
    # evaluate the cumulative
    cumulative = np.cumsum(values / len(flat_shuffled))
    # plot the cumulative function
    plt.plot(base[:-1], cumulative, c='gray', linewidth=5)

    values, base = np.histogram(number_of_rejects_real, bins=40)
    # evaluate the cumulative
    cumulative = np.cumsum(values / len(number_of_rejects_real))
    # plot the cumulative function
    plt.plot(base[:-1], cumulative, c='navy', linewidth=5)

    # plt.axvline(x=tail, color='red', alpha=0.5, linestyle='dashed')
    # plt.axvline(x=percentile_95, color='red', alpha=0.5, linestyle='dashed')
    # plt.axvline(x=percentile_99, color='red', alpha=0.5, linestyle='dashed')

    ax.set_xlabel('Rejected bars / field', size=30)
    ax.set_ylabel('Cumulative probability', size=30)
    plt.savefig(analysis_path + 'distribution_of_rejects_combined_all_' +
                shuffle_type + tag + '_cumulative.png',
                bbox_inches="tight")
    plt.close()