예제 #1
0
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.resize(800, 1000)

        self.layout = QtGui.QGridLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.layout)

        self.gw = pg.GraphicsLayoutWidget()
        self.layout.addWidget(self.gw)

        self.vb1 = self.gw.addViewBox()
        self.img1 = pg.ImageItem()
        self.vb1.addItem(self.img1)

        self.vb2 = self.gw.addViewBox(row=1, col=0)
        self.img2 = pg.ImageItem()
        self.vb2.addItem(self.img2)

        for vb in (self.vb1, self.vb2):
            vb.invertY()
            vb.setAspectLocked(True)

        self.plt1 = self.gw.addPlot(row=2, col=0)
        self.plt1.setLabels(bottom=('time', 's'))
        self.plt1_items = []

        self.rois = [
            pg.RectROI([0, 0], [10, 10], pen=(i, 4)) for i in range(2)
        ]
        for roi in self.rois:
            self.vb1.addItem(roi)
            roi.sigRegionChangeFinished.connect(self.roi_changed)
        self.ignore_roi_change = False

        self.plt2 = self.gw.addPlot(row=3, col=0)
        self.plt2.setXLink(self.plt1)
        self.plt2.setLabels(bottom=('time', 's'))

        self.base_time_rgn = pg.LinearRegionItem([0.0, 0.1])
        self.test_time_rgn = pg.LinearRegionItem([0.1, 0.11])
        for time_rgn in (self.base_time_rgn, self.test_time_rgn):
            self.plt1.addItem(time_rgn)
            time_rgn.sigRegionChangeFinished.connect(self.time_rgn_changed)
            time_rgn.sigRegionChangeFinished.connect(
                self.update_sequence_analysis)
        self.clamp_plots = []

        self.plt3 = self.gw.addPlot(row=4, col=0)
        self.plt3.setLabels(left="dF / F", bottom="trial")

        self.show()
예제 #2
0
    def __init__(self, plot, **opts):
        opts['type'] = 'bool'
        opts['value'] = True
        if not 'name' in opts.keys():
            opts['name'] = 'Region'
        if 'color' in opts:
            opts['color'] = pg.mkColor(opts['color']).setAlpha(50)
        else:
            opts['color'] = pg.mkColor((255,0,0,50))
            
        parameterTypes.GroupParameter.__init__(self, **opts)


        self.addChild({'name':'Start', 'type':'float', 'value':opts.get('startValue', 0), 'suffix':'s', 'siPrefix':True, 'step':0.1, 'dec':True})
        self.addChild({'name':'End', 'type':'float', 'value': opts.get('endValue', 0.05), 'suffix':'s', 'siPrefix':True, 'step':0.1, 'dec':True})
        self.addChild({'name':'Color', 'type':'color', 'value':opts['color']})
        self.addChild({'name':'Display', 'type':'bool', 'value':True})

        self.rgn = pg.LinearRegionItem(brush=self.child('Color').value())
        self.rgn.setRegion([self.child('Start').value(), self.child('End').value()])
        self.plot = plot
        self.plot.addItem(self.rgn)

        self.child('Start').sigValueChanged.connect(self.regionParamChanged)
        self.child('End').sigValueChanged.connect(self.regionParamChanged)
        self.rgn.sigRegionChangeFinished.connect(self.updateRegionParams)
        self.child('Color').sigValueChanged.connect(self.colorChanged)
        self.child('Display').sigValueChanged.connect(self.displayToggled)
예제 #3
0
    def __init__(self):
        QtGui.QWidget.__init__(self)

        self.layout = QtGui.QVBoxLayout()
        self.setLayout(self.layout)
        self.imv1 = pg.ImageView()
        self.layout.addWidget(self.imv1)

        self.plt1 = pg.PlotWidget()
        self.layout.addWidget(self.plt1)

        self.base_time_rgn = pg.LinearRegionItem([0.07, 0.099])
        self.test_time_rgn = pg.LinearRegionItem([0.104, 0.112])
        for time_rgn in (self.base_time_rgn, self.test_time_rgn):
            self.plt1.addItem(time_rgn)
            time_rgn.sigRegionChangeFinished.connect(self.time_rgn_changed)

        self.plot_data = []
예제 #4
0
    def __init__(self, host):
        AnalysisModule.__init__(self, host)
        
        self.background = None
        
        #self.view = pg.GraphicsView()
        self.ctrl = QtGui.QWidget()
        l = QtGui.QGridLayout()
        self.ctrl.setLayout(l)
        self.ctrl.layout = l
        #self.loadBgBtn = QtGui.QPushButton('load reference')
        #l.addWidget(self.loadBgBtn, 0, 0)
        self.addRoiBtn = QtGui.QPushButton('add ROI')
        l.addWidget(self.addRoiBtn, 0, 0)
        s = QtGui.QSpinBox()
        s.setMaximum(10)
        s.setMinimum(1)
        self.nsegSpin = s
        l.addWidget(s, 1, 0)
        self.rois = []
        self.data = []
        
        
        ## Setup basic GUI
        self._elements_ = OrderedDict([
            ('File Loader', {'type': 'fileInput', 'size': (200, 300), 'host': self, 'showFileTree': False}),
            ('Image',       {'type': 'imageView', 'pos': ('right', 'File Loader'), 'size': (800, 300)}),
            ('Time Plot',   {'type': 'plot', 'pos': ('bottom',), 'size': (800, 300)}),
            ('Trial Plot',  {'type': 'plot', 'pos': ('bottom', 'Time Plot'), 'size': (800, 300)}),
            ('Line Scan',   {'type': 'imageView', 'pos': ('right', 'Time Plot'), 'size': (800, 300)}),
            #('Data Table',  {'type': 'table', 'pos': ('below', 'Time Plot')}),
            ('Ctrl',        {'type': 'ctrl', 'pos': ('bottom', 'File Loader'), 'size': (200,30), 'object': self.ctrl}), 
        ])
        self.initializeElements()

        #self.traces = None
        self.plot = self.getElement('Time Plot', create=True)
        self.plot2 = self.getElement('Trial Plot', create=True)
        self.lr = pg.LinearRegionItem([0, 1])
        self.plot.addItem(self.lr)
        
        self.view = self.getElement('Image', create=True)
        
        ## Add a color scale
        ## removed for now--seems to be causing crashes :(
        #self.colorScale = pg.GradientLegend(self.plot1, (20, 150), (-10, -10))
        #self.plot1.scene().addItem(self.colorScale)
        
        ## Plots are updated when the selected region changes
        self.lr.sigRegionChanged.connect(self.updateAnalysis)
        self.addRoiBtn.clicked.connect(self.addRoi)
        self.view.sigProcessingChanged.connect(self.processData)
예제 #5
0
    def __init__(self):
        QtGui.QSplitter.__init__(self, QtCore.Qt.Horizontal)
        self.resize(800, 1000)

        self.params = pg.parametertree.Parameter(
            name='params',
            type='group',
            children=[
                dict(name='sequence',
                     type='group',
                     children=[
                         dict(name='analysis',
                              type='list',
                              values=['dF / F', 'SNR', 'noise']),
                     ]),
            ])
        self.ptree = pg.parametertree.ParameterTree()
        self.ptree.setParameters(self.params)
        self.params.child('sequence').sigTreeStateChanged.connect(
            self.update_sequence_analysis)

        self.leftPanel = QtGui.QWidget()
        self.addWidget(self.leftPanel)
        self.layout = QtGui.QGridLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.leftPanel.setLayout(self.layout)

        self.layout.addWidget(self.ptree, 0, 0)

        self.gw = pg.GraphicsLayoutWidget()
        self.addWidget(self.gw)

        self.vb1 = self.gw.addViewBox()
        self.img1 = pg.ImageItem()
        self.vb1.addItem(self.img1)

        self.vb2 = self.gw.addViewBox(row=1, col=0)
        self.img2 = pg.ImageItem()
        self.vb2.addItem(self.img2)

        for vb in (self.vb1, self.vb2):
            vb.invertY()
            vb.setAspectLocked(True)

        self.plt1 = self.gw.addPlot(row=2, col=0)
        self.plt1.setLabels(bottom=('time', 's'))
        self.plt1_items = []

        self.rois = [
            pg.EllipseROI([0, 0], [10, 10], pen=(i, 4)) for i in range(2)
        ]
        for roi in self.rois:
            self.vb1.addItem(roi)
            roi.sigRegionChangeFinished.connect(self.roi_changed)
        self.ignore_roi_change = False

        self.plt2 = self.gw.addPlot(row=3, col=0)
        self.plt2.setXLink(self.plt1)
        self.plt2.setLabels(bottom=('time', 's'))

        self.noise_time_rgn = pg.LinearRegionItem([0.01, 0.02],
                                                  brush=(255, 0, 0, 30))
        self.base_time_rgn = pg.LinearRegionItem([0.025, 0.95],
                                                 brush=(0, 255, 0, 30))
        self.test_time_rgn = pg.LinearRegionItem([0.1, 0.11],
                                                 brush=(0, 0, 255, 30))
        for time_rgn in (self.base_time_rgn, self.test_time_rgn,
                         self.noise_time_rgn):
            self.plt1.addItem(time_rgn)
            time_rgn.sigRegionChangeFinished.connect(self.time_rgn_changed)
            time_rgn.sigRegionChangeFinished.connect(
                self.update_sequence_analysis)
        self.clamp_plots = []

        self.plt3 = self.gw.addPlot(row=4, col=0)
        self.plt3.setLabels(left="dF / F", bottom="trial")

        self.show()
예제 #6
0
    def __init__(self, host):
        AnalysisModule.__init__(self, host)

        flowchartDir = os.path.join(
            os.path.abspath(os.path.split(__file__)[0]), "flowcharts")
        self.flowchart = Flowchart(filePath=flowchartDir)
        self.flowchart.addInput('dataIn')
        self.flowchart.addOutput('results')
        self.flowchart.outputNode._allowAddInput = False  ## make sure all data is coming out of output['results']

        try:
            ## load default chart
            self.flowchart.loadFile(os.path.join(flowchartDir, 'default.fc'))
        except:
            debug.printExc('Error loading default flowchart:')

        tables = OrderedDict([(self.dbIdentity + '.traces',
                               'TimecourseAnalyzer_traces')])
        self.dbGui = DatabaseGui(dm=host.dataManager(), tables=tables)

        self.ctrl = Qt.QWidget()
        self.ctrl.setLayout(Qt.QVBoxLayout())
        self.analyzeBtn = Qt.QPushButton('Analyze')
        self.storeToDBBtn = Qt.QPushButton('Store to DB')
        self.ctrl.layout().addWidget(self.analyzeBtn)
        self.ctrl.layout().addWidget(self.storeToDBBtn)

        self._elements_ = OrderedDict([('Database', {
            'type': 'ctrl',
            'object': self.dbGui,
            'size': (100, 100)
        }),
                                       ('Analysis Options', {
                                           'type': 'ctrl',
                                           'object': self.flowchart.widget(),
                                           'pos': ('above', 'Database'),
                                           'size': (100, 400)
                                       }),
                                       ('File Loader', {
                                           'type': 'fileInput',
                                           'size': (100, 100),
                                           'pos':
                                           ('above', 'Analysis Options'),
                                           'host': self
                                       }),
                                       ('Experiment Plot', {
                                           'type': 'plot',
                                           'pos': ('right', 'File Loader'),
                                           'size': (400, 100)
                                       }),
                                       ('Traces Plot', {
                                           'type': 'plot',
                                           'pos':
                                           ('bottom', 'Experiment Plot'),
                                           'size': (400, 200)
                                       }),
                                       ('Results Plot', {
                                           'type': 'plot',
                                           'pos': ('bottom', 'Traces Plot'),
                                           'size': (400, 200)
                                       }),
                                       ('Results Table', {
                                           'type': 'table',
                                           'pos': ('bottom', 'Traces Plot'),
                                           'size': (400, 200)
                                       }),
                                       ('Store Ctrl', {
                                           'type': 'ctrl',
                                           'object': self.ctrl,
                                           'size': (100, 100),
                                           'pos': ('bottom', 'File Loader')
                                       })])
        self.initializeElements()

        self.fileLoader = self.getElement('File Loader', create=True)
        self.exptPlot = self.getElement('Experiment Plot', create=True)
        self.tracesPlot = self.getElement('Traces Plot', create=True)
        self.resultsTable = self.getElement('Results Table', create=True)
        self.resultsTable.setSortingEnabled(False)
        self.resultsPlot = self.getElement('Results Plot', create=True)
        self.resultsPlot.getViewBox().setXLink(self.exptPlot.getViewBox(
        ))  ## link the x-axes of the exptPlot and the resultsPlot

        ### initialize variables
        self.expStart = 0
        self.traces = np.array([],
                               dtype=[('timestamp', float), ('data', object),
                                      ('fileHandle', object),
                                      ('results', object)])
        self.files = []

        self.traceSelectRgn = pg.LinearRegionItem()
        self.traceSelectRgn.setRegion([0, 60])
        self.exptPlot.addItem(self.traceSelectRgn)
        self.traceSelectRgn.sigRegionChanged.connect(self.updateTracesPlot)
        #self.traceSelectRgn.sigRegionChangeFinished.connect(self.updateAnalysis)
        #self.flowchart.sigOutputChanged.connect(self.flowchartOutputChanged)

        #self.addRegionParam = pg.parametertree.Parameter.create(name="Add Region", type='action')
        #self.paramTree.addParameters(self.addRegionParam)
        #self.addRegionParam.sigActivated.connect(self.newRegionRequested)
        self.analyzeBtn.clicked.connect(self.analyzeBtnClicked)
        self.storeToDBBtn.clicked.connect(self.storeToDBBtnClicked)
        self.flowchart.sigChartLoaded.connect(self.connectPlots)
        self.fileLoader.sigClearRequested.connect(self.clearFilesRequested)
예제 #7
0
    def __init__(self, image=None, **opts):
        """
        CanvasItem displaying an image. 
        The image may be 2 or 3-dimensional.
        Options:
            image: May be a fileHandle, ndarray, or GraphicsItem.
            handle: May optionally be specified in place of image

        """

        ## If no image was specified, check for a file handle..
        if image is None:
            image = opts.get('handle', None)

        item = None
        self.data = None
        self.currentT = None

        if isinstance(image, QtGui.QGraphicsItem):
            item = image
        elif isinstance(image, np.ndarray):
            self.data = image
        elif isinstance(image, DataManager.FileHandle):
            opts['handle'] = image
            self.handle = image
            self.data = self.handle.read()

            if 'name' not in opts:
                opts['name'] = self.handle.shortName()

            try:
                if 'transform' in self.handle.info():
                    tr = pg.SRTTransform3D(self.handle.info()['transform'])
                    tr = pg.SRTTransform(tr)  ## convert to 2D
                    opts['pos'] = tr.getTranslation()
                    opts['scale'] = tr.getScale()
                    opts['angle'] = tr.getRotation()
                else:  ## check for older info formats
                    if 'imagePosition' in self.handle.info():
                        opts['scale'] = self.handle.info()['pixelSize']
                        opts['pos'] = self.handle.info()['imagePosition']
                    elif 'Downsample' in self.handle.info():
                        ### Needed to support an older format stored by 2p imager
                        if 'pixelSize' in self.handle.info():
                            opts['scale'] = self.handle.info()['pixelSize']
                        if 'microscope' in self.handle.info():
                            m = self.handle.info()['microscope']
                            print 'm: ', m
                            print 'mpos: ', m['position']
                            opts['pos'] = m['position'][0:2]
                        else:
                            info = self.data._info[-1]
                            opts['pos'] = info.get('imagePosition', None)
                    elif hasattr(self.data, '_info'):
                        info = self.data._info[-1]
                        opts['scale'] = info.get('pixelSize', None)
                        opts['pos'] = info.get('imagePosition', None)
                    else:
                        opts['defaultUserTransform'] = {'scale': (1e-5, 1e-5)}
                        opts['scalable'] = True
            except:
                debug.printExc(
                    'Error reading transformation for image file %s:' %
                    image.name())

        if item is None:
            item = pg.ImageItem()
        CanvasItem.__init__(self, item, **opts)

        self.histogram = pg.PlotWidget()
        self.blockHistogram = False
        self.histogram.setMaximumHeight(100)
        self.levelRgn = pg.LinearRegionItem()
        self.histogram.addItem(self.levelRgn)
        self.updateHistogram(autoLevels=True)

        # addWidget arguments: row, column, rowspan, colspan
        self.layout.addWidget(self.histogram, self.layout.rowCount(), 0, 1, 3)

        self.timeSlider = QtGui.QSlider(QtCore.Qt.Horizontal)
        #self.timeSlider.setMinimum(0)
        #self.timeSlider.setMaximum(self.data.shape[0]-1)
        self.layout.addWidget(self.timeSlider, self.layout.rowCount(), 0, 1, 3)
        self.timeSlider.valueChanged.connect(self.timeChanged)
        self.timeSlider.sliderPressed.connect(self.timeSliderPressed)
        self.timeSlider.sliderReleased.connect(self.timeSliderReleased)
        thisRow = self.layout.rowCount()

        self.edgeBtn = QtGui.QPushButton('Edge')
        self.edgeBtn.clicked.connect(self.edgeClicked)
        self.layout.addWidget(self.edgeBtn, thisRow, 0, 1, 1)

        self.meanBtn = QtGui.QPushButton('Mean')
        self.meanBtn.clicked.connect(self.meanClicked)
        self.layout.addWidget(self.meanBtn, thisRow + 1, 0, 1, 1)

        self.tvBtn = QtGui.QPushButton('tv denoise')
        self.tvBtn.clicked.connect(self.tvClicked)
        self.layout.addWidget(self.tvBtn, thisRow + 2, 0, 1, 1)

        self.maxBtn = QtGui.QPushButton('Max no Filter')
        self.maxBtn.clicked.connect(self.maxClicked)
        self.layout.addWidget(self.maxBtn, thisRow, 1, 1, 1)

        self.maxBtn2 = QtGui.QPushButton('Max w/Gaussian')
        self.maxBtn2.clicked.connect(self.max2Clicked)
        self.layout.addWidget(self.maxBtn2, thisRow + 1, 1, 1, 1)

        self.maxMedianBtn = QtGui.QPushButton('Max w/Median')
        self.maxMedianBtn.clicked.connect(self.maxMedianClicked)
        self.layout.addWidget(self.maxMedianBtn, thisRow + 2, 1, 1, 1)

        self.filterOrder = QtGui.QComboBox()
        self.filterLabel = QtGui.QLabel('Order')
        for n in range(1, 11):
            self.filterOrder.addItem("%d" % n)
        self.layout.addWidget(self.filterLabel, thisRow + 3, 2, 1, 1)
        self.layout.addWidget(self.filterOrder, thisRow + 3, 3, 1, 1)

        self.zPlanes = QtGui.QComboBox()
        self.zPlanesLabel = QtGui.QLabel('# planes')
        for s in ['All', '1', '2', '3', '4', '5']:
            self.zPlanes.addItem("%s" % s)
        self.layout.addWidget(self.zPlanesLabel, thisRow + 3, 0, 1, 1)
        self.layout.addWidget(self.zPlanes, thisRow + 3, 1, 1, 1)

        ## controls that only appear if there is a time axis
        self.timeControls = [
            self.timeSlider, self.edgeBtn, self.maxBtn, self.meanBtn,
            self.maxBtn2, self.maxMedianBtn, self.filterOrder, self.zPlanes
        ]

        if self.data is not None:
            self.updateImage(self.data)

        self.graphicsItem().sigImageChanged.connect(self.updateHistogram)
        self.levelRgn.sigRegionChanged.connect(self.levelsChanged)
        self.levelRgn.sigRegionChangeFinished.connect(
            self.levelsChangeFinished)