<commit_before>#!/usr/bin/env python
"""
this file contains the code for the spike sorting GUI
"""
from __future__ import print_function, division, absolute_import
import sys
import os
from getpass import getuser
from time import strftime

from PyQt4.QtCore import *
from PyQt4.QtGui import *


from .ui_sorter import Ui_MainWindow

from .sort_widgets import AllGroupsFigure, ComparisonFigure,\
    GroupOverviewFigure
from .raster_figure import RasterFigure
from .backend import Backend
from .load_joblist import PickJobList, GotoJob
from .picksession import PickSessionDialog
from .group_list_model import ClusterDelegate
from .basics import spikeDist

import numpy as np

from .. import options, TYPE_ART, TYPE_MU, TYPE_SU, TYPE_NO

imageSize = 260
stylesheet = 'QListView:focus { background-color: rgb(240, 255, 255)}'
DEBUG = options['Debug']
LOGFILENAME = 'css_gui_log.txt'


class SpikeSorter(QMainWindow, Ui_MainWindow):
    """
    main class
    """
    def __init__(self, parent=None, arg=None):
        super(SpikeSorter, self).__init__(parent)

        self.setupUi(self)
        self.backend = None
        self.groupOverviewFigure = GroupOverviewFigure(self.centralwidget)
        self.allGroupsFigureDirty = True

        self.oneGroupLayout.addWidget(self.groupOverviewFigure)

        self.allGroupsFigure = AllGroupsFigure(self.centralwidget)
        self.allGroupsFigure.fig.canvas.mpl_connect('button_press_event',
                                                    self.onclick)
        self.allGroupsLayout.addWidget(self.allGroupsFigure)
        self.groupsComparisonFigure = ComparisonFigure(self.centralwidget)
        self.compareFigureLayout.addWidget(self.groupsComparisonFigure)
        view = self.listView
        view.setViewMode(QListView.IconMode)
        view.setResizeMode(QListView.Adjust)
        view.setItemDelegate(ClusterDelegate(self))
        view.setStyleSheet(stylesheet)
        view.addAction(self.actionMakeArtifact)
        view.addAction(self.actionMarkCluster)

        self.allGroupsTab.addAction(self.actionAutoassign)

        for action in (self.actionMakeArtifact,
                       self.actionMarkCluster):
            action.setShortcutContext(Qt.WidgetShortcut)

        self.groupComboBox.addAction(self.actionNextGroup)
        self.actionNewGroup.triggered.connect(self.actionNewGroup_triggered)
        self.pushButtonSave.clicked.connect(self.save_one_group)
        self.pushButtonMerge.clicked.connect(self.actionMerge_triggered)

        self.groupComboBox.currentIndexChanged.\
            connect(self.updateListView)
        self.tabWidget.currentChanged.\
            connect(self.updateActiveTab)

        self.autoassignPushButton.clicked.\
            connect(self.on_actionAutoassign_triggered)

        self.multiRadioButton.toggled.connect(self.saveTypeMU)
        self.singleRadioButton.toggled.connect(self.saveTypeSU)
        self.artifactRadioButton.toggled.connect(self.saveTypeArti)

        self.actionOpen.triggered.connect(self.actionOpen_triggered)
        self.comparePlotpushButton.clicked.connect(self.compare_groups)

        self.actionOpenJobs.triggered.connect(self.actionOpenJobs_triggered)
        self.actionNextJob.triggered.connect(self.actionNextJob_triggered)
        self.actionMergeAll.triggered.connect(self.actionMergeAll_triggered)
        self.actionGotoJob.triggered.connect(self.actionGotoJob_triggered)
        self.actionMerge.triggered.connect(self.actionMerge_triggered)

        if len(arg) > 1:
            self.basedir = os.path.dirname(arg)
        else:
            self.basedir = os.getcwd()

        self.logfid = open(LOGFILENAME, 'a')
        self.user = getuser()

        if 'RunGuiWithRaster' in options:
            if options['RunGuiWithRaster']:
                self.init_raster()

    def init_raster(self):
        import pandas as pd

        # the following is just an example for one specific experiment
        base = os.path.basename(self.basedir)
        try:
            pat = int(base[:3])
            fn = int(base[8:9])
        except ValueError:
            return
        infix = '{:03d}fn{}'.format(pat, fn)
        fname_frame = 'frame_{}.h5'.format(infix)
        frame = pd.read_hdf(fname_frame, 'fn_frame')
        meta_prefix = '/home/johannes/struc/metadata/fotonovela-meta/'
        image_path = os.path.join(meta_prefix, infix, infix)

        # now initialize the data
        self.rasterFigure = RasterFigure(self.centralwidget)
        self.rasterLayout.addWidget(self.rasterFigure)<commit_msg>Added raster widget to master branch<commit_after>#!/usr/bin/env python
"""
this file contains the code for the spike sorting GUI
"""
from __future__ import print_function, division, absolute_import
import sys
import os
from getpass import getuser
from time import strftime

from PyQt4.QtCore import *
from PyQt4.QtGui import *


from .ui_sorter import Ui_MainWindow

from .sort_widgets import AllGroupsFigure, ComparisonFigure,\
    GroupOverviewFigure
from .raster_figure import RasterFigure
from .backend import Backend
from .load_joblist import PickJobList, GotoJob
from .picksession import PickSessionDialog
from .group_list_model import ClusterDelegate
from .basics import spikeDist

import numpy as np

from .. import options, TYPE_ART, TYPE_MU, TYPE_SU, TYPE_NO

imageSize = 260
stylesheet = 'QListView:focus { background-color: rgb(240, 255, 255)}'
DEBUG = options['Debug']
LOGFILENAME = 'css_gui_log.txt'


class SpikeSorter(QMainWindow, Ui_MainWindow):
    """
    main class
    """
    def __init__(self, parent=None, arg=None):
        super(SpikeSorter, self).__init__(parent)

        self.setupUi(self)
        self.backend = None
        self.groupOverviewFigure = GroupOverviewFigure(self.centralwidget)
        self.allGroupsFigureDirty = True

        self.oneGroupLayout.addWidget(self.groupOverviewFigure)

        self.allGroupsFigure = AllGroupsFigure(self.centralwidget)
        self.allGroupsFigure.fig.canvas.mpl_connect('button_press_event',
                                                    self.onclick)
        self.allGroupsLayout.addWidget(self.allGroupsFigure)
        self.groupsComparisonFigure = ComparisonFigure(self.centralwidget)
        self.compareFigureLayout.addWidget(self.groupsComparisonFigure)
        view = self.listView
        view.setViewMode(QListView.IconMode)
        view.setResizeMode(QListView.Adjust)
        view.setItemDelegate(ClusterDelegate(self))
        view.setStyleSheet(stylesheet)
        view.addAction(self.actionMakeArtifact)
        view.addAction(self.actionMarkCluster)

        self.allGroupsTab.addAction(self.actionAutoassign)

        for action in (self.actionMakeArtifact,
                       self.actionMarkCluster):
            action.setShortcutContext(Qt.WidgetShortcut)

        self.groupComboBox.addAction(self.actionNextGroup)
        self.actionNewGroup.triggered.connect(self.actionNewGroup_triggered)
        self.pushButtonSave.clicked.connect(self.save_one_group)
        self.pushButtonMerge.clicked.connect(self.actionMerge_triggered)

        self.groupComboBox.currentIndexChanged.\
            connect(self.updateListView)
        self.tabWidget.setTabEnabled(3, False)
        
        self.tabWidget.currentChanged.\
            connect(self.updateActiveTab)

        self.autoassignPushButton.clicked.\
            connect(self.on_actionAutoassign_triggered)

        self.multiRadioButton.toggled.connect(self.saveTypeMU)
        self.singleRadioButton.toggled.connect(self.saveTypeSU)
        self.artifactRadioButton.toggled.connect(self.saveTypeArti)

        self.actionOpen.triggered.connect(self.actionOpen_triggered)
        self.comparePlotpushButton.clicked.connect(self.compare_groups)

        self.actionOpenJobs.triggered.connect(self.actionOpenJobs_triggered)
        self.actionNextJob.triggered.connect(self.actionNextJob_triggered)
        self.actionMergeAll.triggered.connect(self.actionMergeAll_triggered)
        self.actionGotoJob.triggered.connect(self.actionGotoJob_triggered)
        self.actionMerge.triggered.connect(self.actionMerge_triggered)

        if len(arg) > 1:
            self.basedir = os.path.dirname(arg)
        else:
            self.basedir = os.getcwd()

        self.logfid = open(LOGFILENAME, 'a')
        self.user = getuser()

        if 'RunGuiWithRaster' in options:
            if options['RunGuiWithRaster']:
                self.tabWidget.setTabEnabled(3, True)
                self.init_raster()

    def init_raster(self):
        import pandas as pd

        # the following is just an example for one specific experiment
        base = os.path.basename(self.basedir)
        try:
            pat = int(base[:3])
            fn = int(base[8:9])
        except ValueError:
            return
        infix = '{:03d}fn{}'.format(pat, fn)
        fname_frame = 'frame_{}.h5'.format(infix)
        frame = pd.read_hdf(fname_frame, 'fn_frame')
        meta_prefix = '/home/johannes/struc/metadata/fotonovela-meta/'
        image_path = os.path.join(meta_prefix, infix, infix)

        # now initialize the data
        self.rasterFigure = RasterFigure(self.centralwidget)
        self.rasterLayout.addWidget(self.rasterFigure)
{'fraction_non_alphanumeric': 0.0861005949161709, 'fraction_numerical': 0.004759329367225527, 'mean_word_length': 3.0570425625274242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6408568', 'n_tokens_mistral': 2778, 'n_tokens_neox': 2655, 'n_words': 454}