コード例 #1
0
ファイル: gui.py プロジェクト: yzerlaut/physion
    def __init__(self,
                 app,
                 args=None,
                 parent=None,
                 raw_data_visualization=False,
                 fullscreen=False):

        self.app = app
        self.settings = settings
        self.raw_data_visualization = raw_data_visualization
        self.no_subsampling = False

        super(MainWindow, self).__init__(i=0, title='Data Visualization')

        # play button
        self.updateTimer = QtCore.QTimer()
        self.updateTimer.timeout.connect(self.next_frame)

        guiparts.load_config1(self)
        self.fbox.addItems(FOLDERS.keys())
        self.windowTA, self.windowBM = None, None  # sub-windows

        if args is not None:
            self.root_datafolder = args.root_datafolder
        else:
            self.root_datafolder = os.path.join(os.path.expanduser('~'),
                                                'DATA')

        self.time, self.io, self.roiIndices, self.tzoom = 0, None, [], [0, 50]
        self.CaImaging_bg_key = 'meanImg'
        self.CaImaging_key = 'Fluorescence'

        self.FILES_PER_DAY, self.FILES_PER_SUBJECT, self.SUBJECTS = {}, {}, {}

        self.minView = False
        self.showwindow()
コード例 #2
0
    def __init__(self, app,
                 args=None,
                 parent=None,
                 spatial_subsampling=1,
                 time_subsampling=1):
        """
        sampling in Hz
        """
        self.app = app
        
        super(MainWindow, self).__init__(i=1,
                                         title='Face-motion/Whisking tracking')
        
        # self.refEx = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+E'), self)
        # self.refEx.activated.connect(self.exclude_outlier)
        # self.refPr = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+P'), self)
        # self.refPr.activated.connect(self.process_outliers)
        # self.refc1 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+1'), self)
        # self.refc1.activated.connect(self.set_cursor_1)
        # self.refc2 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+2'), self)
        # self.refc2.activated.connect(self.set_cursor_2)
        # self.refc3 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+3'), self)
        # self.refc3.activated.connect(self.process_outliers)

        self.process_script = os.path.join(str(pathlib.Path(__file__).resolve().parents[0]),
                                           'process.py')
        
        
        self.minView = False
        self.showwindow()
        
        pg.setConfigOptions(imageAxisOrder='row-major')
        
        self.spatial_subsampling = spatial_subsampling
        self.time_subsampling = time_subsampling
        
        self.cwidget = QtGui.QWidget(self)
        self.setCentralWidget(self.cwidget)
        self.l0 = QtGui.QGridLayout()
        self.cwidget.setLayout(self.l0)
        self.win = pg.GraphicsLayoutWidget()
        self.win.move(600,0)
        self.win.resize(600,400)
        self.l0.addWidget(self.win,1,3,37,15)
        layout = self.win.ci.layout

        # A plot area (ViewBox + axes) for displaying the image
        self.p0 = self.win.addViewBox(lockAspect=False,row=0,col=0,invertY=True,
                                      border=[100,100,100])
        self.p0.setMouseEnabled(x=False,y=False)
        self.p0.setMenuEnabled(False)
        self.pimg = pg.ImageItem()
        self.p0.setAspectLocked()
        self.p0.addItem(self.pimg)

        # image ROI
        self.pFace = self.win.addViewBox(lockAspect=False,row=0,col=1,invertY=True,
                                         border=[100,100,100])
        self.pFace.setAspectLocked()
        #self.p0.setMouseEnabled(x=False,y=False)
        self.pFace.setMenuEnabled(False)
        self.pFaceimg = pg.ImageItem(None)
        self.pFace.addItem(self.pFaceimg)

        # roi initializations
        self.iROI = 0
        self.nROIs = 0
        self.saturation = 255
        self.ROI = None
        self.pupil = None
        self.iframes, self.times, self.Pr1, self.Pr2 = [], [], [], []
        self.times, self.imgfolder, self.nframes, self.FILES = None, None, None, None

        # saturation sliders
        self.sl = guiparts.Slider(0, self)
        self.l0.addWidget(self.sl,1,6,1,7)
        qlabel= QtGui.QLabel('saturation')
        qlabel.setStyleSheet('color: white;')
        self.l0.addWidget(qlabel, 0,8,1,3)

        # # # adding blanks ("corneal reflections, ...")
        # self.roiBtn = QtGui.QPushButton('set ROI')
        # self.l0.addWidget(self.roiBtn, 1, 8+6, 1, 1)
        # self.roiBtn.setEnabled(True)
        # self.roiBtn.clicked.connect(self.add_ROI)
        
        # # fit pupil
        # self.fit_pupil = QtGui.QPushButton('fit Pupil [Ctrl+F]')
        # self.l0.addWidget(self.fit_pupil, 1, 9+6, 1, 1)
        # # self.fit_pupil.setEnabled(True)
        # self.fit_pupil.clicked.connect(self.fit_pupil_size)
        # # choose pupil shape
        # self.pupil_shape = QtGui.QComboBox(self)
        # self.pupil_shape.addItem("Ellipse fit")
        # self.pupil_shape.addItem("Circle fit")
        # self.l0.addWidget(self.pupil_shape, 1, 10+6, 1, 1)
        # reset
        self.reset_btn = QtGui.QPushButton('reset')
        self.l0.addWidget(self.reset_btn, 1, 11+6, 1, 1)
        self.reset_btn.clicked.connect(self.reset)
        self.reset_btn.setEnabled(True)

        
        self.debugBtn = QtGui.QPushButton('- Debug -')
        self.l0.addWidget(self.debugBtn, 2, 11+6, 1, 1)
        self.debugBtn.setEnabled(True)
        self.debugBtn.clicked.connect(self.debug)

        self.data = None
        self.scatter, self.fit= None, None # the pupil size contour

        self.p1 = self.win.addPlot(name='plot1',row=1,col=0, colspan=2, rowspan=4,
                                   title='*face motion*')
        self.p1.setMouseEnabled(x=True,y=False)
        self.p1.setMenuEnabled(False)
        self.p1.hideAxis('left')
        self.scatter = pg.ScatterPlotItem()
        self.p1.addItem(self.scatter)
        self.p1.setLabel('bottom', 'time (frame #)')
        self.xaxis = self.p1.getAxis('bottom')
        self.p1.autoRange(padding=0.01)
        
        self.win.ci.layout.setRowStretchFactor(0,5)
        self.movieLabel = QtGui.QLabel("No datafile chosen")
        self.movieLabel.setStyleSheet("color: white;")
        self.l0.addWidget(self.movieLabel,0,1,1,5)


        # create frame slider
        self.timeLabel = QtGui.QLabel("time : ")
        self.timeLabel.setStyleSheet("color: white;")
        # self.timeLabel.setFixedWidth(300)
        self.currentTime = QtGui.QLineEdit()
        self.currentTime.setText('0 s')
        self.currentTime.setFixedWidth(70)
        # self.currentTime.returnPressed.connect(self.set_precise_time)
        
        self.frameSlider = QtGui.QSlider(QtCore.Qt.Horizontal)
        self.frameSlider.setMinimum(0)
        self.frameSlider.setMaximum(200)
        self.frameSlider.setTickInterval(1)
        self.frameSlider.setTracking(False)
        self.frameSlider.valueChanged.connect(self.go_to_frame)

        istretch = 23
        iplay = istretch+15
        iconSize = QtCore.QSize(20, 20)

        self.folderB = QtWidgets.QComboBox(self)
        self.folderB.setMinimumWidth(150)
        self.folderB.addItems(FOLDERS.keys())
        
        self.processBtn = QtGui.QPushButton('process data')
        self.processBtn.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.processBtn.clicked.connect(self.process)

        # self.interpolate = QtGui.QPushButton('interpolate')
        # self.interpolate.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        # self.interpolate.clicked.connect(self.interpolate_data)

        self.motionCheckBox = QtGui.QCheckBox("display motion frames")
        self.motionCheckBox.setStyleSheet("color: gray;")
        
        self.runAsSubprocess = QtGui.QPushButton('run as subprocess')
        self.runAsSubprocess.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.runAsSubprocess.clicked.connect(self.run_as_subprocess)
        # self.runAsSubprocess.setEnabled(True)

        self.load = QtGui.QPushButton('  load data [Ctrl+O]  \u2b07')
        self.load.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.load.clicked.connect(self.open_file)

        sampLabel1 = QtGui.QLabel("spatial subsampling")
        sampLabel1.setStyleSheet("color: gray;")
        sampLabel1.setFixedWidth(220)
        self.SsamplingBox = QtGui.QLineEdit()
        self.SsamplingBox.setText(str(self.spatial_subsampling))
        self.SsamplingBox.setFixedWidth(30)

        sampLabel2 = QtGui.QLabel("temporal subsampling")
        sampLabel2.setStyleSheet("color: gray;")
        sampLabel2.setFixedWidth(220)
        self.TsamplingBox = QtGui.QLineEdit()
        self.TsamplingBox.setText(str(self.time_subsampling))
        self.TsamplingBox.setFixedWidth(30)
        
        self.addROI = QtGui.QPushButton("set ROI")
        self.addROI.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.addROI.clicked.connect(self.add_ROI)

        self.saveData = QtGui.QPushButton('save data')
        self.saveData.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.saveData.clicked.connect(self.save_data)

        iconSize = QtCore.QSize(30, 30)
        self.playButton = QtGui.QToolButton()
        self.playButton.setIcon(self.style().standardIcon(QtGui.QStyle.SP_MediaPlay))
        self.playButton.setIconSize(iconSize)
        self.playButton.setToolTip("Play")
        self.playButton.setCheckable(True)
        self.pauseButton = QtGui.QToolButton()
        self.pauseButton.setCheckable(True)
        self.pauseButton.setIcon(self.style().standardIcon(QtGui.QStyle.SP_MediaPause))
        self.pauseButton.setIconSize(iconSize)
        self.pauseButton.setToolTip("Pause")

        btns = QtGui.QButtonGroup(self)
        btns.addButton(self.playButton,0)
        btns.addButton(self.pauseButton,1)

        self.l0.addWidget(self.folderB,1,0,1,3)
        self.l0.addWidget(self.load,2,0,1,3)
        self.l0.addWidget(self.addROI,14,0,1,3)
        self.l0.addWidget(self.saveData, 16, 0, 1, 3)
        self.l0.addWidget(self.processBtn, 20, 0, 1, 3)
        self.l0.addWidget(self.runAsSubprocess, 21, 0, 1, 3)
        self.l0.addWidget(self.motionCheckBox, 18, 0, 1, 3)
        
        self.l0.addWidget(sampLabel1, 8, 0, 1, 3)
        self.l0.addWidget(self.SsamplingBox, 8, 2, 1, 3)
        self.l0.addWidget(sampLabel2, 9, 0, 1, 3)
        self.l0.addWidget(self.TsamplingBox, 9, 2, 1, 3)

        self.l0.addWidget(QtGui.QLabel(''),istretch,0,1,3)
        self.l0.setRowStretch(istretch,1)
        self.l0.addWidget(self.timeLabel, istretch+10,0,1,3)
        self.l0.addWidget(self.currentTime, istretch+10,1,1,3)
        self.l0.addWidget(self.frameSlider, istretch+15,3,1,15)

        self.l0.addWidget(QtGui.QLabel(''),17,2,1,1)
        self.l0.setRowStretch(16,2)
        # self.l0.addWidget(ll, istretch+3+k+1,0,1,4)
        self.timeLabel.setEnabled(True)
        self.frameSlider.setEnabled(True)
        
        self.nframes = 0
        self.cframe = 0

        self.show()
コード例 #3
0
    def __init__(self, app, args=None, parent=None):
        """
        sampling in Hz
        """
        self.app = app

        super(MainWindow, self).__init__()

        self.setWindowTitle('Assembling')

        self.setGeometry(50, 700, 300, 370)
        # adding a "quit" keyboard shortcut
        self.quitSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'), self)
        self.quitSc.activated.connect(self.quit)

        self.process_script = os.path.join(
            str(pathlib.Path(__file__).resolve().parents[0]), 'build_NWB.py')
        self.script = os.path.join(
            str(pathlib.Path(__file__).resolve().parents[1]),
            'script.sh')  # for batch processing

        self.add2Bash = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+B'), self)
        self.add2Bash.activated.connect(self.add_to_bash_script)

        HEIGHT = 0

        HEIGHT += 10
        QtWidgets.QLabel("Root-folder:", self).move(10, HEIGHT)
        self.folderB = QtWidgets.QComboBox(self)
        self.folderB.setMinimumWidth(150)
        self.folderB.move(100, HEIGHT)
        self.folderB.addItems(FOLDERS.keys())

        HEIGHT += 40
        self.load = QtWidgets.QPushButton('[L]oad datafolder  \u2b07', self)
        self.load.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.load.clicked.connect(self.load_folder)
        self.load.setMinimumWidth(200)
        self.load.move(50, HEIGHT)
        self.loadSc = QtWidgets.QShortcut(QtGui.QKeySequence('L'), self)
        self.loadSc.activated.connect(self.load_folder)

        HEIGHT += 50
        QtWidgets.QLabel("=> Setting :", self).move(10, HEIGHT)
        self.cbc = QtWidgets.QComboBox(self)
        self.cbc.setMinimumWidth(150)
        self.cbc.move(100, HEIGHT)
        self.cbc.activated.connect(self.update_setting)
        self.cbc.addItems(['custom', 'nidaq_only', 'lightweight', 'full'])

        HEIGHT += 40
        s = QtWidgets.QLabel("Photodiode-Sampling (Hz)    ", self)
        s.move(10, HEIGHT)
        s.setMinimumWidth(200)
        self.PHsamplingBox = QtWidgets.QLineEdit('', self)
        self.PHsamplingBox.setText('500')
        self.PHsamplingBox.setFixedWidth(40)
        self.PHsamplingBox.move(200, HEIGHT)

        HEIGHT += 30
        s = QtWidgets.QLabel("Running-Speed-Sampling (Hz)    ", self)
        s.move(10, HEIGHT)
        s.setMinimumWidth(200)
        self.RsamplingBox = QtWidgets.QLineEdit('', self)
        self.RsamplingBox.setText('50')
        self.RsamplingBox.setFixedWidth(40)
        self.RsamplingBox.move(200, HEIGHT)

        HEIGHT += 30
        s = QtWidgets.QLabel("Whisking-Sampling (Hz)    ", self)
        s.move(10, HEIGHT)
        s.setMinimumWidth(200)
        self.WsamplingBox = QtWidgets.QLineEdit('', self)
        self.WsamplingBox.setText('0.05')
        self.WsamplingBox.setFixedWidth(40)
        self.WsamplingBox.move(200, HEIGHT)

        HEIGHT += 30
        s = QtWidgets.QLabel("Pupil-Sampling (Hz)    ", self)
        s.move(10, HEIGHT)
        s.setMinimumWidth(200)
        self.PsamplingBox = QtWidgets.QLineEdit('', self)
        self.PsamplingBox.setText('0.5')
        self.PsamplingBox.setFixedWidth(40)
        self.PsamplingBox.move(200, HEIGHT)

        HEIGHT += 30
        s = QtWidgets.QLabel("FaceCamera-Sampling (Hz)    ", self)
        s.move(10, HEIGHT)
        s.setMinimumWidth(200)
        self.FsamplingBox = QtWidgets.QLineEdit('', self)
        self.FsamplingBox.setText('0.001')
        self.FsamplingBox.setFixedWidth(40)
        self.FsamplingBox.move(200, HEIGHT)

        HEIGHT += 50
        self.gen = QtWidgets.QPushButton(' -= RUN =-  ', self)
        self.gen.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.gen.clicked.connect(self.run)
        self.gen.setMinimumWidth(200)
        self.gen.move(50, HEIGHT)

        self.folder = ''
        self.show()
コード例 #4
0
    def __init__(self,
                 app,
                 args=None,
                 parent=None,
                 raw_data_visualization=False,
                 df_width=600,
                 selector_height=30,
                 win1_Wmax=1200,
                 win1_Wmin=300,
                 win1_Hmax=300,
                 win2_Wmax=500,
                 fullscreen=False):

        self.app = app
        self.settings = settings
        self.raw_data_visualization = raw_data_visualization
        self.no_subsampling = False

        super(MainWindow, self).__init__(i=0, title='Data Visualization')

        # play button
        self.updateTimer = QtCore.QTimer()
        self.updateTimer.timeout.connect(self.next_frame)

        self.cwidget = QtWidgets.QWidget(self)
        self.setCentralWidget(self.cwidget)

        self.statusBar.showMessage(
            'open file [O],    refresh plot [R],    play/pause [Space],    initial-view [I],    max-window [M] '
        )

        mainLayout = QtWidgets.QVBoxLayout()

        Layout1 = QtWidgets.QHBoxLayout()
        mainLayout.addLayout(Layout1)

        Layout11 = QtWidgets.QVBoxLayout()
        Layout1.addLayout(Layout11)
        guiparts.create_calendar(self, Layout11)
        self.cal.setMaximumHeight(150)

        # folder box
        self.fbox = QtWidgets.QComboBox(self)
        self.fbox.setFont(guiparts.smallfont)
        self.fbox.activated.connect(self.scan_folder)
        self.fbox.setMaximumHeight(selector_height)
        self.folder_default_key = '  [root datafolder]'
        self.fbox.addItem(self.folder_default_key)
        self.fbox.setCurrentIndex(0)
        Layout11.addWidget(self.fbox)

        # subject box
        self.sbox = QtWidgets.QComboBox(self)
        self.sbox.setFont(guiparts.smallfont)
        self.sbox.activated.connect(self.pick_subject)  # To be written !!
        self.sbox.setMaximumHeight(selector_height)
        self.subject_default_key = '  [subject] '
        self.sbox.addItem(self.subject_default_key)

        self.sbox.setCurrentIndex(0)
        Layout11.addWidget(self.sbox)

        # notes
        self.notes = QtWidgets.QLabel('\n[exp info]' + 5 * '\n', self)
        self.notes.setFont(guiparts.smallfont)
        self.notes.setMaximumHeight(60)
        Layout11.addWidget(self.notes)

        self.pbox = QtWidgets.QComboBox(self)
        self.pbox.setFont(guiparts.smallfont)
        self.pbox.activated.connect(self.display_quantities)
        self.pbox.setMaximumHeight(selector_height)
        self.pbox.addItem('[visualization/analysis]')
        self.pbox.addItem('-> Show Raw Data')
        self.pbox.addItem('-> Trial-average')
        self.pbox.addItem('-> draw figures')
        self.pbox.addItem('-> build PDF summary')
        self.pbox.addItem('-> open PDF summary')
        self.pbox.setCurrentIndex(0)

        Layout11.addWidget(self.pbox)

        Layout113 = QtWidgets.QHBoxLayout()
        Layout11.addLayout(Layout113)

        add_buttons(self, Layout113)

        Layout12 = QtWidgets.QVBoxLayout()
        Layout1.addLayout(Layout12)

        self.dbox = QtWidgets.QComboBox(self)
        self.dbox.setMinimumWidth(df_width)
        self.dbox.setMaximumWidth(win1_Wmax)
        self.dbox.setMinimumHeight(selector_height)
        self.dbox.setMaximumHeight(selector_height)
        self.dbox.activated.connect(self.pick_datafile)
        Layout12.addWidget(self.dbox)

        self.win1 = pg.GraphicsLayoutWidget()
        self.win1.setMaximumHeight(int(win1_Hmax - 1.5 * selector_height))
        Layout12.addWidget(self.win1)

        self.winTrace = pg.GraphicsLayoutWidget()
        mainLayout.addWidget(self.winTrace)

        guiparts.build_slider(self, mainLayout)

        self.init_panels()

        self.plot = self.winTrace.addPlot()
        self.plot.hideAxis('left')
        self.plot.setMouseEnabled(x=True, y=False)
        # self.plot.setMenuEnabled(False)
        self.plot.setLabel('bottom', 'time (s)')
        self.xaxis = self.plot.getAxis('bottom')
        self.scatter = pg.ScatterPlotItem()
        self.plot.addItem(self.scatter)

        Layout122 = QtWidgets.QHBoxLayout()
        Layout12.addLayout(Layout122)

        self.stimSelect = QtWidgets.QCheckBox("vis. stim")
        self.stimSelect.clicked.connect(self.select_stim)
        self.stimSelect.setStyleSheet('color: grey;')

        self.pupilSelect = QtWidgets.QCheckBox("pupil")
        self.pupilSelect.setStyleSheet('color: red;')

        self.gazeSelect = QtWidgets.QCheckBox("gaze")
        self.gazeSelect.setStyleSheet('color: orange;')

        self.faceMtnSelect = QtWidgets.QCheckBox("whisk.")
        self.faceMtnSelect.setStyleSheet('color: magenta;')

        self.runSelect = QtWidgets.QCheckBox("run")

        self.photodiodeSelect = QtWidgets.QCheckBox("photodiode")
        self.photodiodeSelect.setStyleSheet('color: grey;')

        self.ephysSelect = QtWidgets.QCheckBox("ephys")
        self.ephysSelect.setStyleSheet('color: blue;')

        self.ophysSelect = QtWidgets.QCheckBox("ophys")
        self.ophysSelect.setStyleSheet('color: green;')

        for x in [
                self.stimSelect, self.pupilSelect, self.gazeSelect,
                self.faceMtnSelect, self.runSelect, self.photodiodeSelect,
                self.ephysSelect, self.ophysSelect
        ]:
            x.setFont(guiparts.smallfont)
            Layout122.addWidget(x)

        self.roiPick = QtWidgets.QLineEdit()
        self.roiPick.setText(' [...] ')
        self.roiPick.setMinimumWidth(50)
        self.roiPick.setMaximumWidth(250)
        self.roiPick.returnPressed.connect(self.select_ROI)
        self.roiPick.setFont(guiparts.smallfont)

        self.ephysPick = QtWidgets.QLineEdit()
        self.ephysPick.setText(' ')
        # self.ephysPick.returnPressed.connect(self.select_ROI)
        self.ephysPick.setFont(guiparts.smallfont)

        self.guiKeywords = QtWidgets.QLineEdit()
        self.guiKeywords.setText('     [GUI keywords] ')
        # self.guiKeywords.setFixedWidth(200)
        self.guiKeywords.returnPressed.connect(self.keyword_update)
        self.guiKeywords.setFont(guiparts.smallfont)

        Layout122.addWidget(self.guiKeywords)
        # Layout122.addWidget(self.ephysPick)
        Layout122.addWidget(self.roiPick)

        self.subsamplingSelect = QtWidgets.QCheckBox("subsampl.")
        self.subsamplingSelect.setStyleSheet('color: grey;')
        self.subsamplingSelect.setFont(guiparts.smallfont)
        Layout122.addWidget(self.subsamplingSelect)

        self.annotSelect = QtWidgets.QCheckBox("annot.")
        self.annotSelect.setStyleSheet('color: grey;')
        self.annotSelect.setFont(guiparts.smallfont)
        Layout122.addWidget(self.annotSelect)

        self.imgSelect = QtWidgets.QCheckBox("img")
        self.imgSelect.setStyleSheet('color: grey;')
        self.imgSelect.setFont(guiparts.smallfont)
        self.imgSelect.setChecked(True)
        self.imgSelect.clicked.connect(self.remove_img)
        Layout122.addWidget(self.imgSelect)

        self.cwidget.setLayout(mainLayout)
        self.show()

        self.fbox.addItems(FOLDERS.keys())
        self.windowTA, self.windowBM = None, None  # sub-windows

        if args is not None:
            self.root_datafolder = args.root_datafolder
        else:
            self.root_datafolder = os.path.join(os.path.expanduser('~'),
                                                'DATA')

        self.time, self.data, self.roiIndices, self.tzoom = 0, None, [], [
            0, 50
        ]
        self.CaImaging_bg_key, self.planeID = 'meanImg', 0
        self.CaImaging_key = 'Fluorescence'

        self.FILES_PER_DAY, self.FILES_PER_SUBJECT, self.SUBJECTS = {}, {}, {}

        self.minView = False
        self.showwindow()

        if (args is not None) and hasattr(args, 'datafile') and os.path.isfile(
                args.datafile):
            self.datafile = args.datafile
            self.load_file(self.datafile)
            plots.raw_data_plot(self, self.tzoom)
コード例 #5
0
    def __init__(self, app,
                 args=None,
                 parent=None):
        """
        sampling in Hz
        """
        super(MainWindow, self).__init__()

        self.setGeometry(350, 680, 300, 350)
        # adding a "quit" keyboard shortcut
        self.quitSc = QtWidgets.QShortcut(QtGui.QKeySequence('Q'), self) # or 'Ctrl+Q'
        self.quitSc.activated.connect(self.quit)
            
        self.setWindowTitle('Adding Ca-Imaging')
        
        self.process_script = os.path.join(str(pathlib.Path(__file__).resolve().parents[1]),
                                           'assembling',  'add_ophys.py')

        HEIGHT = 0

        HEIGHT += 10
        QtWidgets.QLabel("Root Data:", self).move(10, HEIGHT)
        self.folderD = QtWidgets.QComboBox(self)
        self.folderD.setMinimumWidth(150)
        self.folderD.move(100, HEIGHT)
        self.folderD.activated.connect(self.update_setting)
        self.folderD.addItems(FOLDERS.keys())

        HEIGHT += 30
        QtWidgets.QLabel("Root Imaging:", self).move(10, HEIGHT)
        self.folderI = QtWidgets.QComboBox(self)
        self.folderI.setMinimumWidth(150)
        self.folderI.move(100, HEIGHT)
        self.folderI.activated.connect(self.update_setting)
        self.folderI.addItems(FOLDERS.keys())
        
        HEIGHT += 40
        self.load = QtWidgets.QPushButton('Load data \u2b07', self)
        self.load.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.load.clicked.connect(self.load_data)
        self.load.setMinimumWidth(200)
        self.load.move(50, HEIGHT)
        self.loadSc = QtWidgets.QShortcut(QtGui.QKeySequence('L'), self)
        self.loadSc.activated.connect(self.load_data)

        HEIGHT += 40
        self.load = QtWidgets.QPushButton('Load imaging \u2b07', self)
        self.load.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.load.clicked.connect(self.load_data)
        self.load.setMinimumWidth(200)
        self.load.move(50, HEIGHT)
        self.loadSc = QtWidgets.QShortcut(QtGui.QKeySequence('L'), self)
        self.loadSc.activated.connect(self.load_imaging)

        HEIGHT += 40
        self.find = QtWidgets.QPushButton('-* Find imaging *-', self)
        self.find.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.find.clicked.connect(self.find_imaging)
        self.find.setMinimumWidth(200)
        self.find.move(50, HEIGHT)

        HEIGHT += 30
        self.imagingF = QtWidgets.QLabel("...", self)
        self.imagingF.move(10, HEIGHT)
        self.imagingF.setMinimumWidth(400)
        
        HEIGHT += 40
        QtWidgets.QLabel("=> Setting :", self).move(10, HEIGHT)
        self.cbc = QtWidgets.QComboBox(self)
        self.cbc.setMinimumWidth(150)
        self.cbc.move(100, HEIGHT)
        self.cbc.activated.connect(self.update_setting)
        self.cbc.addItems(['standard', 'lightweight', 'full', 'NIdaq-only', 'custom'])

        HEIGHT +=30 
        s = QtWidgets.QLabel("CaImaging-Sampling (Hz)    ", self)
        s.move(10, HEIGHT)
        s.setMinimumWidth(200)
        self.PsamplingBox = QtWidgets.QLineEdit('', self)
        self.PsamplingBox.setText('0.0')
        self.PsamplingBox.setFixedWidth(40)
        self.PsamplingBox.move(200, HEIGHT)

        HEIGHT +=40 
        self.gen = QtWidgets.QPushButton('-=- Run -=-', self)
        self.gen.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.gen.clicked.connect(self.run)
        self.gen.setMinimumWidth(200)
        self.gen.move(50, HEIGHT)
        
        self.filename, self.Ifolder = '', ''
        self.show()
コード例 #6
0
    def __init__(self, app,
                 args=None,
                 parent=None,
                 spatial_subsampling=1,
                 time_subsampling=1):
        """
        FaceMotion GUI
        """
        self.app = app
        
        super(MainWindow, self).__init__(i=2,
                                         title='Face-motion/Whisking tracking')

        ##############################
        ##### keyboard shortcuts #####
        ##############################

        self.refc1 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+1'), self)
        self.refc1.activated.connect(self.set_cursor_1)
        self.refc2 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+2'), self)
        self.refc2.activated.connect(self.set_cursor_2)
        self.refc3 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+3'), self)
        self.refc3.activated.connect(self.interpolate_data)

        #############################
        ##### module quantities #####
        #############################
        
        # initializing to defaults/None:
        self.saturation = 255
        self.ROI, self.pupil = None, None
        self.times, self.imgfolder, self.nframes, self.FILES = None, None, None, None
        self.data, self.scatter, self.fit= None, None, None # the pupil size contour
        self.spatial_subsampling = spatial_subsampling
        self.time_subsampling = time_subsampling
        self.process_script = os.path.join(str(pathlib.Path(__file__).resolve().parents[0]),
                                           'process.py') # for batch processing -> execute this script
        
        ########################
        ##### building GUI #####
        ########################
        
        self.minView = False
        self.showwindow()

        # central widget
        self.cwidget = QtWidgets.QWidget(self)
        self.setCentralWidget(self.cwidget)
        # layout
        self.l0 = QtWidgets.QGridLayout()
        self.cwidget.setLayout(self.l0)
        self.win = pg.GraphicsLayoutWidget()
        self.win.move(600,0)
        self.win.resize(600,400)
        self.l0.addWidget(self.win,1,3,37,15)
        layout = self.win.ci.layout

        # A plot area (ViewBox + axes) for displaying the image
        self.p0 = self.win.addViewBox(lockAspect=False,row=0,col=0,invertY=True,
                                      border=[100,100,100])
        self.p0.setMouseEnabled(x=False,y=False)
        self.p0.setMenuEnabled(False)
        self.pimg = pg.ImageItem()
        self.p0.setAspectLocked()
        self.p0.addItem(self.pimg)

        # image ROI
        self.pFace = self.win.addViewBox(lockAspect=False,row=0,col=1,invertY=True,
                                         border=[100,100,100])
        self.pFace.setAspectLocked()
        self.pFace.setMenuEnabled(False)
        self.pFaceimg = pg.ImageItem(None)
        self.pFace.addItem(self.pFaceimg)

        # saturation sliders
        self.sl = Slider(0, self)
        self.l0.addWidget(self.sl,1,6,1,7)
        qlabel= QtWidgets.QLabel('saturation')
        qlabel.setStyleSheet('color: white;')
        self.l0.addWidget(qlabel, 0,8,1,3)

        # reset
        self.reset_btn = QtWidgets.QPushButton('reset')
        self.l0.addWidget(self.reset_btn, 1, 11+6, 1, 1)
        self.reset_btn.clicked.connect(self.reset)
        self.reset_btn.setEnabled(True)

        # debug
        self.debugBtn = QtWidgets.QPushButton('- Debug -')
        self.l0.addWidget(self.debugBtn, 2, 11+6, 1, 1)
        self.debugBtn.setEnabled(True)
        self.debugBtn.clicked.connect(self.debug)

        
        self.p1 = self.win.addPlot(name='plot1',row=1,col=0, colspan=2, rowspan=4,
                                   title='*face motion*')
        self.p1.setMouseEnabled(x=True,y=False)
        self.p1.setMenuEnabled(False)
        self.p1.hideAxis('left')
        self.scatter = pg.ScatterPlotItem()
        self.p1.addItem(self.scatter)
        self.p1.setLabel('bottom', 'time (frame #)')
        self.xaxis = self.p1.getAxis('bottom')
        self.p1.autoRange(padding=0.01)

        self.win.ci.layout.setRowStretchFactor(0,5)
        self.movieLabel = QtWidgets.QLabel("No datafile chosen")
        self.movieLabel.setStyleSheet("color: white;")
        self.l0.addWidget(self.movieLabel,0,1,1,5)

        # create frame slider
        self.timeLabel = QtWidgets.QLabel("time : ")
        self.timeLabel.setStyleSheet("color: white;")
        # self.timeLabel.setFixedWidth(300)
        self.currentTime = QtWidgets.QLineEdit()
        self.currentTime.setText('0 s')
        self.currentTime.setFixedWidth(70)
        # self.currentTime.returnPressed.connect(self.set_precise_time)
        
        self.frameSlider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.frameSlider.setMinimum(0)
        self.frameSlider.setMaximum(200)
        self.frameSlider.setTickInterval(1)
        self.frameSlider.setTracking(False)
        self.frameSlider.valueChanged.connect(self.go_to_frame)

        istretch = 23
        iplay = istretch+15
        iconSize = QtCore.QSize(20, 20)

        self.folderB = QtWidgets.QComboBox(self)
        self.folderB.setMinimumWidth(150)
        self.folderB.addItems(FOLDERS.keys())
        
        self.processBtn = QtWidgets.QPushButton('process data [Ctrl+P]')
        self.processBtn.clicked.connect(self.process)

        self.interpolate = QtGui.QPushButton('interpolate')
        self.interpolate.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.interpolate.clicked.connect(self.interpolate_data)

        self.motionCheckBox = QtWidgets.QCheckBox("display motion frames")
        self.motionCheckBox.setStyleSheet("color: gray;")
        
        self.runAsSubprocess = QtWidgets.QPushButton('run as subprocess')
        self.runAsSubprocess.clicked.connect(self.run_as_subprocess)

        self.load = QtWidgets.QPushButton('  load data [Ctrl+O]  \u2b07')
        self.load.clicked.connect(self.open_file)

        sampLabel1 = QtWidgets.QLabel("spatial subsampling")
        sampLabel1.setStyleSheet("color: gray;")
        sampLabel1.setFixedWidth(220)
        self.SsamplingBox = QtWidgets.QLineEdit()
        self.SsamplingBox.setText(str(self.spatial_subsampling))
        self.SsamplingBox.setFixedWidth(30)

        sampLabel2 = QtWidgets.QLabel("temporal subsampling")
        sampLabel2.setStyleSheet("color: gray;")
        sampLabel2.setFixedWidth(220)
        self.TsamplingBox = QtWidgets.QLineEdit()
        self.TsamplingBox.setText(str(self.time_subsampling))
        self.TsamplingBox.setFixedWidth(30)
        
        self.loadLastGUIsettings = QtWidgets.QPushButton("last GUI settings")
        self.loadLastGUIsettings.clicked.connect(self.load_last_gui_settings)
        
        self.addROI = QtWidgets.QPushButton("set ROI")
        self.addROI.clicked.connect(self.add_ROI)

        self.saveData = QtWidgets.QPushButton('save data [Ctrl+S]')
        self.saveData.clicked.connect(self.save_data)

        sampLabel3 = QtWidgets.QLabel("grooming threshold")
        sampLabel3.setStyleSheet("color: gray;")
        sampLabel3.setFixedWidth(220)
        self.groomingBox = QtWidgets.QLineEdit()
        self.groomingBox.setText('-1')
        self.groomingBox.setFixedWidth(40)
        self.groomingBox.returnPressed.connect(self.update_grooming_threshold)

        self.processGrooming = QtWidgets.QPushButton("process grooming")
        self.processGrooming.clicked.connect(self.process_grooming)
        
        for x in [self.processBtn, self.motionCheckBox, self.runAsSubprocess,
                  self.load, self.addROI, self.saveData, self.TsamplingBox,
                  self.SsamplingBox, self.groomingBox, self.processGrooming]:
            x.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        
        iconSize = QtCore.QSize(30, 30)
        self.playButton = QtWidgets.QToolButton()
        self.playButton.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay))
        self.playButton.setIconSize(iconSize)
        self.playButton.setToolTip("Play")
        self.playButton.setCheckable(True)
        self.pauseButton = QtWidgets.QToolButton()
        self.pauseButton.setCheckable(True)
        self.pauseButton.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPause))
        self.pauseButton.setIconSize(iconSize)
        self.pauseButton.setToolTip("Pause")

        btns = QtWidgets.QButtonGroup(self)
        btns.addButton(self.playButton,0)
        btns.addButton(self.pauseButton,1)

        for wdg, loc in zip([self.load,self.folderB,
                             sampLabel1, sampLabel2,
                             self.loadLastGUIsettings, self.addROI, self.saveData,
                             sampLabel3, self.processGrooming,
                             self.motionCheckBox, self.processBtn, self.runAsSubprocess,
                             self.timeLabel],
                            [1,2,
                             8,9,
                             11, 12,14,
                             25,26,
                             19,20,21,
                             istretch+13]):
            
            self.l0.addWidget(wdg,loc,0,1,3)

        self.l0.addWidget(self.SsamplingBox, 8, 2, 1, 3)
        self.l0.addWidget(self.TsamplingBox, 9, 2, 1, 3)
        self.l0.addWidget(self.groomingBox, 19, 2, 1, 3)
        
        self.l0.addWidget(QtWidgets.QLabel(''),istretch,0,1,3)
        self.l0.setRowStretch(istretch,1)
        self.l0.addWidget(self.currentTime, istretch+13,1,1,3)
        self.l0.addWidget(self.frameSlider, istretch+17,3,1,15)
        
        # self.l0.addWidget(QtWidgets.QLabel(''),17,2,1,1)
        # self.l0.setRowStretch(16,2)
        # # self.l0.addWidget(ll, istretch+3+k+1,0,1,4)
        self.timeLabel.setEnabled(True)
        self.frameSlider.setEnabled(True)
        
        self.nframes = 0
        self.cframe = 0
        self.grooming_threshold = -1

        self.show()
コード例 #7
0
    def __init__(self, app,
                 args=None,
                 parent=None,
                 gaussian_smoothing=0,
                 cm_scale_px=570,
                 subsampling=1000):
        """
        sampling in Hz
        """
        self.app = app
        
        super(MainWindow, self).__init__()

        self.setGeometry(500,150,400,400)

        self.process_script = os.path.join(str(pathlib.Path(__file__).resolve().parents[0]),'process.py')
        self.script = os.path.join(str(pathlib.Path(__file__).resolve().parents[1]), 'script.sh') # for batch processing

        # adding a "quit" keyboard shortcut
        self.quitSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'), self)
        self.quitSc.activated.connect(self.quit)
        self.maxSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+M'), self)
        self.maxSc.activated.connect(self.showwindow)
        self.fitSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+F'), self)
        self.fitSc.activated.connect(self.fit_pupil_size)
        self.loadSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+O'), self)
        self.loadSc.activated.connect(self.load_data)
        self.refSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+R'), self)
        self.refSc.activated.connect(self.jump_to_frame)
        # self.refEx = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+E'), self)
        # self.refEx.activated.connect(self.exclude_outlier)
        self.refPr = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+P'), self)
        self.refPr.activated.connect(self.process_ROIs)
        self.refS = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+S'), self)
        self.refS.activated.connect(self.save_pupil_data)
        self.refc1 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+1'), self)
        self.refc1.activated.connect(self.set_cursor_1)
        self.refc2 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+2'), self)
        self.refc2.activated.connect(self.set_cursor_2)
        self.refc3 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+3'), self)
        self.refc3.activated.connect(self.process_outliers)

        self.add2Bash = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+B'), self)
        self.add2Bash.activated.connect(self.add_to_bash_script)
        
        self.minView = False
        self.showwindow()
        
        pg.setConfigOptions(imageAxisOrder='row-major')
        
        self.gaussian_smoothing = gaussian_smoothing
        self.subsampling = subsampling
        self.cm_scale_px = cm_scale_px
        
        self.cwidget = QtGui.QWidget(self)
        self.setCentralWidget(self.cwidget)
        self.l0 = QtGui.QGridLayout()
        self.cwidget.setLayout(self.l0)
        self.win = pg.GraphicsLayoutWidget()
        self.win.move(600,0)
        self.win.resize(600,400)
        self.l0.addWidget(self.win,1,3,37,15)
        layout = self.win.ci.layout

        # A plot area (ViewBox + axes) for displaying the image
        self.p0 = self.win.addViewBox(lockAspect=False,
                                      row=0,col=0,#border=[100,100,100],
                                      invertY=True)

        self.p0.setMouseEnabled(x=False,y=False)
        self.p0.setMenuEnabled(False)
        self.pimg = pg.ImageItem()
        self.p0.setAspectLocked()
        self.p0.addItem(self.pimg)

        # image ROI
        self.pPupil = self.win.addViewBox(lockAspect=True,#row=0,col=1,
                                          # border=[100,100,100],
                                          invertY=True)
        #self.p0.setMouseEnabled(x=False,y=False)
        self.pPupil.setMenuEnabled(False)
        self.pPupilimg = pg.ImageItem(None)
        self.pPupil.addItem(self.pPupilimg)
        self.pupilContour = pg.ScatterPlotItem()
        self.pPupil.addItem(self.pupilContour)
        self.pupilCenter = pg.ScatterPlotItem()
        self.pPupil.addItem(self.pupilCenter)

        # roi initializations
        self.iROI = 0
        self.nROIs = 0
        self.saturation = 255
        self.ROI = None
        self.pupil = None
        self.iframes, self.times, self.Pr1, self.Pr2 = [], [], [], []

        # saturation sliders
        self.sl = guiparts.Slider(0, self)
        self.l0.addWidget(self.sl,1,6,1,7)
        qlabel= QtGui.QLabel('saturation')
        qlabel.setStyleSheet('color: white;')
        self.l0.addWidget(qlabel, 0,8,1,3)

        # adding blanks ("corneal reflections, ...")
        self.reflector = QtGui.QPushButton('add blank')
        self.l0.addWidget(self.reflector, 1, 8+6, 1, 1)
        # self.reflector.setEnabled(True)
        self.reflector.clicked.connect(self.add_reflectROI)
        # fit pupil
        self.fit_pupil = QtGui.QPushButton('fit Pupil [Ctrl+F]')
        self.l0.addWidget(self.fit_pupil, 1, 9+6, 1, 1)
        # self.fit_pupil.setEnabled(True)
        self.fit_pupil.clicked.connect(self.fit_pupil_size)
        # choose pupil shape
        self.pupil_shape = QtGui.QComboBox(self)
        self.pupil_shape.addItem("Ellipse fit")
        self.pupil_shape.addItem("Circle fit")
        self.l0.addWidget(self.pupil_shape, 1, 10+6, 1, 1)
        # reset
        self.reset_btn = QtGui.QPushButton('reset')
        self.l0.addWidget(self.reset_btn, 1, 11+6, 1, 1)
        self.reset_btn.clicked.connect(self.reset)
        # self.reset_btn.setEnabled(True)
        # draw pupil
        self.refresh_pupil = QtGui.QPushButton('Refresh [Ctrl+R]')
        self.l0.addWidget(self.refresh_pupil, 2, 11+6, 1, 1)
        self.refresh_pupil.setEnabled(True)
        self.refresh_pupil.clicked.connect(self.jump_to_frame)

        self.data = None
        self.rROI= []
        self.reflectors=[]
        self.scatter, self.fit= None, None # the pupil size contour

        self.p1 = self.win.addPlot(name='plot1',row=1,col=0, colspan=2, rowspan=4,
                                   title='Pupil diameter')
        self.p1.setMouseEnabled(x=True,y=False)
        self.p1.setMenuEnabled(False)
        self.p1.hideAxis('left')
        self.scatter = pg.ScatterPlotItem()
        self.p1.addItem(self.scatter)
        self.p1.setLabel('bottom', 'time (frame #)')
        self.xaxis = self.p1.getAxis('bottom')
        self.p1.autoRange(padding=0.01)
        
        self.win.ci.layout.setRowStretchFactor(0,5)
        self.movieLabel = QtGui.QLabel("No datafile chosen")
        self.movieLabel.setStyleSheet("color: white;")
        self.l0.addWidget(self.movieLabel,0,1,1,5)


        # create frame slider
        self.timeLabel = QtGui.QLabel("Current time (seconds):")
        self.timeLabel.setStyleSheet("color: white;")
        self.currentTime = QtGui.QLineEdit()
        self.currentTime.setText('0')
        self.currentTime.setValidator(QtGui.QDoubleValidator(0, 100000, 2))
        self.currentTime.setFixedWidth(50)
        self.currentTime.returnPressed.connect(self.set_precise_time)
        
        self.frameSlider = QtGui.QSlider(QtCore.Qt.Horizontal)
        self.frameSlider.setMinimum(0)
        self.frameSlider.setMaximum(200)
        self.frameSlider.setTickInterval(1)
        self.frameSlider.setTracking(False)
        self.frameSlider.valueChanged.connect(self.go_to_frame)

        istretch = 23
        iplay = istretch+15
        iconSize = QtCore.QSize(20, 20)

        self.folderB = QtWidgets.QComboBox(self)
        self.folderB.setMinimumWidth(150)
        self.folderB.addItems(FOLDERS.keys())

        self.process = QtGui.QPushButton('process data [Ctrl+P]')
        self.process.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.process.clicked.connect(self.process_ROIs)

        self.cursor1 = QtGui.QPushButton('Set Cursor 1 [Ctrl+1]')
        self.cursor1.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.cursor1.clicked.connect(self.set_cursor_1)

        self.cursor2 = QtGui.QPushButton('Set Cursor 2 [Ctrl+2]')
        self.cursor2.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.cursor2.clicked.connect(self.set_cursor_2)
        
        self.runAsSubprocess = QtGui.QPushButton('run as subprocess')
        self.runAsSubprocess.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.runAsSubprocess.clicked.connect(self.run_as_subprocess)

        self.load = QtGui.QPushButton('  load data [Ctrl+O]  \u2b07')
        self.load.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.load.clicked.connect(self.load_data)

        sampLabel = QtGui.QLabel("Subsampling (frame)")
        sampLabel.setStyleSheet("color: gray;")
        self.samplingBox = QtGui.QLineEdit()
        self.samplingBox.setText(str(self.subsampling))
        self.samplingBox.setFixedWidth(50)

        smoothLabel = QtGui.QLabel("Smoothing (px)")
        smoothLabel.setStyleSheet("color: gray;")
        self.smoothBox = QtGui.QLineEdit()
        self.smoothBox.setText(str(self.gaussian_smoothing))
        self.smoothBox.setFixedWidth(30)

        scaleLabel = QtGui.QLabel("1cm = (px)")
        scaleLabel.setStyleSheet("color: gray;")
        self.scaleBox = QtGui.QLineEdit()
        self.scaleBox.setText(str(self.cm_scale_px))
        self.scaleBox.setFixedWidth(30)

        self.addROI = QtGui.QPushButton("add Pupil-ROI")
        self.addROI.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.addROI.clicked.connect(self.add_ROI)

        self.saverois = QtGui.QPushButton('save data [Ctrl+S]')
        self.saverois.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.saverois.clicked.connect(self.save_ROIs)

        # self.addOutlier = QtGui.QPushButton('exclude outlier [Ctrl+E]')
        # self.addOutlier.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        # self.addOutlier.clicked.connect(self.exclude_outlier)

        self.processOutliers = QtGui.QPushButton('Set blinking interval')
        self.processOutliers.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.processOutliers.clicked.connect(self.process_outliers)

        self.printSize = QtGui.QPushButton('print ROI size')
        self.printSize.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.printSize.clicked.connect(self.print_size)
        
        iconSize = QtCore.QSize(30, 30)
        self.playButton = QtGui.QToolButton()
        self.playButton.setIcon(self.style().standardIcon(QtGui.QStyle.SP_MediaPlay))
        self.playButton.setIconSize(iconSize)
        self.playButton.setToolTip("Play")
        self.playButton.setCheckable(True)
        self.pauseButton = QtGui.QToolButton()
        self.pauseButton.setCheckable(True)
        self.pauseButton.setIcon(self.style().standardIcon(QtGui.QStyle.SP_MediaPause))
        self.pauseButton.setIconSize(iconSize)
        self.pauseButton.setToolTip("Pause")

        btns = QtGui.QButtonGroup(self)
        btns.addButton(self.playButton,0)
        btns.addButton(self.pauseButton,1)

        self.l0.addWidget(self.folderB,1,0,1,3)
        self.l0.addWidget(self.load,2,0,1,3)
        self.l0.addWidget(sampLabel, 8, 0, 1, 3)
        self.l0.addWidget(self.samplingBox, 8, 2, 1, 3)
        self.l0.addWidget(smoothLabel, 9, 0, 1, 3)
        self.l0.addWidget(self.smoothBox, 9, 2, 1, 3)
        self.l0.addWidget(scaleLabel, 10, 0, 1, 3)
        self.l0.addWidget(self.scaleBox, 10, 2, 1, 3)
        self.l0.addWidget(self.addROI,14,0,1,3)
        self.l0.addWidget(self.process, 16, 0, 1, 3)
        self.l0.addWidget(self.runAsSubprocess, 17, 0, 1, 3)
        self.l0.addWidget(self.saverois, 19, 0, 1, 3)
        self.l0.addWidget(self.cursor1, 23, 0, 1, 3)
        self.l0.addWidget(self.cursor2, 24, 0, 1, 3)
        self.l0.addWidget(self.processOutliers, 25, 0, 1, 3)
        self.l0.addWidget(self.printSize, 26, 0, 1, 3)

        self.l0.addWidget(QtGui.QLabel(''),istretch,0,1,3)
        self.l0.setRowStretch(istretch,1)
        self.l0.addWidget(self.timeLabel, istretch+13,0,1,3)
        self.l0.addWidget(self.currentTime, istretch+14,0,1,3)
        self.l0.addWidget(self.frameSlider, istretch+15,3,1,15)

        self.l0.addWidget(QtGui.QLabel(''),17,2,1,1)
        self.l0.setRowStretch(16,2)
        # self.l0.addWidget(ll, istretch+3+k+1,0,1,4)
        self.updateFrameSlider()
        
        self.nframes = 0
        self.cframe, self.cframe1, self.cframe2, = 0, 0, 0

        self.updateTimer = QtCore.QTimer()
        
        self.win.show()
        self.show()
        self.processed = False

        # self.datafile = args.datafile
        self.show()
コード例 #8
0
ファイル: guiPP.py プロジェクト: yzerlaut/physion
    def __init__(self, app,
                 args=None,
                 parent=None):
        """
        sampling in Hz
        """
        super(MainWindow, self).__init__()

        self.setGeometry(350, 470, 300, 260)
        # adding a "quit" and "load" keyboard shortcuts
        self.quitSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'), self)
        self.quitSc.activated.connect(self.quit)
        self.loadSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+O'), self)
        self.loadSc.activated.connect(self.load_imaging)
            
        self.setWindowTitle('Ca-Preprocessing')
        
        self.process_script = os.path.join(str(pathlib.Path(__file__).resolve().parents[1]),
                                           'Ca_imaging',  'preprocessing.py')

        HEIGHT = 0

        HEIGHT += 10
        QtWidgets.QLabel("Root Folder:", self).move(10, HEIGHT)
        self.folderI = QtWidgets.QComboBox(self)
        self.folderI.setMinimumWidth(150)
        self.folderI.move(100, HEIGHT)
        self.folderI.activated.connect(self.update_setting)
        self.folderI.addItems(FOLDERS.keys())
        
        HEIGHT += 40
        self.load = QtWidgets.QPushButton('Upload (set of) TSeries \u2b07', self)
        self.load.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.load.clicked.connect(self.load_imaging)
        self.load.setMinimumWidth(200)
        self.load.move(50, HEIGHT)

        HEIGHT += 40
        QtWidgets.QLabel("=> Setting :", self).move(10, HEIGHT)
        self.cbc = QtWidgets.QComboBox(self)
        self.cbc.setMinimumWidth(150)
        self.cbc.move(100, HEIGHT)
        self.cbc.activated.connect(self.update_setting)
        self.cbc.addItems(list(PREPROCESSING_SETTINGS.keys()))

        HEIGHT += 40
        QtWidgets.QLabel("   delay ?", self).move(10, HEIGHT)
        self.delayBox = QtWidgets.QComboBox(self)
        self.delayBox.setMinimumWidth(150)
        self.delayBox.move(100, HEIGHT)
        self.delayBox.addItems(['None', '10min', '1h', '2h', '10h', '20h'])
        
        HEIGHT +=40 
        self.gen = QtWidgets.QPushButton('-=- Run -=-', self)
        self.gen.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.gen.clicked.connect(self.run)
        self.gen.setMinimumWidth(200)
        self.gen.move(50, HEIGHT)
        
        HEIGHT +=40 
        self.gen = QtWidgets.QPushButton(' open Suite2p ', self)
        self.gen.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.gen.clicked.connect(self.open_suite2p)
        self.gen.setMinimumWidth(200)
        self.gen.move(50, HEIGHT)
        
        self.CMDS = []
        self.show()
コード例 #9
0
    def __init__(self,
                 app,
                 args=None,
                 parent=None,
                 gaussian_smoothing=1,
                 cm_scale_px=570,
                 subsampling=1000):
        """
        Cell Identification GUI for Z-stacks Imaging
        """
        self.app = app

        super(MainWindow, self).__init__(
            i=-2,
            size=(1000, 800),
            title='Cell Identification GUI for Z-stacks Imaging')

        ##############################
        ##### keyboard shortcuts #####
        ##############################

        self.refc1 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+N'), self)
        self.refc1.activated.connect(self.next_frames)
        self.refc2 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+B'), self)
        self.refc2.activated.connect(self.previous_frames)
        self.refc3 = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+C'), self)
        self.refc3.activated.connect(self.new_ROI)

        #############################
        ##### module quantities #####
        #############################

        self.ROIS = []

        ########################
        ##### building GUI #####
        ########################

        self.cwidget = QtGui.QWidget(self)
        self.setCentralWidget(self.cwidget)
        self.grid = QtGui.QGridLayout()

        self.folderB = QtWidgets.QComboBox(self)
        self.folderB.setMinimumWidth(150)
        self.folderB.addItems(FOLDERS.keys())
        self.grid.addWidget(self.folderB, 1, 1, 1, 1)

        self.load = QtGui.QPushButton('  load data [Ctrl+O]  \u2b07')
        self.load.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        self.load.clicked.connect(self.open_file)
        self.grid.addWidget(self.load, 1, 2, 1, 1)

        self.channelB = QtWidgets.QComboBox(self)
        self.channelB.addItems(['Ch2', 'Ch1'])
        self.grid.addWidget(self.channelB, 1, 3, 1, 1)

        self.grid.addWidget(QtGui.QLabel("sampling (frame):"), 1, 4, 1, 1)
        self.samplingB = QtWidgets.QComboBox(self)
        self.samplingB.addItems(['1', '2', '3', '5', '7', '10'])
        self.grid.addWidget(self.samplingB, 1, 5, 1, 1)

        self.depth = QtGui.QLineEdit()
        self.depth.setText("depth= %.1f um" % 0)
        self.grid.addWidget(self.depth, 1, 6, 1, 2)

        self.grid.addWidget(QtGui.QLabel("cell-range (um):"), 1, 8, 1, 1)
        self.cellRange = QtWidgets.QComboBox(self)
        self.cellRange.addItems(['1', '10', '20', '50', '100', '1000'])
        self.cellRange.setCurrentIndex(2)
        self.grid.addWidget(self.cellRange, 1, 9, 1, 1)

        self.newRoiBtn = QtGui.QPushButton('new Cell [Ctrl+C]')
        self.newRoiBtn.clicked.connect(self.new_ROI)
        self.grid.addWidget(self.newRoiBtn, 2, 1, 1, 1)

        self.showCells = QtGui.QCheckBox("show cells")
        self.showCells.clicked.connect(self.display_frames)
        self.grid.addWidget(self.showCells, 2, 2, 1, 2)

        self.prevBtn = QtGui.QPushButton('next frames [Ctrl+N]')
        self.prevBtn.clicked.connect(self.next_frames)
        self.grid.addWidget(self.prevBtn, 2, 4, 1, 1)

        self.nextBtn = QtGui.QPushButton('prev. frames [Ctrl+P]')
        self.nextBtn.clicked.connect(self.previous_frames)
        self.grid.addWidget(self.nextBtn, 2, 5, 1, 1)

        self.saveCellsBtn = QtGui.QPushButton('save cells')
        self.saveCellsBtn.clicked.connect(self.save_cells)
        self.grid.addWidget(self.saveCellsBtn, 2, 7, 1, 1)

        self.threeDBtn = QtGui.QPushButton('show 3D view')
        self.threeDBtn.clicked.connect(self.show_3d_view)
        self.grid.addWidget(self.threeDBtn, 2, 8, 1, 1)

        self.resetBtn = QtGui.QPushButton('reset')
        self.resetBtn.clicked.connect(self.reset)
        self.grid.addWidget(self.resetBtn, 2, 10, 1, 1)

        self.cwidget.setLayout(self.grid)
        self.win = pg.GraphicsLayoutWidget()
        self.grid.addWidget(self.win, 3, 1, 10, 10)
        layout = self.win.ci.layout

        # for i, key in enumerate(['pPrev', 'Prev', 'Center', 'Next', 'nNext']):
        for i, key in enumerate(['Center']):
            # A plot area (ViewBox + axes) for displaying the image
            setattr(
                self, 'view_%s' % key,
                self.win.addViewBox(lockAspect=True,
                                    row=0,
                                    col=i,
                                    border=[10, 10, 10],
                                    invertY=True))
            setattr(self, 'img_%s' % key, pg.ImageItem())
            getattr(self,
                    'view_%s' % key).addItem(getattr(self, 'img_%s' % key))

        if hasattr(args, 'folder'):
            self.load_data(args.folder)

        self.win.show()
        self.show()
コード例 #10
0
    def __init__(self, app, args=None, parent=None):
        """
        Intrinsic Imaging Analysis GUI
        """
        self.app = app

        super(AnalysisWindow,
              self).__init__(i=2, title='intrinsic imaging analysis')

        self.datafolder, self.img, self.vasculature_img = '', None, None

        if args is not None:
            self.datafolder = args.datafile
        else:
            self.datafolder = ''

        ########################
        ##### building GUI #####
        ########################

        self.minView = False
        self.showwindow()

        # layout (from NewWindow class)
        self.init_basic_widget_grid(wdgt_length=3, Ncol_wdgt=23, Nrow_wdgt=20)

        # --- ROW (Nx_wdgt), COLUMN (Ny_wdgt)
        self.add_widget(QtWidgets.QLabel('data folder:'), spec='small-left')
        self.folderB = QtWidgets.QComboBox(self)
        self.folderB.addItems(FOLDERS.keys())
        self.add_widget(self.folderB, spec='large-right')

        self.raw_trace = self.graphics_layout.addPlot(row=0,
                                                      col=0,
                                                      rowspan=1,
                                                      colspan=23)

        self.spectrum_power = self.graphics_layout.addPlot(row=1,
                                                           col=0,
                                                           rowspan=2,
                                                           colspan=9)
        self.spDot = pg.ScatterPlotItem()
        self.spectrum_power.addItem(self.spDot)

        self.spectrum_phase = self.graphics_layout.addPlot(row=1,
                                                           col=9,
                                                           rowspan=2,
                                                           colspan=9)
        self.sphDot = pg.ScatterPlotItem()
        self.spectrum_phase.addItem(self.sphDot)

        # images
        self.img1B = self.graphics_layout.addViewBox(row=3,
                                                     col=0,
                                                     rowspan=10,
                                                     colspan=10,
                                                     lockAspect=True,
                                                     invertY=True)
        self.img1 = pg.ImageItem()
        self.img1B.addItem(self.img1)

        self.img2B = self.graphics_layout.addViewBox(row=3,
                                                     col=10,
                                                     rowspan=10,
                                                     colspan=9,
                                                     lockAspect=True,
                                                     invertY=True)
        self.img2 = pg.ImageItem()
        self.img2B.addItem(self.img2)

        self.img = np.random.randn(30, 30)
        self.img1.setImage(self.img)
        self.img2.setImage(self.img)

        for i in range(3):
            self.graphics_layout.ci.layout.setColumnStretchFactor(i, 1)
        self.graphics_layout.ci.layout.setColumnStretchFactor(3, 2)
        self.graphics_layout.ci.layout.setColumnStretchFactor(12, 2)
        self.graphics_layout.ci.layout.setRowStretchFactor(0, 3)
        self.graphics_layout.ci.layout.setRowStretchFactor(1, 4)
        self.graphics_layout.ci.layout.setRowStretchFactor(3, 5)

        self.folderButton = QtWidgets.QPushButton("load data [Ctrl+O]", self)
        self.folderButton.clicked.connect(self.open_file)
        self.add_widget(self.folderButton, spec='large-left')
        self.lastBox = QtWidgets.QCheckBox("last ")
        self.lastBox.setStyleSheet("color: gray;")
        self.add_widget(self.lastBox, spec='small-right')
        self.lastBox.setChecked((self.datafolder == ''))

        self.add_widget(QtWidgets.QLabel(' '))
        self.vdButton = QtWidgets.QPushButton("vasc. img", self)
        self.vdButton.clicked.connect(self.show_vasc_pic)
        self.add_widget(self.vdButton, 'small-left')
        self.rdButton = QtWidgets.QPushButton(" === show raw data === ", self)
        self.rdButton.clicked.connect(self.show_raw_data)
        self.add_widget(self.rdButton, 'large-right')
        self.add_widget(QtWidgets.QLabel('  - high pass filtering:'),
                        spec='large-left')
        self.hpBox = QtWidgets.QLineEdit()
        self.hpBox.setText('0')
        self.add_widget(self.hpBox, spec='small-right')
        self.add_widget(QtWidgets.QLabel('  - protocol:'), spec='small-left')
        self.protocolBox = QtWidgets.QComboBox(self)
        self.protocolBox.addItems(['up', 'down', 'left', 'right'])
        self.add_widget(self.protocolBox, spec='small-middle')
        self.numBox = QtWidgets.QComboBox(self)
        self.numBox.addItems(['sum'] + [str(i) for i in range(1, 10)])
        self.add_widget(self.numBox, spec='small-right')
        self.pmButton = QtWidgets.QPushButton(" ==== compute phase maps ==== ",
                                              self)
        self.pmButton.clicked.connect(self.compute_phase_maps)
        self.add_widget(self.pmButton)

        self.add_widget(QtWidgets.QLabel('  - direction:'), spec='small-left')
        self.mapBox = QtWidgets.QComboBox(self)
        self.mapBox.addItems(['azimuth', 'altitude'])
        self.add_widget(self.mapBox, spec='small-middle')
        self.twoPiBox = QtWidgets.QCheckBox("[0,2pi]")
        self.twoPiBox.setStyleSheet("color: gray;")
        self.add_widget(self.twoPiBox, spec='small-right')

        self.rmButton = QtWidgets.QPushButton(
            " === compute retinotopic maps === ", self)
        self.rmButton.clicked.connect(self.compute_retinotopic_maps)
        self.add_widget(self.rmButton)

        # self.add_widget(QtWidgets.QLabel('  - spatial smoothing (px):'),
        #                 spec='large-left')
        # self.spatialSmoothingBox = QtWidgets.QLineEdit()
        # self.spatialSmoothingBox.setText('5')
        # self.add_widget(self.spatialSmoothingBox, spec='small-right')

        # self.add_widget(QtWidgets.QLabel('  - temporal smoothing (ms):'),
        #                 spec='large-left')
        # self.temporalSmoothingBox = QtWidgets.QLineEdit()
        # self.temporalSmoothingBox.setText('100')
        # self.add_widget(self.temporalSmoothingBox, spec='small-right')

        self.add_widget(QtWidgets.QLabel(' '))
        self.pasButton = QtWidgets.QPushButton(
            " == perform area segmentation == ", self)
        self.pasButton.clicked.connect(self.perform_area_segmentation)
        self.add_widget(self.pasButton)
        self.add_widget(QtWidgets.QLabel('  - display:'), spec='small-left')
        self.displayBox = QtWidgets.QComboBox(self)
        self.displayBox.addItems(['sign map', 'areas (+vasc.)'])
        self.add_widget(self.displayBox, spec='large-right')

        # === -- parameters for area segmentation -- ===

        # phaseMapFilterSigma
        self.add_widget(QtWidgets.QLabel('  - phaseMapFilterSigma:'),
                        spec='large-left')
        self.phaseMapFilterSigmaBox = QtWidgets.QLineEdit()
        self.phaseMapFilterSigmaBox.setText('1.0')
        self.phaseMapFilterSigmaBox.setToolTip(
            'The sigma value (in pixels) of Gaussian filter for altitude and azimuth maps.\n FLOAT, default = 1.0, recommended range: [0.0, 2.0].\n Large "phaseMapFilterSigma" gives you more patches.\n Small "phaseMapFilterSigma" gives you less patches.'
        )
        self.add_widget(self.phaseMapFilterSigmaBox, spec='small-right')

        # signMapFilterSigma
        self.add_widget(QtWidgets.QLabel('  - signMapFilterSigma:'),
                        spec='large-left')
        self.signMapFilterSigmaBox = QtWidgets.QLineEdit()
        self.signMapFilterSigmaBox.setText('9.0')
        self.signMapFilterSigmaBox.setToolTip(
            'The sigma value (in pixels) of Gaussian filter for visual sign maps.\n FLOAT, default = 9.0, recommended range: [0.6, 10.0].\n Large "signMapFilterSigma" gives you less patches.\n Small "signMapFilterSigma" gives you more patches.'
        )
        self.add_widget(self.signMapFilterSigmaBox, spec='small-right')

        # signMapThr
        self.add_widget(QtWidgets.QLabel('  - signMapThr:'), spec='large-left')
        self.signMapThrBox = QtWidgets.QLineEdit()
        self.signMapThrBox.setText('0.35')
        self.signMapThrBox.setToolTip(
            'Threshold to binarize visual signmap.\n FLOAT, default = 0.35, recommended range: [0.2, 0.5], allowed range: [0, 1).\n Large signMapThr gives you fewer patches.\n Smaller signMapThr gives you more patches.'
        )
        self.add_widget(self.signMapThrBox, spec='small-right')

        self.add_widget(QtWidgets.QLabel('  - splitLocalMinCutStep:'),
                        spec='large-left')
        self.splitLocalMinCutStepBox = QtWidgets.QLineEdit()
        self.splitLocalMinCutStepBox.setText('5.0')
        self.splitLocalMinCutStepBox.setToolTip(
            'The step width for detecting number of local minimums during spliting. The local minimums detected will be used as marker in the following open cv watershed segmentation.\n FLOAT, default = 5.0, recommend range: [0.5, 15.0].\n Small "splitLocalMinCutStep" will make it more likely to split but into less sub patches.\n Large "splitLocalMinCutStep" will make it less likely to split but into more sub patches.'
        )
        self.add_widget(self.splitLocalMinCutStepBox, spec='small-right')

        # splitOverlapThr:
        self.add_widget(QtWidgets.QLabel('  - splitOverlapThr:'),
                        spec='large-left')
        self.splitOverlapThrBox = QtWidgets.QLineEdit()
        self.splitOverlapThrBox.setText('1.1')
        self.splitOverlapThrBox.setToolTip(
            'Patches with overlap ration larger than this value will go through the split procedure.\n FLOAT, default = 1.1, recommend range: [1.0, 1.2], should be larger than 1.0.\n Small "splitOverlapThr" will split more patches.\n Large "splitOverlapThr" will split less patches.'
        )
        self.add_widget(self.splitOverlapThrBox, spec='small-right')

        # mergeOverlapThr:
        self.add_widget(QtWidgets.QLabel('  - mergeOverlapThr:'),
                        spec='large-left')
        self.mergeOverlapThrBox = QtWidgets.QLineEdit()
        self.mergeOverlapThrBox.setText('0.1')
        self.mergeOverlapThrBox.setToolTip(
            'Considering a patch pair (A and B) with same sign, A has visual coverage a deg2 and B has visual coverage b deg2 and the overlaping visual coverage between this pair is c deg2.\n Then if (c/a < "mergeOverlapThr") and (c/b < "mergeOverlapThr"), these two patches will be merged.\n FLOAT, default = 0.1, recommend range: [0.0, 0.2], should be smaller than 1.0.\n Small "mergeOverlapThr" will merge less patches.\n Large "mergeOverlapThr" will merge more patches.'
        )
        self.add_widget(self.mergeOverlapThrBox, spec='small-right')

        self.pixROI = pg.ROI((10, 10),
                             size=(10, 10),
                             pen=pg.mkPen((255, 0, 0, 255)),
                             rotatable=False,
                             resizable=False)
        self.img1B.addItem(self.pixROI)

        self.show()
コード例 #11
0
    def __init__(self,
                 app,
                 args=None,
                 parent=None,
                 spatial_subsampling=4,
                 time_subsampling=1):
        """
        Intrinsic Imaging GUI
        """
        self.app = app

        super(MainWindow, self).__init__(i=1, title='intrinsic imaging')

        # some initialisation
        self.running, self.stim, self.STIM = False, None, None
        self.datafolder, self.img, self.vasculature_img = '', None, None

        self.t0, self.period = 0, 1

        ### trying the camera
        try:
            # we initialize the camera
            self.bridge = Bridge()
            self.core = self.bridge.get_core()
            self.exposure = self.core.get_exposure()
            self.demo = False
            auto_shutter = self.core.get_property('Core', 'AutoShutter')
            self.core.set_property('Core', 'AutoShutter', 0)
        except BaseException as be:
            print(be)
            print('')
            print(' /!\ Problem with the Camera /!\ ')
            print('        --> no camera found ')
            print('')
            self.exposure = -1  # flag for no camera
            self.demo = True

        ########################
        ##### building GUI #####
        ########################

        self.minView = False
        self.showwindow()

        # layout (from NewWindow class)
        self.init_basic_widget_grid(wdgt_length=3, Ncol_wdgt=20, Nrow_wdgt=20)

        # -- A plot area (ViewBox + axes) for displaying the image ---
        self.view = self.graphics_layout.addViewBox(lockAspect=True,
                                                    invertY=True)
        self.view.setMenuEnabled(False)
        self.view.setAspectLocked()
        self.pimg = pg.ImageItem()

        # ---  setting subject information ---
        self.add_widget(QtWidgets.QLabel('subjects file:'))
        self.subjectFileBox = QtWidgets.QComboBox(self)
        self.subjectFileBox.addItems([
            f for f in os.listdir(subjects_path)[::-1] if f.endswith('.json')
        ])
        self.subjectFileBox.activated.connect(self.get_subject_list)
        self.add_widget(self.subjectFileBox)

        self.add_widget(QtWidgets.QLabel('subject:'))
        self.subjectBox = QtWidgets.QComboBox(self)
        self.get_subject_list()
        self.add_widget(self.subjectBox)

        self.add_widget(QtWidgets.QLabel(20 * ' - '))
        self.vascButton = QtWidgets.QPushButton(
            " - = save Vasculature Picture = - ", self)
        self.vascButton.clicked.connect(self.take_vasculature_picture)
        self.add_widget(self.vascButton)

        self.add_widget(QtWidgets.QLabel(20 * ' - '))

        # ---  data acquisition properties ---
        self.add_widget(QtWidgets.QLabel('data folder:'), spec='small-left')
        self.folderB = QtWidgets.QComboBox(self)
        self.folderB.addItems(FOLDERS.keys())
        self.add_widget(self.folderB, spec='large-right')

        self.add_widget(QtWidgets.QLabel('  - protocol:'), spec='small-left')
        self.protocolBox = QtWidgets.QComboBox(self)
        self.protocolBox.addItems(['ALL', 'up', 'down', 'left', 'right'])
        self.add_widget(self.protocolBox, spec='large-right')
        self.add_widget(
            QtWidgets.QLabel('  - exposure: %.0f ms (from Micro-Manager)' %
                             self.exposure))

        self.add_widget(QtWidgets.QLabel('  - Nrepeat :'), spec='large-left')
        self.repeatBox = QtWidgets.QLineEdit()
        self.repeatBox.setText('10')
        self.add_widget(self.repeatBox, spec='small-right')

        self.add_widget(QtWidgets.QLabel('  - stim. period (s):'),
                        spec='large-left')
        self.periodBox = QtWidgets.QLineEdit()
        self.periodBox.setText('10')
        self.add_widget(self.periodBox, spec='small-right')

        self.add_widget(QtWidgets.QLabel('  - bar size (degree):'),
                        spec='large-left')
        self.barBox = QtWidgets.QLineEdit()
        self.barBox.setText('6')
        self.add_widget(self.barBox, spec='small-right')

        self.add_widget(QtWidgets.QLabel('  - spatial sub-sampling (px):'),
                        spec='large-left')
        self.spatialBox = QtWidgets.QLineEdit()
        self.spatialBox.setText(str(spatial_subsampling))
        self.add_widget(self.spatialBox, spec='small-right')

        self.add_widget(QtWidgets.QLabel('  - acq. freq. (Hz):'),
                        spec='large-left')
        self.freqBox = QtWidgets.QLineEdit()
        self.freqBox.setText('10')
        self.add_widget(self.freqBox, spec='small-right')

        # self.add_widget(QtWidgets.QLabel('  - flick. freq. (Hz) /!\ > acq:'),
        #                 spec='large-left')
        # self.flickBox = QtWidgets.QLineEdit()
        # self.flickBox.setText('10')
        # self.add_widget(self.flickBox, spec='small-right')

        self.demoBox = QtWidgets.QCheckBox("demo mode")
        self.demoBox.setStyleSheet("color: gray;")
        self.add_widget(self.demoBox, spec='large-left')
        self.demoBox.setChecked(self.demo)

        self.camBox = QtWidgets.QCheckBox("cam.")
        self.camBox.setStyleSheet("color: gray;")
        self.add_widget(self.camBox, spec='small-right')
        self.camBox.setChecked(True)

        # ---  launching acquisition ---
        self.liveButton = QtWidgets.QPushButton("--   live view    -- ", self)
        self.liveButton.clicked.connect(self.live_view)
        self.add_widget(self.liveButton)

        # ---  launching acquisition ---
        self.acqButton = QtWidgets.QPushButton("-- RUN PROTOCOL -- ", self)
        self.acqButton.clicked.connect(self.launch_protocol)
        self.add_widget(self.acqButton, spec='large-left')
        self.stopButton = QtWidgets.QPushButton(" STOP ", self)
        self.stopButton.clicked.connect(self.stop_protocol)
        self.add_widget(self.stopButton, spec='small-right')

        # ---  launching analysis ---
        self.add_widget(QtWidgets.QLabel(20 * ' - '))
        self.analysisButton = QtWidgets.QPushButton(" - = Analysis GUI = - ",
                                                    self)
        self.analysisButton.clicked.connect(self.open_analysis)
        self.add_widget(self.analysisButton, spec='large-left')

        self.pimg.setImage(0 * self.get_frame())
        self.view.addItem(self.pimg)
        self.view.autoRange(padding=0.001)
        self.analysisWindow = None
コード例 #12
0
ファイル: gui.py プロジェクト: marcelbvv/cortical-physio-icm
    def __init__(self, app,
                 args=None,
                 parent=None,
                 gaussian_smoothing=1,
                 subsampling=1000):
        """
        Pupil Tracking GUI
        """
        self.app = app
        
        super(MainWindow, self).__init__(i=1,
                                         title='Pupil tracking')


        ##############################
        ##### keyboard shortcuts #####
        ##############################

        self.refc1 = QtWidgets.QShortcut(QtGui.QKeySequence('1'), self)
        self.refc1.activated.connect(self.set_cursor_1)
        self.refc2 = QtWidgets.QShortcut(QtGui.QKeySequence('2'), self)
        self.refc2.activated.connect(self.set_cursor_2)
        self.refc3 = QtWidgets.QShortcut(QtGui.QKeySequence('3'), self)
        self.refc3.activated.connect(self.process_outliers)
        self.refc4 = QtWidgets.QShortcut(QtGui.QKeySequence('4'), self)
        self.refc4.activated.connect(self.interpolate)
        self.refc5 = QtWidgets.QShortcut(QtGui.QKeySequence('E'), self)
        self.refc5.activated.connect(self.find_outliers)
        
        #############################
        ##### module quantities #####
        #############################

        self.gaussian_smoothing = gaussian_smoothing
        self.subsampling = subsampling
        self.process_script = os.path.join(str(pathlib.Path(__file__).resolve().parents[0]),
                                           'process.py')
        self.ROI, self.pupil, self.times = None, None, None
        self.data = None
        self.bROI, self.reflectors = [], []
        self.scatter, self.fit= None, None # the pupil size contour
        
        ########################
        ##### building GUI #####
        ########################
        
        self.cwidget = QtWidgets.QWidget(self)
        self.setCentralWidget(self.cwidget)
        self.l0 = QtWidgets.QGridLayout()
        self.cwidget.setLayout(self.l0)
        self.win = pg.GraphicsLayoutWidget()
        self.win.move(600,0)
        self.win.resize(600,400)
        self.l0.addWidget(self.win,1,3,37,15)
        layout = self.win.ci.layout

        # A plot area (ViewBox + axes) for displaying the image
        self.p0 = self.win.addViewBox(lockAspect=False,
                                      row=0,col=0,#border=[100,100,100],
                                      invertY=True)

        self.p0.setMouseEnabled(x=False,y=False)
        self.p0.setMenuEnabled(False)
        self.pimg = pg.ImageItem()
        self.p0.setAspectLocked()
        self.p0.addItem(self.pimg)

        # image ROI
        self.pPupil = self.win.addViewBox(lockAspect=True,#row=0,col=1,
                                          # border=[100,100,100],
                                          invertY=True)
        #self.p0.setMouseEnabled(x=False,y=False)
        self.pPupil.setMenuEnabled(False)
        self.pPupilimg = pg.ImageItem(None)
        self.pPupil.addItem(self.pPupilimg)
        self.pupilContour = pg.ScatterPlotItem()
        self.pPupil.addItem(self.pupilContour)
        self.pupilCenter = pg.ScatterPlotItem()
        self.pPupil.addItem(self.pupilCenter)

        # saturation sliders
        self.sl = Slider(0, self)
        self.sl.setValue(100)
        self.l0.addWidget(self.sl,1,6,1,7)
        qlabel= QtWidgets.QLabel('saturation')
        qlabel.setStyleSheet('color: white;')
        self.l0.addWidget(qlabel, 0,8,1,3)

        # adding blanks (eye borders, ...)
        self.blankBtn = QtWidgets.QPushButton('add blanks')
        self.l0.addWidget(self.blankBtn, 1, 8+6, 1, 1)
        self.blankBtn.setEnabled(True)
        self.blankBtn.clicked.connect(self.add_blankROI)
        
        # adding reflections ("corneal reflections, ...")
        self.reflectorBtn = QtWidgets.QPushButton('add reflect.')
        self.l0.addWidget(self.reflectorBtn, 2, 8+6, 1, 1)
        self.reflectorBtn.setEnabled(True)
        self.reflectorBtn.clicked.connect(self.add_reflectROI)

        self.keepCheckBox = QtWidgets.QCheckBox("keep ROIs")
        self.keepCheckBox.setStyleSheet("color: gray;")
        self.keepCheckBox.setChecked(True)
        self.l0.addWidget(self.keepCheckBox, 2, 8+7, 1, 1)
        
        # fit pupil
        self.fit_pupil = QtWidgets.QPushButton('fit Pupil [Ctrl+F]')
        self.l0.addWidget(self.fit_pupil, 1, 9+6, 1, 1)
        # self.fit_pupil.setEnabled(True)
        self.fit_pupil.clicked.connect(self.fit_pupil_size)
        # choose pupil shape
        self.pupil_shape = QtWidgets.QComboBox(self)
        self.pupil_shape.addItem("Ellipse fit")
        self.pupil_shape.addItem("Circle fit")
        self.l0.addWidget(self.pupil_shape, 1, 10+6, 1, 1)
        # reset
        self.reset_btn = QtWidgets.QPushButton('reset')
        self.l0.addWidget(self.reset_btn, 1, 11+6, 1, 1)
        self.reset_btn.clicked.connect(self.reset)
        # self.reset_btn.setEnabled(True)
        # draw pupil
        self.refresh_pupil = QtWidgets.QPushButton('Refresh [Ctrl+R]')
        self.l0.addWidget(self.refresh_pupil, 2, 11+6, 1, 1)
        self.refresh_pupil.setEnabled(True)
        self.refresh_pupil.clicked.connect(self.jump_to_frame)

        self.p1 = self.win.addPlot(name='plot1',row=1,col=0, colspan=2, rowspan=4,
                                   title='Pupil diameter')
        self.p1.setMouseEnabled(x=True,y=False)
        self.p1.setMenuEnabled(False)
        self.p1.hideAxis('left')
        self.scatter = pg.ScatterPlotItem()
        self.p1.addItem(self.scatter)
        self.p1.setLabel('bottom', 'time (frame #)')
        self.xaxis = self.p1.getAxis('bottom')
        self.p1.autoRange(padding=0.01)
        
        self.win.ci.layout.setRowStretchFactor(0,5)
        self.movieLabel = QtWidgets.QLabel("No datafile chosen")
        self.movieLabel.setStyleSheet("color: white;")
        self.l0.addWidget(self.movieLabel,0,1,1,5)


        # create frame slider
        self.timeLabel = QtWidgets.QLabel("Current time (seconds):")
        self.timeLabel.setStyleSheet("color: white;")
        self.currentTime = QtWidgets.QLineEdit()
        self.currentTime.setText('0')
        self.currentTime.setValidator(QtGui.QDoubleValidator(0, 100000, 2))
        self.currentTime.setFixedWidth(50)
        self.currentTime.returnPressed.connect(self.set_precise_time)
        
        self.frameSlider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.frameSlider.setMinimum(0)
        self.frameSlider.setMaximum(200)
        self.frameSlider.setTickInterval(1)
        self.frameSlider.setTracking(False)
        self.frameSlider.valueChanged.connect(self.go_to_frame)

        istretch = 23
        iplay = istretch+15
        iconSize = QtCore.QSize(20, 20)

        self.folderB = QtWidgets.QComboBox(self)
        self.folderB.setMinimumWidth(150)
        self.folderB.addItems(FOLDERS.keys())

        self.process = QtWidgets.QPushButton('process data [Ctrl+P]')
        self.process.clicked.connect(self.process_ROIs)

        self.cursor1 = QtWidgets.QPushButton('Set Cursor 1 [Ctrl+1]')
        self.cursor1.clicked.connect(self.set_cursor_1)

        self.cursor2 = QtWidgets.QPushButton('Set Cursor 2 [Ctrl+2]')
        self.cursor2.clicked.connect(self.set_cursor_2)
        
        self.runAsSubprocess = QtWidgets.QPushButton('run as subprocess')
        self.runAsSubprocess.clicked.connect(self.run_as_subprocess)

        self.load = QtWidgets.QPushButton('  load data [Ctrl+O]  \u2b07')
        self.load.clicked.connect(self.load_data)

        self.loadLastGUIsettings = QtWidgets.QPushButton("last GUI settings")
        self.loadLastGUIsettings.clicked.connect(self.load_last_gui_settings)
        
        sampLabel = QtWidgets.QLabel("Subsampling (frame)")
        sampLabel.setStyleSheet("color: gray;")
        self.samplingBox = QtWidgets.QLineEdit()
        self.samplingBox.setText(str(self.subsampling))
        self.samplingBox.setFixedWidth(50)

        smoothLabel = QtWidgets.QLabel("Smoothing (px)")
        smoothLabel.setStyleSheet("color: gray;")
        self.smoothBox = QtWidgets.QLineEdit()
        self.smoothBox.setText(str(self.gaussian_smoothing))
        self.smoothBox.setFixedWidth(30)

        self.addROI = QtWidgets.QPushButton("add Pupil-ROI")
        
        self.addROI.clicked.connect(self.add_ROI)

        self.saverois = QtWidgets.QPushButton('save data [Ctrl+S]')
        self.saverois.clicked.connect(self.save)

        stdLabel = QtWidgets.QLabel("std excl. factor: ")
        stdLabel.setStyleSheet("color: gray;")
        self.stdBox = QtWidgets.QLineEdit()
        self.stdBox.setText('3.0')
        self.stdBox.setFixedWidth(50)

        wdthLabel = QtWidgets.QLabel("excl. width (s): ")
        wdthLabel.setStyleSheet("color: gray;")
        self.wdthBox = QtWidgets.QLineEdit()
        self.wdthBox.setText('0.1')
        self.wdthBox.setFixedWidth(50)
        
        self.excludeOutliers = QtWidgets.QPushButton('exclude outlier [Ctrl+E]')
        self.excludeOutliers.clicked.connect(self.find_outliers)

        cursorLabel = QtWidgets.QLabel("set cursor 1 [Ctrl+1], cursor 2 [Ctrl+2]")
        cursorLabel.setStyleSheet("color: gray;")
        
        self.interpBtn = QtWidgets.QPushButton('interpolate only [Ctrl+4]')
        self.interpBtn.clicked.connect(self.interpolate)

        self.processOutliers = QtWidgets.QPushButton('Set blinking interval [Ctrl+3]')
        self.processOutliers.clicked.connect(self.process_outliers)
        
        self.printSize = QtWidgets.QPushButton('print ROI size')
        self.printSize.clicked.connect(self.print_size)

        for x in [self.process, self.cursor1, self.cursor2, self.runAsSubprocess, self.load,
                  self.saverois, self.addROI, self.interpBtn, self.processOutliers,
                  self.stdBox, self.wdthBox, self.excludeOutliers, self.printSize, cursorLabel,
                  self.loadLastGUIsettings,
                  sampLabel, smoothLabel, stdLabel, wdthLabel, self.smoothBox, self.samplingBox]:
            x.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
        
        
        iconSize = QtCore.QSize(30, 30)
        self.playButton = QtWidgets.QToolButton()
        self.playButton.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay))
        self.playButton.setIconSize(iconSize)
        self.playButton.setToolTip("Play")
        self.playButton.setCheckable(True)
        self.pauseButton = QtWidgets.QToolButton()
        self.pauseButton.setCheckable(True)
        self.pauseButton.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_MediaPause))
        self.pauseButton.setIconSize(iconSize)
        self.pauseButton.setToolTip("Pause")

        btns = QtWidgets.QButtonGroup(self)
        btns.addButton(self.playButton,0)
        btns.addButton(self.pauseButton,1)

        self.l0.addWidget(self.folderB,1,0,1,3)
        self.l0.addWidget(self.load,2,0,1,3)
        self.l0.addWidget(self.loadLastGUIsettings, 7, 0, 1, 3)
        self.l0.addWidget(sampLabel, 8, 0, 1, 3)
        self.l0.addWidget(self.samplingBox, 8, 2, 1, 3)
        self.l0.addWidget(smoothLabel, 9, 0, 1, 3)
        self.l0.addWidget(self.smoothBox, 9, 2, 1, 3)
        self.l0.addWidget(self.addROI,14,0,1,3)
        self.l0.addWidget(self.process, 16, 0, 1, 3)
        self.l0.addWidget(self.runAsSubprocess, 17, 0, 1, 3)
        self.l0.addWidget(self.saverois, 19, 0, 1, 3)

        self.l0.addWidget(stdLabel, 21, 0, 1, 3)
        self.l0.addWidget(self.stdBox, 21, 2, 1, 3)
        self.l0.addWidget(wdthLabel, 22, 0, 1, 3)
        self.l0.addWidget(self.wdthBox, 22, 2, 1, 3)
        self.l0.addWidget(self.excludeOutliers, 23, 0, 1, 3)
        self.l0.addWidget(cursorLabel, 25, 0, 1, 3)
        self.l0.addWidget(self.processOutliers, 26, 0, 1, 3)
        self.l0.addWidget(self.interpBtn, 27, 0, 1, 3)
        self.l0.addWidget(self.printSize, 29, 0, 1, 3)

        self.l0.addWidget(QtWidgets.QLabel(''),istretch,0,1,3)
        self.l0.setRowStretch(istretch,1)
        self.l0.addWidget(self.timeLabel, istretch+13,0,1,3)
        self.l0.addWidget(self.currentTime, istretch+14,0,1,3)
        self.l0.addWidget(self.frameSlider, istretch+15,3,1,15)

        self.l0.addWidget(QtWidgets.QLabel(''),17,2,1,1)
        self.l0.setRowStretch(16,2)
        # self.l0.addWidget(ll, istretch+3+k+1,0,1,4)
        self.updateFrameSlider()
        
        self.nframes = 0
        self.cframe, self.cframe1, self.cframe2, = 0, 0, 0

        self.updateTimer = QtCore.QTimer()
        
        self.win.show()
        self.show()
コード例 #13
0
    def __init__(self, app, args=None, parent=None, debug=False):
        """
        Red-Cell selection GUI
        """
        self.app = app
        self.debug = debug

        super(RCGwindow, self).__init__(i=3, title='red-cell gui')

        self.nextSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+N'), self)
        self.nextSc.activated.connect(self.next_roi)

        self.saveSc = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+S'), self)
        self.saveSc.activated.connect(self.save)

        self.Sc1 = QtWidgets.QShortcut(QtGui.QKeySequence('1'), self)
        self.Sc1.activated.connect(self.switch_to_1)
        self.Sc2 = QtWidgets.QShortcut(QtGui.QKeySequence('2'), self)
        self.Sc2.activated.connect(self.switch_to_2)
        self.Sc3 = QtWidgets.QShortcut(QtGui.QKeySequence('3'), self)
        self.Sc3.activated.connect(self.switch_to_3)
        self.Sc4 = QtWidgets.QShortcut(QtGui.QKeySequence('4'), self)
        self.Sc4.activated.connect(self.switch_to_4)
        self.Sc5 = QtWidgets.QShortcut(QtGui.QKeySequence('5'), self)
        self.Sc5.activated.connect(self.switch_to_5)
        self.Sc6 = QtWidgets.QShortcut(QtGui.QKeySequence('6'), self)
        self.Sc6.activated.connect(self.switch_to_6)

        self.roiSc = QtWidgets.QShortcut(QtGui.QKeySequence('Space'), self)
        self.roiSc.activated.connect(self.switch_roi_display)

        self.roi_index = 0

        ########################
        ##### building GUI #####
        ########################

        self.minView = False
        self.showwindow()

        # central widget
        self.cwidget = QtGui.QWidget(self)
        self.setCentralWidget(self.cwidget)

        # layout
        self.l0 = QtGui.QGridLayout()
        self.cwidget.setLayout(self.l0)
        self.win = pg.GraphicsLayoutWidget()
        self.win.move(600, 0)
        self.win.resize(600, 400)
        self.l0.addWidget(self.win, 1, 3, 37, 15)
        layout = self.win.ci.layout

        # A plot area (ViewBox + axes) for displaying the image
        self.p0 = self.win.addViewBox(lockAspect=False,
                                      row=0,
                                      col=0,
                                      invertY=True,
                                      border=[100, 100, 100])
        self.p0.setMouseEnabled(x=False, y=False)
        self.p0.setMenuEnabled(False)
        self.pimg = pg.ImageItem()
        self.p0.setAspectLocked()
        self.p0.addItem(self.pimg)

        # buttons and widgets
        self.folderB = QtWidgets.QComboBox(self)
        self.folderB.setMinimumWidth(150)
        self.folderB.addItems(FOLDERS.keys())

        self.imgB = QtWidgets.QComboBox(self)
        self.imgB.setMinimumWidth(150)
        self.imgB.addItems(KEYS)
        self.imgB.activated.connect(self.draw_image)

        self.load = QtGui.QPushButton('  load data [Ctrl+O]  \u2b07')
        self.load.clicked.connect(self.open_file)

        self.nextB = QtGui.QPushButton('next roi [Ctrl+N]')
        self.nextB.clicked.connect(self.next_roi)

        self.prevB = QtGui.QPushButton('prev. roi [Ctrl+P]')
        self.prevB.clicked.connect(self.process)

        self.switchB = QtGui.QPushButton('SWITCH [Ctrl+Space]')
        self.switchB.clicked.connect(self.hitting_space)

        self.saveB = QtGui.QPushButton('save data [Ctrl+S]')
        self.saveB.clicked.connect(self.save)

        self.rstRoiB = QtGui.QPushButton('reset ALL rois to green')
        self.rstRoiB.clicked.connect(self.reset_all_to_green)

        self.roiShapeCheckBox = QtWidgets.QCheckBox("ROIs as circle")
        self.roiShapeCheckBox.setChecked(True)

        for wdgt, index in zip([
                self.folderB, self.load, self.imgB, self.nextB, self.prevB,
                self.switchB, self.saveB, self.rstRoiB, self.roiShapeCheckBox
        ], [1, 2, 6, 10, 11, 12, 16, 21, 23]):
            wdgt.setFont(QtGui.QFont("Arial", 8, QtGui.QFont.Bold))
            self.l0.addWidget(wdgt, index, 0, 1, 3)

        self.rois_green = pg.ScatterPlotItem()
        self.rois_red = pg.ScatterPlotItem()
        self.rois_hl = pg.ScatterPlotItem()

        self.folder, self.rois_on = '', True
        self.show()