def execute(self): # if no clusters to merge: do nothing if len(self.spikes_to_split) == 0: return clusters = self.dh.clusters.copy() # array with clusters to split clusters_to_split = np.unique(self._old_clusters[self.spikes_to_split]) clusters_to_split.sort() nclusters_to_split = len(clusters_to_split) # create nclusters_to_split new clusters nc = self.dh.new_cluster() new_clusters = np.arange(nc, nc + nclusters_to_split) # invalidate the cross correlograms of the clusters to merge self.sdh.invalidate(clusters_to_split) for cluster, new_cluster in zip(clusters_to_split, new_clusters): # spikes which are in the current cluster spikes_in_cluster = np.nonzero(self._old_clusters == cluster)[0] # the spikes in the current cluster to be split spikes_in_cluster_to_split = np.in1d(spikes_in_cluster, self.spikes_to_split) spikes_in_cluster_to_split = spikes_in_cluster[spikes_in_cluster_to_split] # assign the new cluster to the split spikes clusters[spikes_in_cluster_to_split] = new_cluster # record the list of newly created clusters self.new_clusters = new_clusters self.clusters_to_split = clusters_to_split # get clusters info clusters_info = get_clusters_info(clusters) nclusters = len(clusters_info) for clusteridx, info in clusters_info.iteritems(): # if the cluster has not been changed if clusteridx not in new_clusters: info['color'] = self.dh.clusters_info['clusters_info'][clusteridx]['color'] info['groupidx'] = self.dh.clusters_info['clusters_info'][clusteridx]['groupidx'] # group of new cluster = group of corresponding old cluster for old_clusteridx, new_clusteridx in zip(clusters_to_split, new_clusters): clusters_info[new_clusteridx]['groupidx'] = self._old_clusters_info[old_clusteridx]['groupidx'] # update self.dh.nclusters = nclusters self.dh.clusters = clusters self.dh.clusters_info['clusters_info'] = clusters_info # Update correlation matrix. tasks.TASKS.correlation_matrix_queue.process(self.dh)
def execute(self): # if no clusters to merge: do nothing if len(self.clusters_to_merge) == 0: return # invalidate the cross correlograms of the clusters to merge self.sdh.invalidate(self.clusters_to_merge) # get the index of the new cluster self.new_cluster = self.dh.new_cluster() # copy and update the clusters array clusters = self.dh.clusters.copy() # update the clusters array ind = np.in1d(clusters, self.clusters_to_merge) # if old cluster in clusters to merge, then assign to new cluster clusters[ind] = self.new_cluster # get clusters info clusters_info = get_clusters_info(clusters) nclusters = len(clusters_info) colors = np.zeros(nclusters, dtype=np.int32) groups = np.zeros(nclusters, dtype=np.int32) new_color = self.dh.clusters_info['clusters_info'][self.clusters_to_merge[0]]['color'] new_group = self.dh.clusters_info['clusters_info'][self.clusters_to_merge[0]]['groupidx'] for clusteridx, info in clusters_info.iteritems(): # if the cluster has not been changed if clusteridx != self.new_cluster and clusteridx not in self.clusters_to_merge: # new color = old color info['color'] = self.dh.clusters_info['clusters_info'][clusteridx]['color'] info['groupidx'] = self.dh.clusters_info['clusters_info'][clusteridx]['groupidx'] # otherwise, set the new color else: info['color'] = new_color info['groupidx'] = new_group # update self.dh.nclusters = nclusters self.dh.clusters = clusters self.dh.clusters_info['clusters_info'] = clusters_info # Update correlation matrix. tasks.TASKS.correlation_matrix_queue.process(self.dh)