Exemplo n.º 1
0
def get_correlogramsview_data(loader, statscache):
    clusters_selected0 = loader.get_clusters_selected()
    
    # Subset of selected clusters if there are too many clusters.
    max_nclusters = USERPREF['correlograms_max_nclusters']
    if len(clusters_selected0) < max_nclusters:
        clusters_selected = clusters_selected0
    else:
        clusters_selected = clusters_selected0[:max_nclusters]
    
    correlograms = statscache.correlograms.submatrix(
        clusters_selected)
    # Compute the baselines.
    sizes = get_array(select(loader.get_cluster_sizes(), clusters_selected))
    colors = select(loader.get_cluster_colors(), clusters_selected)
    corrbin = SETTINGS.get('correlograms.corrbin', CORRBIN_DEFAULT)
    ncorrbins = SETTINGS.get('correlograms.ncorrbins', NCORRBINS_DEFAULT)
    duration = corrbin * ncorrbins
    baselines = get_baselines(sizes, duration, corrbin)
    data = dict(
        correlograms=correlograms,
        baselines=baselines,
        clusters_selected=clusters_selected,
        cluster_colors=colors,
        ncorrbins=ncorrbins,
        corrbin=corrbin,
    )
    return data
Exemplo n.º 2
0
def get_correlogramsview_data(loader, statscache):
    clusters_selected0 = loader.get_clusters_selected()

    # Subset of selected clusters if there are too many clusters.
    max_nclusters = USERPREF['correlograms_max_nclusters']
    if len(clusters_selected0) < max_nclusters:
        clusters_selected = clusters_selected0
    else:
        clusters_selected = clusters_selected0[:max_nclusters]

    correlograms = statscache.correlograms.submatrix(clusters_selected)
    # Compute the baselines.
    sizes = get_array(select(loader.get_cluster_sizes(), clusters_selected))
    colors = select(loader.get_cluster_colors(), clusters_selected)
    corrbin = SETTINGS.get('correlograms.corrbin', CORRBIN_DEFAULT)
    ncorrbins = SETTINGS.get('correlograms.ncorrbins', NCORRBINS_DEFAULT)
    duration = corrbin * ncorrbins
    baselines = get_baselines(sizes, duration, corrbin)
    data = dict(
        correlograms=correlograms,
        baselines=baselines,
        clusters_selected=clusters_selected,
        cluster_colors=colors,
        ncorrbins=ncorrbins,
        corrbin=corrbin,
    )
    return data
Exemplo n.º 3
0
    def _compute_correlograms(self, clusters_selected):
        # Get the correlograms parameters.
        spiketimes = get_array(self.loader.get_spiketimes('all'))
        # 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')))
        # 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,
                clusters,
                clusters_to_update=clusters_to_update,
                clusters_selected=clusters_selected,
                ncorrbins=ncorrbins,
                corrbin=corrbin)
        # Otherwise, update directly the correlograms view without launching
        # the task in the external process.
        else:
            # self.update_correlograms_view()
            return '_update_correlograms_view'
Exemplo n.º 4
0
 def _compute_correlograms(self, clusters_selected):
     # Get the correlograms parameters.
     spiketimes = get_array(self.loader.get_spiketimes('all'))
     # 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')))
     # 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, clusters,
             clusters_to_update=clusters_to_update, 
             clusters_selected=clusters_selected,
             ncorrbins=ncorrbins, corrbin=corrbin)    
     # Otherwise, update directly the correlograms view without launching
     # the task in the external process.
     else:
         # self.update_correlograms_view()
         return '_update_correlograms_view'
Exemplo n.º 5
0
    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,), {})
Exemplo n.º 6
0
 def change_ncorrbins_callback(self, checked=None):
     if not self.loader:
         return
     corrbin = SETTINGS.get('correlograms.corrbin', CORRBIN_DEFAULT)
     ncorrbins = SETTINGS.get('correlograms.ncorrbins', NCORRBINS_DEFAULT)
     duration = corrbin * ncorrbins
     # duration = self.loader.get_correlogram_window()
     duration_new, ok = QtGui.QInputDialog.getDouble(self,
         "Correlograms time window", "Half width (ms):", 
         duration / 2 * 1000, 1, 100000, 1)
     if ok:
         duration_new = duration_new * .001 * 2
         ncorrbins_new = 2 * int(np.ceil(.5 * duration_new / corrbin))
         # ncorrbins_new = int(duration_new / corrbin * .001)
         SETTINGS['correlograms.ncorrbins'] = ncorrbins_new
         self.taskgraph.change_correlograms_parameters(ncorrbins=ncorrbins_new)
Exemplo n.º 7
0
 def change_ncorrbins_callback(self, checked=None):
     if not self.loader:
         return
     corrbin = SETTINGS.get('correlograms.corrbin', CORRBIN_DEFAULT)
     ncorrbins = SETTINGS.get('correlograms.ncorrbins', NCORRBINS_DEFAULT)
     duration = corrbin * ncorrbins
     # duration = self.loader.get_correlogram_window()
     duration_new, ok = QtGui.QInputDialog.getDouble(self,
         "Correlograms time window", "Half width (ms):",
         duration / 2 * 1000, 1, 100000, 1)
     if ok:
         duration_new = duration_new * .001 * 2
         ncorrbins_new = 2 * int(np.ceil(.5 * duration_new / corrbin))
         # ncorrbins_new = int(duration_new / corrbin * .001)
         SETTINGS['correlograms.ncorrbins'] = ncorrbins_new
         self.taskgraph.change_correlograms_parameters(ncorrbins=ncorrbins_new)
Exemplo n.º 8
0
 def change_corrbin_callback(self, checked=None):
     if not self.loader:
         return
     # ncorrbins = self.loader.ncorrbins
     # corrbin = self.loader.corrbin
     # duration = self.loader.get_correlogram_window()
     corrbin = SETTINGS.get('correlograms.corrbin', CORRBIN_DEFAULT)
     ncorrbins = SETTINGS.get('correlograms.ncorrbins', NCORRBINS_DEFAULT)
     duration = corrbin * ncorrbins
     corrbin_new, ok = QtGui.QInputDialog.getDouble(self,
         "Correlograms bin size", "Bin size (ms):", 
         corrbin * 1000, .01, 1000, 2)
     if ok:
         corrbin_new = corrbin_new * .001
         ncorrbins_new = 2 * int(np.ceil(.5 * duration/ corrbin_new))
         SETTINGS['correlograms.corrbin'] = corrbin_new
         SETTINGS['correlograms.ncorrbins'] = ncorrbins_new
         self.taskgraph.change_correlograms_parameters(corrbin=corrbin_new,
             ncorrbins=ncorrbins_new)
Exemplo n.º 9
0
 def change_corrbin_callback(self, checked=None):
     if not self.loader:
         return
     # ncorrbins = self.loader.ncorrbins
     # corrbin = self.loader.corrbin
     # duration = self.loader.get_correlogram_window()
     corrbin = SETTINGS.get('correlograms.corrbin', CORRBIN_DEFAULT)
     ncorrbins = SETTINGS.get('correlograms.ncorrbins', NCORRBINS_DEFAULT)
     duration = corrbin * ncorrbins
     corrbin_new, ok = QtGui.QInputDialog.getDouble(
         self, "Correlograms bin size", "Bin size (ms):", corrbin * 1000,
         .01, 1000, 2)
     if ok:
         corrbin_new = corrbin_new * .001
         ncorrbins_new = 2 * int(np.ceil(.5 * duration / corrbin_new))
         SETTINGS['correlograms.corrbin'] = corrbin_new
         SETTINGS['correlograms.ncorrbins'] = ncorrbins_new
         self.taskgraph.change_correlograms_parameters(
             corrbin=corrbin_new, ncorrbins=ncorrbins_new)
Exemplo n.º 10
0
    def closeEvent(self, e):
        prompt_save_on_exit = USERPREF['prompt_save_on_exit']
        if prompt_save_on_exit is None:
            prompt_save_on_exit = True
        if self.need_save and prompt_save_on_exit:
            reply = QtGui.QMessageBox.question(self, 'Save',
            "Do you want to save?",
            (
            QtGui.QMessageBox.Save |
             QtGui.QMessageBox.Close |
             QtGui.QMessageBox.Cancel
             ),
            QtGui.QMessageBox.Save)
            if reply == QtGui.QMessageBox.Save:
                folder = SETTINGS.get('main_window.last_data_file')
                self.loader.save()
            elif reply == QtGui.QMessageBox.Cancel:
                e.ignore()
                return
            elif reply == QtGui.QMessageBox.Close:
                pass

        # Save the window geometry when closing the software.
        self.save_geometry()

        # End the threads.
        self.join_threads()

        # Close the loader.
        self.loader.close()

        # Close all views.
        for views in self.views.values():
            for view in views:
                if hasattr(view, 'closeEvent'):
                    view.closeEvent(e)

        # Close the logger file.
        if self.dolog:
            close_file_logger()

        # Close the main window.
        return super(MainWindow, self).closeEvent(e)
Exemplo n.º 11
0
 def open_done(self):
     self.is_file_open = True
     self.setWindowTitle('KlustaViewa: {0:s}'.format(
         os.path.basename(self.loader.filename)
     ))
     
     register(FileLogger(self.loader.log_filename, name='kwik', 
              level=logging.INFO))
     
     # Start the selection buffer.
     self.buffer = Buffer(self, 
         # delay_timer=.1, delay_buffer=.2
         delay_timer=USERPREF['delay_timer'], 
         delay_buffer=USERPREF['delay_buffer']
         )
     self.buffer.start()
     self.buffer.accepted.connect(self.buffer_accepted_callback)
     
     # HACK: force release of Control key.
     self.force_key_release()
     clusters = self.get_view('ClusterView').selected_clusters()
     if clusters:
         self.get_view('ClusterView').unselect()
     
     # Create the Controller.
     self.controller = Controller(self.loader)
     # Create the cache for the cluster statistics that need to be
     # computed in the background.
     self.statscache = StatsCache(SETTINGS.get('correlograms.ncorrbins', NCORRBINS_DEFAULT))
     # Update stats cache in IPython view.
     ipython = self.get_view('IPythonView')
     if ipython:
         ipython.set_data(stats=self.statscache)
     
     # Initialize the wizard.
     self.wizard = Wizard()
     
     # Update the task graph.
     self.taskgraph.set(self)
     # self.taskgraph.update_projection_view()
     self.taskgraph.update_cluster_view()
     self.taskgraph.compute_similarity_matrix()
     self.taskgraph.update_trace_view()
Exemplo n.º 12
0
 def closeEvent(self, e):
     prompt_save_on_exit = USERPREF['prompt_save_on_exit']
     if prompt_save_on_exit is None:
         prompt_save_on_exit = True
     if self.need_save and prompt_save_on_exit:
         reply = QtGui.QMessageBox.question(self, 'Save',
         "Do you want to save?",
         (
         QtGui.QMessageBox.Save | 
          QtGui.QMessageBox.Close |
          QtGui.QMessageBox.Cancel 
          ),
         QtGui.QMessageBox.Save)
         if reply == QtGui.QMessageBox.Save:
             folder = SETTINGS.get('main_window.last_data_file')
             self.loader.save()
         elif reply == QtGui.QMessageBox.Cancel:
             e.ignore()
             return
         elif reply == QtGui.QMessageBox.Close:
             pass
     
     # Save the window geometry when closing the software.
     self.save_geometry()
     
     # End the threads.
     self.join_threads()
     
     # Close the loader.
     self.loader.close()
     
     # Close all views.
     for views in self.views.values():
         for view in views:
             if hasattr(view, 'closeEvent'):
                 view.closeEvent(e)
     
     # Close the logger file.
     if self.dolog:
         close_file_logger()
     
     # Close the main window.
     return super(MainWindow, self).closeEvent(e)
Exemplo n.º 13
0
    def open_done(self):
        self.is_file_open = True
        self.setWindowTitle('KlustaViewa: {0:s}'.format(
            os.path.basename(self.loader.filename)
        ))

        register(FileLogger(self.loader.log_filename, name='kwik',
                 level=logging.INFO))

        # Start the selection buffer.
        self.buffer = Buffer(self,
            # delay_timer=.1, delay_buffer=.2
            delay_timer=USERPREF['delay_timer'],
            delay_buffer=USERPREF['delay_buffer']
            )
        self.buffer.start()
        self.buffer.accepted.connect(self.buffer_accepted_callback)

        # HACK: force release of Control key.
        self.force_key_release()
        clusters = self.get_view('ClusterView').selected_clusters()
        if clusters:
            self.get_view('ClusterView').unselect()

        # Create the Controller.
        self.controller = Controller(self.loader)
        # Create the cache for the cluster statistics that need to be
        # computed in the background.
        self.statscache = StatsCache(SETTINGS.get('correlograms.ncorrbins', NCORRBINS_DEFAULT))
        # Update stats cache in IPython view.
        ipython = self.get_view('IPythonView')
        if ipython:
            ipython.set_data(stats=self.statscache)

        # Initialize the wizard.
        self.wizard = Wizard()

        # Update the task graph.
        self.taskgraph.set(self)
        # self.taskgraph.update_projection_view()
        self.taskgraph.update_cluster_view()
        self.taskgraph.compute_similarity_matrix()
Exemplo n.º 14
0
 def restore_geometry(self):
     """Return a dictionary with the user preferences regarding geometry
     in the WaveformView."""
     pref = SETTINGS.get('waveform_view.geometry')
     self.position_manager.set_geometry_preferences(pref)
Exemplo n.º 15
0
 def save_geometry(self):
     pref = self.position_manager.get_geometry_preferences()
     SETTINGS.set('waveform_view.geometry', pref)
Exemplo n.º 16
0
 def restore_geometry(self):
     """Return a dictionary with the user preferences regarding geometry
     in the WaveformView."""
     pref = SETTINGS.get('waveform_view.geometry')
     self.position_manager.set_geometry_preferences(pref)
Exemplo n.º 17
0
 def save_geometry(self):
     pref = self.position_manager.get_geometry_preferences()
     SETTINGS.set('waveform_view.geometry', pref)