def _compute_correlograms(self, clusters_selected, wizard=None): # Get the correlograms parameters. spiketimes = get_array(self.loader.get_spiketimes("all")) sample_rate = self.loader.freq # print spiketimes.dtype # Make a copy of the array so that it does not change before the # computation of the correlograms begins. clusters = np.array(get_array(self.loader.get_clusters("all"))) # Get excerpts nexcerpts = USERPREF.get("correlograms_nexcerpts", 50) excerpt_size = USERPREF.get("correlograms_excerpt_size", 10000) spiketimes_excerpts = get_excerpts(spiketimes, nexcerpts=nexcerpts, excerpt_size=excerpt_size) clusters_excerpts = get_excerpts(clusters, nexcerpts=nexcerpts, excerpt_size=excerpt_size) # corrbin = self.loader.corrbin # ncorrbins = self.loader.ncorrbins corrbin = SETTINGS.get("correlograms.corrbin", 0.001) ncorrbins = SETTINGS.get("correlograms.ncorrbins", 101) # Ensure ncorrbins is odd. if ncorrbins % 2 == 0: ncorrbins += 1 # Get cluster indices that need to be updated. # clusters_to_update = (self.statscache.correlograms. # not_in_key_indices(clusters_selected)) clusters_to_update = clusters_selected # If there are pairs that need to be updated, launch the task. if len(clusters_to_update) > 0: # Set wait cursor. self.mainwindow.set_busy(computing_correlograms=True) # Launch the task. self.tasks.correlograms_task.compute( spiketimes_excerpts, clusters_excerpts, clusters_to_update=clusters_to_update, clusters_selected=clusters_selected, ncorrbins=ncorrbins, corrbin=corrbin, sample_rate=sample_rate, wizard=wizard, ) # Otherwise, update directly the correlograms view without launching # the task in the external process. else: # self.update_correlograms_view() return ("_update_correlograms_view", (wizard,), {})
def _compute_correlograms(self, clusters_selected, wizard=None): # Get the correlograms parameters. spiketimes = get_array(self.loader.get_spiketimes('all')) # print spiketimes.dtype # Make a copy of the array so that it does not change before the # computation of the correlograms begins. clusters = np.array(get_array(self.loader.get_clusters('all'))) # Get excerpts nexcerpts = USERPREF.get('correlograms_nexcerpts', 100) excerpt_size = USERPREF.get('correlograms_excerpt_size', 20000) spiketimes_excerpts = get_excerpts(spiketimes, nexcerpts=nexcerpts, excerpt_size=excerpt_size) clusters_excerpts = get_excerpts(clusters, nexcerpts=nexcerpts, excerpt_size=excerpt_size) # corrbin = self.loader.corrbin # ncorrbins = self.loader.ncorrbins corrbin = SETTINGS.get('correlograms.corrbin', .001) ncorrbins = SETTINGS.get('correlograms.ncorrbins', 100) # Get cluster indices that need to be updated. clusters_to_update = ( self.statscache.correlograms.not_in_key_indices(clusters_selected)) # If there are pairs that need to be updated, launch the task. if len(clusters_to_update) > 0: # Set wait cursor. self.mainwindow.set_busy(computing_correlograms=True) # Launch the task. self.tasks.correlograms_task.compute( spiketimes_excerpts, clusters_excerpts, clusters_to_update=clusters_to_update, clusters_selected=clusters_selected, ncorrbins=ncorrbins, corrbin=corrbin, wizard=wizard) # Otherwise, update directly the correlograms view without launching # the task in the external process. else: # self.update_correlograms_view() return ('_update_correlograms_view', (wizard, ), {})
def get_featureview_data(loader, autozoom): data = dict( features=loader.get_features(), features_background=loader.get_features_background(), spiketimes=loader.get_spiketimes(), masks=loader.get_masks(), clusters=loader.get_clusters(), clusters_selected=loader.get_clusters_selected(), cluster_colors=loader.get_cluster_colors(), nchannels=loader.nchannels, fetdim=loader.fetdim, nextrafet=loader.nextrafet, freq=loader.freq, autozoom=autozoom, duration=loader.get_duration(), alpha_selected=USERPREF.get('feature_selected_alpha', .75), alpha_background=USERPREF.get('feature_background_alpha', .1), time_unit=USERPREF['features_info_time_unit'] or 'second', ) return data
def refresh_preferences_callback(self, checked=None): log.debug("Refreshing user preferences.") USERPREF.refresh()
def set_data(self, features=None, features_background=None, spiketimes=None, # a subset of all spikes, disregarding cluster masks=None, # masks for all spikes in selected clusters clusters=None, # clusters for all spikes in selected clusters clusters_selected=None, cluster_colors=None, fetdim=None, nchannels=None, channels=None, nextrafet=None, autozoom=None, # None, or the target cluster duration=None, freq=None, alpha_selected=.75, alpha_background=.25, time_unit=None, ): if features is None: features = np.zeros((0, 2)) features_background = np.zeros((0, 2)) masks = np.zeros((0, 1)) clusters = np.zeros(0, dtype=np.int32) clusters_selected = [] cluster_colors = np.zeros(0, dtype=np.int32) fetdim = 2 nchannels = 1 nextrafet = 0 if features.shape[1] == 1: features = np.tile(features, (1, 4)) if features_background.shape[1] == 1: features_background = np.tile(features_background, (1, 4)) assert fetdim is not None self.duration = duration self.spiketimes = spiketimes self.freq = freq self.interaction_manager.get_processor('grid').update_viewbox() # Feature background alpha value. self.alpha_selected = alpha_selected self.alpha_background = alpha_background # can be 'second' or 'samples' self.time_unit = time_unit # Extract the relevant spikes, but keep the other ones in features_full self.clusters = clusters # Contains all spikes, needed for splitting. self.features_full = features self.features_full_array = get_array(features) # Keep a subset of all spikes in the view. self.nspikes_full = len(features) # > features_nspikes_per_cluster_max spikes ==> take a selection nspikes_max = USERPREF.get('features_nspikes_per_cluster_max', 1000) k = self.nspikes_full // nspikes_max + 1 # self.features = features[::k] subsel = slice(None, None, k) self.features = select(features, subsel) self.features_array = get_array(self.features) # self.features_background contains all non-selected spikes self.features_background = features_background self.features_background_array = get_array(self.features_background) # Background spikes are those which do not belong to the selected clusters self.npoints_background = self.features_background_array.shape[0] self.nspikes_background = self.npoints_background if channels is None: channels = range(nchannels) self.nspikes, self.ndim = self.features.shape self.fetdim = fetdim self.nchannels = nchannels self.channels = channels self.nextrafet = nextrafet self.npoints = self.features.shape[0] if masks is None: masks = np.ones_like(self.features, dtype=np.float32) self.masks = masks # Subselection self.masks = select(self.masks, subsel) self.masks_array = get_array(self.masks) if self.spiketimes is not None: self.spiketimes = select(self.spiketimes, subsel) self.clusters = select(self.clusters, subsel) self.clusters_array = get_array(self.clusters) self.feature_indices = get_indices(self.features) self.feature_full_indices = get_indices(self.features_full) self.feature_indices_array = get_array(self.feature_indices) self.cluster_colors = get_array(cluster_colors, dosort=True) # Relative indexing. if self.npoints > 0: self.clusters_rel = np.digitize(self.clusters_array, sorted(clusters_selected)) - 1 self.clusters_rel_ordered = np.argsort(clusters_selected)[self.clusters_rel] else: self.clusters_rel = np.zeros(0, dtype=np.int32) self.clusters_rel_ordered = np.zeros(0, dtype=np.int32) self.clusters_unique = sorted(clusters_selected) self.nclusters = len(clusters_selected) self.masks_full = self.masks_array.T.ravel() self.clusters_full_depth = self.clusters_rel_ordered self.clusters_full = self.clusters_rel # prepare GPU data self.data = np.empty((self.nspikes, 2), dtype=np.float32) self.data_full = np.empty((self.nspikes_full, 2), dtype=np.float32) self.data_background = np.empty((self.nspikes_background, 2), dtype=np.float32) # set initial projection self.projection_manager.set_data() self.autozoom = autozoom if autozoom is None: self.projection_manager.reset_projection() else: self.projection_manager.auto_projection(autozoom) # update the highlight manager self.highlight_manager.initialize() self.selection_manager.initialize() self.selection_manager.cancel_selection()