Esempio n. 1
0
    def __init__(self, host):
        AnalysisModule.__init__(self, host)
        if self.dataModel is None:
            raise Exception(
                "MapAnalyzer module requires a data model, but none is loaded yet."
            )

        self.currentMap = None
        self.analysisValid = False
        self.colorsValid = False

        self.ctrlLayout = pg.LayoutWidget()
        self.ctrl = ptree.ParameterTree(showHeader=False)
        self.ctrlLayout.addWidget(self.ctrl, row=0, col=0)
        self.recalcBtn = QtGui.QPushButton('Recalculate')
        self.ctrlLayout.addWidget(self.recalcBtn, row=1, col=0)
        self.storeBtn = pg.FeedbackButton('Store to DB')
        self.ctrlLayout.addWidget(self.storeBtn, row=2, col=0)

        self.loader = Loader(host=self, dm=host.dataManager())

        modPath = os.path.abspath(os.path.dirname(__file__))
        self.colorMapper = ColorMapper(
            filePath=os.path.join(modPath, "colorMaps"))
        self._elements_ = OrderedDict([
            ('File Loader', {
                'type': 'fileInput',
                'size': (300, 300),
                'host': self,
                'showFileTree': False
            }),
            ('Map Loader', {
                'type': 'ctrl',
                'object': self.loader,
                'size': (300, 300),
                'pos': ('below', 'File Loader')
            }),
            ('Color Mapper', {
                'type': 'ctrl',
                'object': self.colorMapper,
                'size': (800, 200),
                'pos': ('right', 'Map Loader')
            }),
            ('Canvas', {
                'type': 'canvas',
                'size': (800, 400),
                'pos': ('right', 'Color Mapper'),
                'args': {
                    'name': 'MapAnalyzer'
                }
            }),
            ('Options', {
                'type': 'ctrl',
                'object': self.ctrlLayout,
                'size': (300, 500),
                'pos': ('bottom', 'Map Loader')
            }),
            ('Data Plot', {
                'type': 'plot',
                'pos': ('top', 'Color Mapper'),
                'size': (800, 300)
            }),
            ('Score Histogram', {
                'type': 'plot',
                'pos': ('bottom', 'Data Plot'),
                'size': (800, 300)
            }),
            ('Timeline', {
                'type': 'plot',
                'pos': ('bottom', 'Data Plot'),
                'size': (800, 300)
            }),
            ('Stats Table', {
                'type': 'dataTree',
                'pos': ('bottom', 'Canvas'),
                'size': (800, 300)
            }),
        ])
        host.resize(1100, 800)
        self.initializeElements()

        self.filterStage = EventFilter()
        self.spontRateStage = SpontRateAnalyzer(
            plot=self.getElement('Timeline', create=True))
        self.statsStage = EventStatisticsAnalyzer(
            histogramPlot=self.getElement('Score Histogram', create=True))
        self.regions = RegionMarker(self.getElement('Canvas', create=True))
        self.stages = [
            self.filterStage, self.spontRateStage, self.statsStage,
            self.regions
        ]

        params = [
            dict(name='Time Ranges',
                 type='group',
                 children=[
                     dict(name='Direct Start',
                          type='float',
                          value=0.498,
                          suffix='s',
                          step=0.001,
                          siPrefix=True),
                     dict(name='Stimulus',
                          type='float',
                          value=0.5,
                          suffix='s',
                          step=0.001,
                          siPrefix=True),
                     dict(name='Post Start',
                          type='float',
                          value=0.502,
                          suffix='s',
                          step=0.001,
                          siPrefix=True),
                     dict(name='Post Stop',
                          type='float',
                          value=0.700,
                          suffix='s',
                          step=0.001,
                          siPrefix=True),
                 ]),
        ]

        ## each processing stage comes with its own set of parameters
        for stage in self.stages:
            params.append(stage.parameters())

        self.params = ptree.Parameter.create(name='options',
                                             type='group',
                                             children=params)
        self.ctrl.setParameters(self.params, showTop=False)

        canvas = self.getElement('Canvas', create=True)
        #self.scalebar = pg.ScaleBar(100e-6)
        #canvas.addGraphicsItem(self.scalebar, name="ScaleBar")
        self.scalebar = pg.ScaleBar(size=500e-6)
        self.scalebar.setParentItem(canvas.view)
        self.scalebar.anchor((1, 1), (1, 1), offset=(-20, -20))

        ## Note: need to reconnect this!!
        #self.params.sigTreeStateChanged.connect(self.invalidate)
        self.recalcBtn.clicked.connect(self.recalcClicked)
        self.storeBtn.clicked.connect(self.storeToDB)
        self.params.param('Time Ranges').sigTreeStateChanged.connect(
            self.updateTimes)

        self.getElement('Color Mapper',
                        create=True).sigChanged.connect(self.colorMapChanged)
        self.regions.sigRegionChanged.connect(self.processRegions)
Esempio n. 2
0
    def __init__(self, host):
        AnalysisModule.__init__(self, host)

        self.ctrlLayout = pg.LayoutWidget()

        self.reloadBtn = Qt.QPushButton('Reload Data')
        self.ctrlLayout.addWidget(self.reloadBtn)
        self.ctrl = ptree.ParameterTree(showHeader=False)
        self.ctrlLayout.addWidget(self.ctrl, row='next', col=0)
        self.filterBtn = Qt.QPushButton('Filter')
        self.ctrlLayout.addWidget(self.filterBtn, row='next', col=0)

        self.cellList = Qt.QListWidget()
        self.cellList.setSelectionMode(self.cellList.ExtendedSelection)
        self.filterText = Qt.QTextEdit("selected = data")
        self.ctrlLayout.addWidget(self.filterText, row='next', col=0)
        self.ctrlLayout.addWidget(self.cellList, row='next', col=0)

        ## 3D atlas
        self.atlas = CN.CNAtlasDisplayWidget()
        self.stimPoints = gl.GLScatterPlotItem()
        self.atlas.addItem(self.stimPoints)
        self.cellPoints = gl.GLScatterPlotItem()
        self.atlas.addItem(self.cellPoints)

        modPath = os.path.abspath(os.path.dirname(__file__))
        self.colorMapper = ColorMapper(
            filePath=os.path.join(modPath, "colorMaps"))
        self._elements_ = OrderedDict([
            #('Database Query', {'type':'ctrl', 'object': DatabaseQueryWidget(self.dataManager()), 'size':(300,200), 'pos': 'left'}),
            ('Options', {
                'type': 'ctrl',
                'object': self.ctrlLayout,
                'size': (300, 500),
                'pos': 'left'
            }),
            ('Atlas', {
                'type': 'ctrl',
                'object': self.atlas,
                'size': (600, 500),
                'pos': 'right'
            }),
            ('Color Mapper', {
                'type': 'ctrl',
                'object': self.colorMapper,
                'size': (600, 200),
                'pos': ('bottom', 'Atlas')
            }),
        ])
        host.resize(1100, 800)
        self.initializeElements()

        params = [
            dict(name='Transform',
                 type='group',
                 children=[
                     dict(name='Mirror RL', type='bool', value=True),
                     dict(name='Cell-centered', type='bool', value=False),
                 ]),
            dict(name='Display',
                 type='group',
                 children=[
                     dict(name='Cells', type='bool', value=True),
                     dict(name='Color by type', type='bool', value=True),
                     dict(name='Stimulus Sites', type='bool', value=True),
                     dict(name='Atlas', type='bool', value=False),
                     dict(name='Grid', type='bool', value=True),
                 ]),
            FilterList(name='Filter'),
        ]

        self.params = ptree.Parameter.create(name='options',
                                             type='group',
                                             children=params)
        self.ctrl.setParameters(self.params, showTop=False)

        #self.params.sigTreeStateChanged.connect(self.invalidate)

        #dbq = self.getElement('Database Query', create=True)
        #dbq.sigChanged.connect(self.dbDataChanged)
        #db = dbq.currentDatabase()
        db = self.dataManager().currentDatabase()
        self.tableName = 'map_site_view'
        if not db.hasTable(self.tableName):
            print("Creating DB views.")
            db.createView(self.tableName, [
                'map_sites', 'photostim_maps', 'dirtable_cell',
                'cochlearnucleus_protocol', 'cochlearnucleus_cell'
            ])
            ## view creation SQL:
            ## select * from map_sites
            ## inner join photostim_maps on "photostim_maps"."rowid"="map_sites"."map"
            ## inner join dirtable_cell on "dirtable_cell"."rowid"="photostim_maps"."cell"
            ## inner join cochlearnucleus_protocol on cochlearnucleus_protocol.protocoldir=map_sites.firstsite
            ## inner join cochlearnucleus_cell on cochlearnucleus_cell.celldir=dirtable_cell.rowid;
        self.reloadData()

        self.reloadBtn.clicked.connect(self.reloadData)
        self.filterBtn.clicked.connect(self.refilter)
        self.cellList.itemSelectionChanged.connect(self.selectCells)
        self.colorMapper.sigChanged.connect(self.recolor)
        self.params.param('Display').sigTreeStateChanged.connect(
            self.updateDisplay)
        self.params.param('Transform').sigTreeStateChanged.connect(
            self.transform)

        self.transform()
        self.refilter()
Esempio n. 3
0
    def __init__(self, manager, name, config):
        Module.__init__(self, manager, name, config)

        self.recordDir = None
        self.recordWritable = False
        self.running = False

        self.win = Qt.QSplitter()

        self.ctrlWidget = pg.LayoutWidget()
        self.win.addWidget(self.ctrlWidget)
        self.newBtn = Qt.QPushButton('New Record')
        self.loadBtn = Qt.QPushButton('Load Record')
        self.startBtn = Qt.QPushButton('Start')
        self.startBtn.setCheckable(True)
        self.fileLabel = Qt.QLabel()
        self.ctrlWidget.addWidget(self.newBtn, 0, 0)
        self.ctrlWidget.addWidget(self.loadBtn, 1, 0)
        self.ctrlWidget.addWidget(self.startBtn, 2, 0)
        self.ctrlWidget.addWidget(self.fileLabel, 3, 0)
        self.newBtn.clicked.connect(self.newRecord)
        self.loadBtn.clicked.connect(self.loadClicked)
        self.startBtn.toggled.connect(self.startToggled)

        self.params = pg.parametertree.Parameter.create(
            name='params',
            type='group',
            children=[
                dict(name='interval',
                     type='float',
                     value=10,
                     suffix='s',
                     siPrefix=True,
                     limits=[0.001, None],
                     step=1.0),
                dict(name='trace duration',
                     type='float',
                     value=1.0,
                     suffix='s',
                     siPrefix=True,
                     limits=[0.001, None],
                     step=0.1),
                dict(name='sample rate',
                     type='int',
                     value=1e6,
                     suffix='Hz',
                     siPrefix=True,
                     limits=[100, None],
                     step=1e5),
            ])
        self.ptree = pg.parametertree.ParameterTree()
        self.ptree.setParameters(self.params)
        self.ctrlWidget.addWidget(self.ptree, 4, 0)

        self.channelLayout = Qt.QSplitter()
        self.win.addWidget(self.channelLayout)

        self.channels = collections.OrderedDict()

        self.win.show()

        self.timer = Qt.QTimer()
        self.timer.timeout.connect(self.runOnce)
Esempio n. 4
0
#db.update('Cell', {'type': typ}, rowid=i[0])
#print d, typ

global eventView, siteView, cells
eventView = 'events_view'
siteView = 'sites_view'

firstRun = False
if 'events' not in locals():
    global events
    events = {}
    firstRun = True

    win = Qt.QMainWindow()
    #cw = Qt.QWidget()
    layout = pg.LayoutWidget()
    #layout = Qt.QGridLayout()
    #layout.setContentsMargins(0,0,0,0)
    #layout.setSpacing(0)
    #cw.setLayout(layout)
    win.setCentralWidget(layout)

    cellCombo = Qt.QComboBox()
    cellCombo.setSizeAdjustPolicy(cellCombo.AdjustToContents)
    layout.addWidget(cellCombo)

    reloadBtn = Qt.QPushButton('reload')
    layout.addWidget(reloadBtn)

    separateCheck = Qt.QCheckBox("color pre/post")
    layout.addWidget(separateCheck)