コード例 #1
0
def plot_interim_tsne_results_with_labels(folder_path):
    # Import labels
    pkl_file = open(label_path, 'rb')
    labels = pickle.load(pkl_file)
    pkl_file.close()
    juxta = labels.loc['Juxta']
    juxta_indices = juxta['Spike_Indices']
    juxta_indices = juxta_indices[juxta_indices < len(spike_indices)]
    num_labels = len(labels)
    label_indices = labels['Spike_Indices']
    color_indices = plt.Normalize(0, num_labels)
    cm = plt.cm.gist_ncar

    os.chdir(folder_path)
    #os.mkdir(folder_path + '\interim_frames')
    plt.figure('Summary',  figsize=(12, 8), dpi=120, facecolor='w', edgecolor='k')
    interim_dat_files = glob.glob("interim*.dat")
    for c in range(1,len(interim_dat_files), 1):
        file = interim_dat_files[c]
        print(file)
        tsne_data = TSNE.load_tsne_result(folder_path, file)
        tsne_data = np.transpose(tsne_data)
        plt.cla()
        plt.plot(tsne_data[0, :], tsne_data[1, :], '.', MarkerSize = 2, Color = [0.0, 0.0, 0.0, 0.15])
        #plt.plot(tsne_data[0, juxta_indices], tsne_data[1, juxta_indices], '.', MarkerSize = 2, Color = [1.0, 0.0, 0.0, 0.3])
        for g in range(0, num_labels):
            l_idx = label_indices[g]
            l_idx = l_idx[l_idx < len(spike_indices)]
            plt.plot(tsne_data[0][l_idx], tsne_data[1][l_idx], '.', MarkerSize=2, Color=cm(color_indices(g)), Alpha=0.25)

        minX = np.min(tsne_data[0, :])
        maxX = np.max(tsne_data[0, :])
        minY = np.min(tsne_data[1, :])
        maxY = np.max(tsne_data[1, :])
        rangeX = np.max(np.abs([minX, maxX]))
        rangeY = np.max(np.abs([minY, maxY]))
        #print(rangeX)
        plt.ylim([-rangeY, rangeY])
        plt.xlim([-rangeX, rangeX])
        plt.savefig(folder_path + '/interim_frames'+'/'+ file[:-4] +'.png')
コード例 #2
0
def plot_interim_tsne_results(folder_path):
    os.chdir(folder_path)
    #os.mkdir(folder_path + '\interim_frames')
    plt.figure('Summary',  figsize=(12, 8), dpi=120, facecolor='w', edgecolor='k')
    count = 1
    for file in glob.glob("interim*.dat"):
        print(file)
        tsne_data = TSNE.load_tsne_result(folder_path, file)
        tsne_data = np.transpose(tsne_data)
        plt.cla()
        plt.plot(tsne_data[0, :], tsne_data[1, :], '.', MarkerSize = 2, Color = [0.0, 0.0, 0.0, 0.25])
        minX = np.min(tsne_data[0, :])
        maxX = np.max(tsne_data[0, :])
        minY = np.min(tsne_data[1, :])
        maxY = np.max(tsne_data[1, :])
        rangeX = np.max(np.abs([minX, maxX]))
        rangeY = np.max(np.abs([minY, maxY]))
        #print(rangeX)
        plt.ylim([-rangeY, rangeY])
        plt.xlim([-rangeX, rangeX])
        plt.savefig(folder_path + '/interim_frames'+'/'+ file[:-4] +'.png')
        count = count + 1
コード例 #3
0
filename = r'D:\Data\George\Projects\SpikeSorting\Joana_Paired_128ch\2015-09-03\Analysis\klustakwik\threshold_6_5std\threshold_6_5std.kwik'
h5file = h5.File(filename, mode='r')
spike_times_phy = np.array(list(h5file['channel_groups/0/spikes/time_samples']))
h5file.close()


kilosort_experiment_folder = r'thres4_10_10_Fe16_Pc12'  # thres4_10_10_Fe16_Pc12 OR thres4_10_10_Fe256_Pc128 OR thres6_12_12_Fe256_Pc128
kilosort_path = os.path.join(r'D:\Data\George\Projects\SpikeSorting\Joana_Paired_128ch\2015-09-03\Analysis\kilosort',
                             kilosort_experiment_folder)
spike_clusters_kilosort = np.load(os.path.join(kilosort_path, 'kilosort output\\spike_templates.npy'))
spike_times_kilosort = np.load(os.path.join(kilosort_path, 'kilosort output\spike_times.npy'))
template_features = np.load(os.path.join(kilosort_path, 'kilosort output\\template_features.npy'))
template_features_ind = np.load(os.path.join(kilosort_path, 'kilosort output\\template_feature_ind.npy'))

template_features_tsne = TSNE.load_tsne_result(os.path.join(kilosort_path, 'tsne'),
                                               'tsne_template_features_466313sp_100per_2000its_02theta.dat')
pc_features_tsne = TSNE.load_tsne_result(os.path.join(kilosort_path, r'tsne\pc_features_results'),
                                         'tsne_pc_features_466ksp_per100_theta02_it2k_rs1.dat')


spikes_used = np.arange(len(template_features_tsne))#np.arange(150000) #np.random.choice(np.arange(len(template_features_tsne)), 150000) #np.arange(len(template_features_tsne))
template_features_tsne = np.transpose(np.array(template_features_tsne)[spikes_used])

pc_features_tsne = np.transpose(np.array(pc_features_tsne)[spikes_used])

spike_clusters_kilosort = spike_clusters_kilosort[spikes_used]
spike_times_kilosort = spike_times_kilosort[spikes_used]

cluster_info_filename = os.path.join(kilosort_path, 'tsne\\cluster_info_full_final.pkl')
#cluster_info = tsne_cluster.create_cluster_info_from_kilosort_spike_templates(cluster_info_filename,
#                                                                              spike_clusters_kilosort)