amp_gain=amp_gain,
        num_of_raw_data_channels=None,
        spike_channels=None,
        verbose=True)
    pf.plot_tsne(tsne,
                 juxta_cluster_indices_grouped,
                 cm=plt.cm.brg,
                 label_name='Peak size in uV',
                 label_array=(spike_thresholds_groups * 1e6).astype(int),
                 subtitle='T-sne of ' + str(channel_number[code]) +
                 'channels, ' + str(geometry_descriptions[code]))

# ----------------------------------------------------------------------------------------------------------------------
# CLUSTERING AND SCORING

db, n_clusters, labels, core_samples_mask, score = taf.fit_dbscan(
    tsne, 0.019, 40, normalize=True, show=True)

pf.show_clustered_tsne(db,
                       tsne,
                       juxta_cluster_indices_grouped=None,
                       threshold_legend=None)

taf.calculate_precision_recall_for_single_label_grouped(
    tsne,
    juxta_cluster_indices_grouped,
    n_clusters,
    labels,
    core_samples_mask,
    show_means=False)

# ----------------------------------------------------------------------------------------------------------------------
                         exageration=exageration,
                         iterations=iterations,
                         random_seed=random_seed,
                         verbose=verbose)

# </editor-fold>
# -------------------------------------------------

# -------------------------------------------------
# <editor-fold desc="DBSCAN THE TSNE AND SAVE THE RESULTING LABELS">

tsne_result = tsne_io.load_tsne_result(tsne_folder)

X = tsne_result.transpose()

db, n_clusters_, labels, core_samples_mask, score = tsne_funcs.fit_dbscan(
    X, eps=0.015, min_samples=40, normalize=True, show=True)
pickle.dump(db, open(join(tsne_folder, 'dbscan_result.pcl'), 'wb'))
np.save(join(tsne_folder, 'dbscan_labels.npy'), db.labels_)
# </editor-fold>
# -------------------------------------------------

# -------------------------------------------------
# <editor-fold desc="SHOW THE FRAMES AND THE PCs ON THE CLUSTERED T-SNE">

tsne_result = tsne_io.load_tsne_result(tsne_folder)
db = pickle.load(open(join(tsne_folder, 'dbscan_result.pcl'), 'rb'))
grayscale_resized_video_array_frame_smoothed = np.load(
    join(subsumpled_video_folder,
         'grayscale_resized_cropped_video_array_frame_smoothed.npy'), )

f = plt.figure(3)
                                                                                    adc_dtype=adc_dtype,
                                                                                    inter_spike_time_distance=inter_spike_time_distance,
                                                                                    amp_gain=amp_gain,
                                                                                    num_of_raw_data_channels=None,
                                                                                    spike_channels=None,
                                                                                    verbose=True)
    pf.plot_tsne(tsne, juxta_cluster_indices_grouped, cm=plt.cm.brg,
             label_name='Peak size in uV',
             label_array=(spike_thresholds_groups*1e6).astype(int),
             subtitle='T-sne of '+str(channel_number[code])+'channels, '+str(geometry_descriptions[code]))


# ----------------------------------------------------------------------------------------------------------------------
# CLUSTERING AND SCORING

db, n_clusters, labels, core_samples_mask, score = taf.fit_dbscan(tsne, 0.019, 40, normalize=True, show=True)

pf.show_clustered_tsne(db, tsne, juxta_cluster_indices_grouped=None, threshold_legend=None)


taf.calculate_precision_recall_for_single_label_grouped(tsne, juxta_cluster_indices_grouped, n_clusters, labels,
                                                        core_samples_mask, show_means=False)

# ----------------------------------------------------------------------------------------------------------------------
# Comparing tsnes with the manual clustering of the 128 channels

base_dir = r'D:\Data\George\Projects\SpikeSorting\Joana_Paired_128ch\2015-09-03'
tsne_dir = r'Analysis\klustakwik\threshold_6_5std'
cluster_info_filename = join(base_dir, tsne_dir, 'cluster_info.pkl')
clusters = pd.read_pickle(cluster_info_filename)['Spike_Indices'].tolist()
예제 #4
0
           exe_dir=barnes_hut_exe_dir,
           num_dims=num_dims,
           perplexity=perplexity,
           theta=theta,
           iterations=iterations,
           random_seed=random_seed,
           verbose=verbose)
preproc_kilo.generate_spike_info_from_full_tsne(
    kilosort_folder=kilosort_folder, tsne_folder=template_folder)

spike_info = np.load(join(template_folder, 'spike_info.df'))
vis.plot_tsne_of_spikes(spike_info)

# DBSCAN
data = np.array([spike_info['tsne_x'], spike_info['tsne_y']])
db, n_clusters, labels, core_samples_mask, score = tsne_funcs.fit_dbscan(
    data, eps=0.025, min_samples=43, normalize=True, show=True)
spike_info_for_labels = spike_info.copy()
spike_info_for_labels[ct.TEMPLATE_AFTER_CLEANING] = labels
spike_info_for_labels[ct.TEMPLATE_AFTER_SORTING] = labels
#spike_info_for_labels.to_pickle(join(template_folder, 'spike_info_for_labels.df'))
spike_info_for_labels.to_pickle(join(template_folder, 'spike_info.df'))
vis.plot_tsne_of_spikes(spike_info_for_labels)
# -------------------------------------------------------------

# TSNE ALL LARGE MUA
number_of_spikes_in_large_mua_templates = 10000
large_mua_templates = preproc_kilo.find_large_mua_templates(
    kilosort_folder, number_of_spikes_in_large_mua_templates)

templates_of_spikes = np.load(join(kilosort_folder, 'spike_templates.npy'))
spike_times = np.squeeze(np.load(join(kilosort_folder, 'spike_times.npy')))
예제 #5
0
spike_rates_per_video_frame_filename = join(
    kilosort_folder, 'firing_rate_with_video_frame_window.npy')
spike_rates_per_video_frame = np.load(spike_rates_per_video_frame_filename)

dlc_folder = join(analysis_folder, 'Deeplabcut')
dlc_project_folder = join(dlc_folder, 'projects', 'V1--2019-06-30')
video_file = join(dlc_folder, 'BonsaiCroping', 'Full_video.avi')
body_positions = np.load(
    join(dlc_project_folder, 'post_processing', 'body_positions.npy'))
speeds = np.load(join(dlc_project_folder, 'post_processing', 'speeds.npy'))

patterned_vs_non_patterned_folder = join(analysis_folder, 'Behaviour',
                                         'PatternedVsNonPatterned')

results_folder = join(analysis_folder, 'Results')
poke_folder = join(results_folder, 'EventsCorrelations', 'Poke')
events_definitions_folder = join(results_folder, 'EventsDefinitions')

template_info = pd.read_pickle(join(kilosort_folder, 'template_info.df'))

tsne_folder = join(tsne_folder_base,
                   'All_spikes_100msbin_count_top40PCs_10Kiter')

tsne_result = tsne_io.load_tsne_result(tsne_folder).transpose()

# </editor-fold>
# -------------------------------------------------

db, n_clusters_, labels, core_samples_mask, score = tsne_funcs.fit_dbscan(
    tsne_result, eps=0.032, min_samples=150, normalize=False, show=True)