def plot_coverage(position_heat_map, prm):
    print('I will plot a heat map of the position of the animal to show coverage.')
    save_path = prm.get_output_path() + '/Figures/session'
    if os.path.exists(save_path) is False:
        os.makedirs(save_path)
    coverage = plt.figure()
    coverage.set_size_inches(5, 5, forward=True)
    ax = coverage.add_subplot(1, 1, 1)  # specify (nrows, ncols, axnum)
    ax = plot_utility.style_open_field_plot(ax)
    ax.imshow(position_heat_map, cmap=cmocean.cm.thermal, interpolation='nearest')
    plt.title('coverage', y=1.08)
    plt.savefig(save_path + '/heatmap.png', dpi=300)
    plt.savefig(save_path + '/heatmap.pdf')
    plt.close()
def plot_firing_rate_maps(spatial_firing, prm):
    print('I will make rate map plots.')
    save_path = prm.get_output_path() + '/Figures/rate_maps'
    if os.path.exists(save_path) is False:
        os.makedirs(save_path)
    for cluster in range(len(spatial_firing)):
        cluster = spatial_firing.cluster_id.values[cluster] - 1
        firing_rate_map_original = spatial_firing.firing_maps[cluster]
        firing_rate_map = np.rot90(firing_rate_map_original)
        firing_rate_map_fig = plt.figure()
        firing_rate_map_fig.set_size_inches(5, 5, forward=True)
        ax = firing_rate_map_fig.add_subplot(1, 1, 1)  # specify (nrows, ncols, axnum)
        ax = plot_utility.style_open_field_plot(ax)
        ax.imshow(firing_rate_map, cmap='jet', interpolation='nearest')
        plt.title('max fr: ' + str(round(spatial_firing.max_firing_rate[cluster], 2)) + ' Hz', y=1.08)
        plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] + '_rate_map_' + str(cluster + 1) + '.png', dpi=300)
        # plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] + '_rate_map_' + str(cluster + 1) + '.pdf')
        plt.close()
def plot_rate_map_autocorrelogram(spatial_firing, prm):
    print('I will make the rate map autocorrelogram grid plots now.')
    save_path = prm.get_output_path() + '/Figures/rate_map_autocorrelogram'
    if os.path.exists(save_path) is False:
        os.makedirs(save_path)
    for cluster in range(len(spatial_firing)):
        cluster = spatial_firing.cluster_id.values[cluster] - 1
        rate_map_autocorr_fig = plt.figure()
        rate_map_autocorr_fig.set_size_inches(5, 5, forward=True)
        ax = rate_map_autocorr_fig.add_subplot(1, 1, 1)  # specify (nrows, ncols, axnum)
        rate_map_autocorr = spatial_firing.rate_map_autocorrelogram[cluster]
        if rate_map_autocorr.size:
            ax = plt.subplot(1, 1, 1)
            ax = plot_utility.style_open_field_plot(ax)
            ax.imshow(rate_map_autocorr, cmap='jet', interpolation='nearest')
            plt.tight_layout()
            plt.title('grid score: ' + str(round(spatial_firing.grid_score[cluster], 2)))
            plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] + '_rate_map_autocorrelogram_' + str(cluster + 1) + '.png', dpi=300, bbox_inches="tight")
            # plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] + '_rate_map_autocorrelogram_' + str(cluster + 1) + '.pdf', bbox_inches="tight")
        plt.close()
Exemplo n.º 4
0
def plot_hd(spatial_firing, position_data, prm):
    print('I will plot HD on open field maps as a scatter plot for each cluster.')
    save_path = prm.get_output_path() + '/Figures/head_direction_plots_2d'
    if os.path.exists(save_path) is False:
        os.makedirs(save_path)
    for cluster in range(len(spatial_firing)):
        cluster = spatial_firing.cluster_id.values[cluster] - 1
        x_positions = spatial_firing.position_x[cluster]
        y_positions = spatial_firing.position_y[cluster]
        hd = spatial_firing.hd[cluster]
        hd_map_fig = plt.figure()
        hd_map_fig.set_size_inches(5, 5, forward=True)
        ax = hd_map_fig.add_subplot(1, 1, 1)  # specify (nrows, ncols, axnum)
        ax = plot_utility.style_open_field_plot(ax)
        ax.plot(position_data['position_x'], position_data['position_y'], color='black', linewidth=2, zorder=1,
                alpha=0.2)
        hd_plot = ax.scatter(x_positions, y_positions, s=20, c=hd, vmin=-180, vmax=180, marker='o', cmap=cmocean.cm.phase)
        plt.colorbar(hd_plot, fraction=0.046, pad=0.04)
        plt.title('Head direction at spikes', y=1.08, fontsize=24)
        plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] + '_hd_map_' + str(cluster + 1) + '.png', dpi=300, bbox_inches='tight', pad_inches=0)
        # plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] + '_hd_map_' + str(cluster + 1) + '.pdf', bbox_inches='tight', pad_inches=0)
        plt.close()
def plot_rate_map_comparison(grid_data, rate_map_1, rate_map_2, iterator,
                             path):
    # corr = scipy.signal.correlate2d(rate_map_2, rate_map_2)
    corr = PostSorting.open_field_grid_cells.get_rate_map_autocorrelogram(
        rate_map_2)
    firing_rate_map_fig = plt.figure()
    firing_rate_map_fig.set_size_inches(5, 5, forward=True)
    ax = firing_rate_map_fig.add_subplot(1, 1,
                                         1)  # specify (nrows, ncols, axnum)
    ax = plot_utility.style_open_field_plot(ax)
    rate_map_img = ax.imshow(corr, cmap='jet', interpolation='nearest')
    # firing_rate_map_fig.colorbar(rate_map_img)
    ax.axvline(x=(corr.shape[1]) / 2, color='black', linewidth=4)
    ax.axhline(y=(corr.shape[0]) / 2, color='black', linewidth=4)
    plt.savefig(path + grid_data.iloc[iterator].session_id +
                str(grid_data.iloc[iterator].session_id) + 'auto_corr2.png')

    plt.cla()

    corr = PostSorting.open_field_grid_cells.get_rate_map_autocorrelogram(
        rate_map_1)
    firing_rate_map_fig = plt.figure()
    firing_rate_map_fig.set_size_inches(5, 5, forward=True)
    ax = firing_rate_map_fig.add_subplot(1, 1,
                                         1)  # specify (nrows, ncols, axnum)
    ax = plot_utility.style_open_field_plot(ax)
    rate_map_img = ax.imshow(corr, cmap='jet', interpolation='nearest')
    # firing_rate_map_fig.colorbar(rate_map_img)
    ax.axvline(x=(corr.shape[1]) / 2, color='black', linewidth=4)
    ax.axhline(y=(corr.shape[0]) / 2, color='black', linewidth=4)
    plt.savefig(path + grid_data.iloc[iterator].session_id +
                str(grid_data.iloc[iterator].session_id) + 'auto_corr1.png')

    plt.cla()

    corr = PostSorting.open_field_grid_cells.get_rate_map_crosscorrelogram(
        rate_map_1, rate_map_2)
    firing_rate_map_fig = plt.figure()
    firing_rate_map_fig.set_size_inches(5, 5, forward=True)
    ax = firing_rate_map_fig.add_subplot(1, 1,
                                         1)  # specify (nrows, ncols, axnum)
    ax = plot_utility.style_open_field_plot(ax)
    rate_map_img = ax.imshow(corr, cmap='jet', interpolation='nearest')
    # firing_rate_map_fig.colorbar(rate_map_img)
    ax.axvline(x=(corr.shape[1]) / 2, color='black', linewidth=4)
    ax.axhline(y=(corr.shape[0]) / 2, color='black', linewidth=4)
    plt.savefig(path + grid_data.iloc[iterator].session_id +
                str(grid_data.iloc[iterator].session_id) + 'cross_corr.png')

    plt.cla()
    firing_rate_map_fig = plt.figure()
    firing_rate_map_fig.set_size_inches(5, 5, forward=True)
    ax = firing_rate_map_fig.add_subplot(1, 1,
                                         1)  # specify (nrows, ncols, axnum)
    ax = plot_utility.style_open_field_plot(ax)
    rate_map_img = ax.imshow(rate_map_2 - rate_map_1,
                             cmap='jet',
                             interpolation='nearest')
    firing_rate_map_fig.colorbar(rate_map_img)
    plt.savefig(path + grid_data.iloc[iterator].session_id +
                str(grid_data.iloc[iterator].session_id) + 'subtract.png')
    plt.cla()

    plt.cla()
    firing_rate_map_fig = plt.figure()
    firing_rate_map_fig.set_size_inches(5, 5, forward=True)
    ax = firing_rate_map_fig.add_subplot(1, 1,
                                         1)  # specify (nrows, ncols, axnum)
    ax = plot_utility.style_open_field_plot(ax)
    rate_map_img = ax.imshow(rate_map_1 - rate_map_2,
                             cmap='jet',
                             interpolation='nearest')
    firing_rate_map_fig.colorbar(rate_map_img)
    plt.savefig(path + grid_data.iloc[iterator].session_id +
                str(grid_data.iloc[iterator].session_id) + 'subtract2.png')
    plt.cla()