def plot_spikes_for_channel_centered(grid, spike_data, cluster, channel,
                                     snippet_column_name):
    max_channel = spike_data.primary_channel[cluster]
    sd = np.std(spike_data.random_snippets[cluster][max_channel - 1, :, :] *
                -1)
    highest_value = np.median(
        spike_data.random_snippets[cluster][max_channel - 1, :, :] *
        -1) + (sd * 4)
    lowest_value = np.median(
        spike_data.random_snippets[cluster][max_channel - 1, :, :] *
        -1) - (sd * 4)
    snippet_plot = plt.subplot(grid[int(channel / 2), channel % 2])
    plt.ylim(lowest_value - 10, highest_value + 30)
    plot_utility.style_plot(snippet_plot)
    snippet_plot.plot(spike_data[snippet_column_name][cluster][channel, :, :] *
                      -1,
                      color='lightslategray')
    snippet_plot.plot(
        np.mean(spike_data[snippet_column_name][cluster][channel, :, :], 1) *
        -1,
        color='red')
    plt.xticks([0, 30], [0, 1])
    plt.xticks(fontsize=14)
    plt.yticks(fontsize=14)
    plt.xlabel('Time (ms)', fontsize=14)
    plt.ylabel('Voltage (µV)', fontsize=14)
Example #2
0
def plot_interesting_cells(cluster_id, spike_index, save_output_path):
    cluster5 = np.where(cluster_id == 5)
    cluster5_firings = np.take(spike_index, cluster5[0])
    cluster6 = np.where(cluster_id == 6)
    cluster6_firings = np.take(spike_index, cluster6[0])

    c5 = np.array(cluster5_firings, dtype=int)
    c6 = np.array(cluster6_firings, dtype=int)

    spikes_fig_whole_recording = plt.figure()
    ax1 = spikes_fig_whole_recording.add_subplot(1, 1, 1)
    spikes_fig_whole_recording, ax1 = plot_utility.style_plot(ax1)
    ax1.get_yaxis().set_visible(False)
    ax1.spines['left'].set_visible(False)
    ax1.vlines(c5, 0.5, 0.95, color='navy')
    ax1.vlines(c6, 1, 1.45, color='black')
    plt.title('C5 and C6 from M5, 6th of March')
    plt.xlabel('sample points')
    plt.ylabel('cluster')
    plt.savefig(save_output_path + 'M5_conjunctive_vs_grid_cluster')

    spikes_small_section = plt.figure()
    ax2 = spikes_small_section.add_subplot(1, 1, 1)
    spikes_small_section, ax2 = plot_utility.style_plot(ax2)
    ax2.get_yaxis().set_visible(False)
    ax2.spines['left'].set_visible(False)
    ax2.vlines(c5, 0.5, 0.95, color='navy')
    ax2.vlines(c6, 1, 1.45, color='black')
    plt.title('C5 and C6 from M5, 6th of March')
    plt.xlabel('sample points')
    plt.ylabel('cluster')
    plt.xlim(3050000, 3150000)
    plt.savefig(save_output_path + 'M5_conjunctive_vs_grid_cluster_section')
def plot_spikes_for_channel(grid, highest_value, lowest_value, spike_data,
                            cluster, channel, snippet_column_name):
    snippet_plot = plt.subplot(grid[int(channel / 2), channel % 2])
    plt.ylim(lowest_value - 10, highest_value + 30)
    plot_utility.style_plot(snippet_plot)
    snippet_plot.plot(spike_data[snippet_column_name][cluster][channel, :, :] *
                      -1,
                      color='lightslategray')
    snippet_plot.plot(
        np.mean(spike_data[snippet_column_name][cluster][channel, :, :], 1) *
        -1,
        color='red')
    plt.xticks([0, 10, 30], [-10, 0, 20])
Example #4
0
def plot_firing_rate_vs_speed(spatial_firing, spatial_data, prm):
    sampling_rate = 30
    print(
        'I will plot spikes vs speed for the whole session excluding opto tagging.'
    )
    save_path = prm.get_output_path() + '/Figures/firing_properties'
    if os.path.exists(save_path) is False:
        os.makedirs(save_path)
    speed = spatial_data.speed[~np.isnan(spatial_data.speed)]
    number_of_bins = math.ceil(max(speed)) - math.floor(min(speed))
    session_hist, bins_s = np.histogram(speed,
                                        bins=number_of_bins,
                                        range=(math.floor(min(speed)),
                                               math.ceil(max(speed))))
    for cluster in range(len(spatial_firing)):
        cluster = spatial_firing.cluster_id.values[cluster] - 1
        speed_cluster = spatial_firing.speed[cluster]
        speed_cluster = sorted(speed_cluster)
        spike_hist = plt.figure()
        spike_hist.set_size_inches(5, 5, forward=True)
        ax = spike_hist.add_subplot(1, 1, 1)
        speed_hist, ax = plot_utility.style_plot(ax)
        if number_of_bins > 0:
            hist, bins = np.histogram(speed_cluster[1:],
                                      bins=number_of_bins,
                                      range=(math.floor(min(speed)),
                                             math.ceil(max(speed))))
            width = bins[1] - bins[0]
            center_bin = (bins[:-1] + bins[1:]) / 2
            center = center_bin[tuple(
                [np.where(session_hist > sum(session_hist) * 0.005)])]
            hist = np.array(hist, dtype=float)
            session_hist = np.array(session_hist, dtype=float)
            rate = np.divide(hist,
                             session_hist,
                             out=np.zeros_like(hist),
                             where=session_hist != 0)
            rate = rate[tuple([
                np.where(
                    session_hist[~np.isnan(session_hist)] > sum(session_hist) *
                    0.005)
            ])]
            plt.bar(center[0],
                    rate[0] * sampling_rate,
                    align='center',
                    width=width,
                    color='black')
        plt.xlabel('speed [cm/s]')
        plt.ylabel('firing rate [Hz]')
        plt.xlim(0, 30)
        plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] +
                    '_' + str(cluster + 1) + '_speed_histogram.png',
                    dpi=300,
                    bbox_inches='tight',
                    pad_inches=0)
        plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] +
                    '_' + str(cluster + 1) + '_speed_histogram.pdf',
                    bbox_inches='tight',
                    pad_inches=0)
        plt.close()
def plot_spike_histogram(spatial_firing, prm):
    sampling_rate = prm.get_sampling_rate()
    print(
        'I will plot spikes vs time for the whole session excluding opto tagging.'
    )
    save_path = prm.get_output_path() + '/Figures/firing_properties'
    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
        number_of_bins = int(
            (spatial_firing.firing_times[cluster][-1] -
             spatial_firing.firing_times[cluster][0]) / (5 * sampling_rate))
        firings_cluster = spatial_firing.firing_times[
            cluster] / sampling_rate / 60
        spike_hist = plt.figure()
        spike_hist.set_size_inches(5, 5, forward=True)
        ax = spike_hist.add_subplot(1, 1, 1)
        spike_hist, ax = plot_utility.style_plot(ax)
        if number_of_bins > 0:
            hist, bins = np.histogram(firings_cluster, bins=number_of_bins)
            width = bins[1] - bins[0]
            center = (bins[:-1] + bins[1:]) / 2
            plt.bar(center, hist, align='center', width=width, color='black')
        plt.title(
            'Spike histogram \n total spikes = ' +
            str(spatial_firing.number_of_spikes[cluster]) + ', \n mean fr = ' +
            str(round(spatial_firing.mean_firing_rate[cluster], 0)) + ' Hz',
            y=1.08,
            fontsize=24)
        plt.xlabel('Time (min)', fontsize=25)
        plt.ylabel('Number of spikes', fontsize=25)
        plt.xticks(fontsize=20)
        plt.yticks(fontsize=20)

        plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] +
                    '_' + str(cluster + 1) + '_spike_histogram.png',
                    dpi=300,
                    bbox_inches='tight',
                    pad_inches=0)
        # plt.savefig(save_path + '/' + spatial_firing.session_id[cluster] + '_' + str(cluster + 1) + '_spike_histogram.pdf', bbox_inches='tight', pad_inches=0)
        plt.close()
Example #6
0
def plot_correlation_coef_hist(correlation_coefs,
                               save_path,
                               y_axis_label='Number of fields'):
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)  # specify (nrows, ncols, axnum)
    fig, ax = plot_utility.style_plot(ax)
    ax.hist(correlation_coefs, color='navy')
    ax.xaxis.set_tick_params(labelsize=20)
    ax.yaxis.set_tick_params(labelsize=20)
    plt.xlabel('Correlation coefficient', fontsize=30)
    plt.ylabel(y_axis_label, fontsize=30)
    plt.xlim(-1, 1)
    plt.axvline(x=0, color='red', linewidth=5)
    plt.gcf().subplots_adjust(bottom=0.15)
    plt.savefig(save_path)
    plt.close()

    plt.cla()
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)  # specify (nrows, ncols, axnum)
    fig, ax = plot_utility.style_plot(ax)
    # ax.hist(correlation_coefs, color='navy')
    plot_utility.plot_cumulative_histogram(correlation_coefs, ax)
    ax.xaxis.set_tick_params(labelsize=20)
    ax.yaxis.set_tick_params(labelsize=20)
    plt.xlabel('Correlation coefficient', fontsize=25)
    plt.ylabel(y_axis_label, fontsize=25)
    plt.xlim(-1, 1)
    plt.axvline(x=0, color='red', linewidth=5)
    plt.gcf().subplots_adjust(bottom=0.15)
    plt.savefig(save_path + 'cumulative.png')
    plt.close()

    fields = pd.read_excel(path)
    print(fields.head())
    significant = (fields.p_value < 0.001)
    correlation_coefs = fields[significant]['correlation coef'].values
    save_path = path + 'correlation_coef_hist.png'
    plot_correlation_coef_hist(correlation_coefs, save_path)

    grid_cells = fields['cell type'] == 'grid'
    hd_cells = fields['cell type'] == 'hd'
    conjunctive_cells = fields['cell type'] == 'conjunctive'
    not_classified = fields['cell type'] == 'na'
    fields[grid_cells & significant]['correlation coef'].std()

    grid_coeffs = fields[grid_cells & significant]['correlation coef'].values
    save_path = path + 'correlation_coef_hist_grid.png'
    plot_correlation_coef_hist(grid_coeffs, save_path)

    grid_coeffs = fields[hd_cells & significant]['correlation coef'].values
    save_path = path + 'correlation_coef_hist_hd.png'
    plot_correlation_coef_hist(grid_coeffs, save_path)

    grid_coeffs = fields[not_classified
                         & significant]['correlation coef'].values
    save_path = path + 'correlation_coef_hist_nc.png'
    plot_correlation_coef_hist(grid_coeffs, save_path)

    grid_coeffs = fields[conjunctive_cells
                         & significant]['correlation coef'].values
    save_path = path + 'correlation_coef_hist_conj.png'
    plot_correlation_coef_hist(grid_coeffs, save_path)