from emcat import KK
from default_parameters import default_parameters


script_params = default_parameters.copy()
#script_params.update(
#        run_monitoring_server=False,
#        debug=True,
#        )

picklefile = '/home/skadir/globalphy/nicktest/nick_global_80001_supercluster.p'
pkl_file = open(picklefile,'rb')
[time_taken_parallel, full_adjacency, channel_order_dict,globalcl_dict,supercluster_info,supercluster_results, superclusters] = pickle.load(pkl_file)
pkl_file.close()  

#superdata used to be called silly
superdata = sorting.sparsify_superclusters(superclusters)
outsil = superdata.to_sparse_data() #don't need to write the outsil variable, everything is stored within the sparse class
distdata = superdata.supercluster_distribution()
start_time = time.time()
[clust50, dic50] = superdata.clump_fine_clustering(50)
time_taken_clump = time.time()-start_time
print('Time taken for clump clustering %.2f s' %(time_taken_clump))
embed()
kk = KK(superdata,**script_params)
kk.cluster_from(clust50)

#Automatically create clust100 via
#kk.cluster_hammingmask_starts(100)
embed()
mixture = pickle.load(pkl_file)
pkl_file.close()  

#Get initial clustering for testing
initpicklefile = personal_homedir + 'global_superclustering/global_code/init_synthetic_cat_4.p'
initpkl_file = open(initpicklefile,'rb')
initclust = pickle.load(initpkl_file)
initpkl_file.close()  

#embed()
mixture_dict = mixture[0]
#num_starting_clusters = 15
#num_spikes = mixture_dict['superclusters'].shape[0]
#initclust = tc.generate_random_initial_clustering(num_starting_clusters, num_spikes )

#superdata used to be called silly
superdata = sorting.sparsify_superclusters(mixture_dict['superclusters'])
outsparse = superdata.to_sparse_data() #don't need to write the outsil variable, everything is stored within the sparse class
distdata = superdata.supercluster_distribution()
start_time = time.time()
[clust10, dic10] = superdata.clump_fine_clustering(10)
time_taken_clump = time.time()-start_time
print('Time taken for clump clustering %.2f s' %(time_taken_clump))

kk = KK(outsparse,**script_params)
#kk.cluster_from(clust10)
kk.cluster_from(initclust)
#Automatically create clust100 via
#kk.cluster_hammingmask_starts(100)
embed()
#        run_monitoring_server=False,
#        debug=True,
#        )

picklefile = '/home/skadir/globalphy/global_superclustering/global_code/synthetic_cat.p'
pkl_file = open(picklefile, 'rb')
mixture = pickle.load(pkl_file)
pkl_file.close()
#embed()
mixture_dict = mixture[0]
num_starting_clusters = 15
num_spikes = mixture_dict['superclusters'].shape[0]
initclust = tc.generate_random_initial_clustering(num_starting_clusters,
                                                  num_spikes)
#superdata used to be called silly
superdata = sorting.sparsify_superclusters(mixture_dict['superclusters'])
outsparse = superdata.to_sparse_data(
)  #don't need to write the outsil variable, everything is stored within the sparse class
distdata = superdata.supercluster_distribution()
start_time = time.time()
[clust10, dic10] = superdata.clump_fine_clustering(10)
time_taken_clump = time.time() - start_time
print('Time taken for clump clustering %.2f s' % (time_taken_clump))

kk = KK(outsparse, **script_params)
#kk.cluster_from(clust10)
kk.cluster_from(initclust)
#Automatically create clust100 via
#kk.cluster_hammingmask_starts(100)
embed()