Beispiel #1
0
 def valueString(self, param):
     units = param.opts.get('units', None)
     if isinstance(units, basestring) and len(units) > 0:
         val = pg.siFormat(param.value(), suffix=units, space='*', precision=5, allowUnicode=False)
     else:
         val = '%0.5g' % param.value()
     return val
Beispiel #2
0
    def update(self):
        pos = self.dev.getPosition()
        #for i in [0,1,2]:
            #if pos[i] < self.limit

        text = [pg.siFormat(x, suffix='m', precision=5) for x in pos]
        self.ui.xPosLabel.setText(text[0])
        self.ui.yPosLabel.setText(text[1])
        self.ui.zPosLabel.setText(text[2])
Beispiel #3
0
 def handleNewFrame(self, frame):
     prof = Profiler('PatchWindow.handleNewFrame', disabled=True)
     with self.paramLock:
         mode = self.params['mode']
     
     data = frame['data'][self.clampName]
     
     if mode == 'vc':
         self.ui.patchPlot.setLabel('left', units='A')
     else:
         self.ui.patchPlot.setLabel('left', units='V')
     prof.mark('1')
         
     self.patchCurve.setData(data.xvals('Time'), data['primary'])
     prof.mark('2')
     if self.redrawCommand > 0:
         self.redrawCommand -= 1
         #print "set command curve"
         self.commandCurve.setData(data.xvals('Time'), data['command'])
         if mode == 'vc':
             self.ui.commandPlot.setLabel('left', units='V')
         else:
             self.ui.commandPlot.setLabel('left', units='A')
     prof.mark('3')
     #self.ui.patchPlot.replot()
     #self.ui.commandPlot.replot()
     if frame['analysis']['fitTrace'] is not None:
         self.patchFitCurve.show()
         self.patchFitCurve.setData(data.xvals('Time'), frame['analysis']['fitTrace'])
     else:
         self.patchFitCurve.hide()
     prof.mark('4')
     
     for k in self.analysisItems:
         if k in frame['analysis']:
             self.analysisData[k].append(frame['analysis'][k])
     prof.mark('5')
             
     for r in ['input', 'access']:
         res = r+'Resistance'
         label = getattr(self.ui, res+'Label')
         resistance = frame['analysis'][res]
         label.setText(siFormat(resistance) + u'Ω')
     prof.mark('6')
     self.ui.restingPotentialLabel.setText(siFormat(frame['analysis']['restingPotential'], error=frame['analysis']['restingPotentialStd'], suffix='V'))
     self.ui.restingCurrentLabel.setText(siFormat(frame['analysis']['restingCurrent'], error=frame['analysis']['restingCurrentStd'], suffix='A'))
     self.ui.capacitanceLabel.setText('%sF' % siFormat(frame['analysis']['capacitance']))
     self.ui.fitErrorLabel.setText('%7.2g' % frame['analysis']['fitError'])
     prof.mark('7')
     
     start = data._info[-1]['DAQ']['command']['startTime']
     if self.startTime is None:
         self.startTime = start
         if self.ui.recordBtn.isChecked() and self.storageFile is not None:
             self.storageFile.setInfo({'startTime': self.startTime})
     self.analysisData['time'].append(start - self.startTime)
     prof.mark('8')
     self.updateAnalysisPlots()
     prof.mark('9')
     
     ## Record to disk if requested.
     if self.ui.recordBtn.isChecked():
         
         arr = self.makeAnalysisArray(lastOnly=True)
         #print "appending array", arr.shape
         if self.storageFile is None:
             self.newFile(arr)
         else:
             arr.write(self.storageFile.name(), appendAxis='Time')
     prof.mark('10')
     prof.finish()
Beispiel #4
0
 def update(self):
     pos = self.dev.getPosition()
     text = [pg.siFormat(x, suffix="m", precision=5) for x in pos]
     self.label.setText(", ".join(text))
Beispiel #5
0
 def update(self):
     pos = self.dev.getPosition()
     for i in range(3):
         text = pg.siFormat(pos[i], suffix="m", precision=5)
         self.posLabels[i].setText(text)
Beispiel #6
0
def showCell(**kwds):
    pw2.clear()
    reloadData = kwds.get('reloadData', False)
    #global lock
    #if lock:
        #return
    #lock = True
    QtGui.QApplication.processEvents() ## prevents double-spin
    #lock = False
    cell = cells[cellCombo.currentIndex()-1]
    
    dh = cell #db.getDir('Cell', cell)
    loadCell(dh, reloadData=reloadData)
    
    try:
        image.setImage(dh['morphology.png'].read())
        gv.setRange(image.sceneBoundingRect())
    except:
        image.setImage(np.zeros((2,2)))
        pass
    
    ev, numExSites, numInSites = events[cell]
    
    ev2 = select(ev, ex=True)
    ev3 = select(ev, ex=False)
    
    if colorCheck.isChecked():
        sp1.hide()
        sp2.hide()
        sp3.hide()
        sp4.show()
        
        start = postRgnStart()
        stop = postRgnStop()
        ev2post = ev2[(ev2['fitTime']>start) * (ev2['fitTime']<stop)]
        ev3post = ev3[(ev3['fitTime']>start) * (ev3['fitTime']<stop)]
        ev4 = np.concatenate([ev2post, ev3post])
        
        yMax = ev4['dorsal'].max()
        yMin = ev4['dorsal'].min()
        brushes = []
        for i in range(len(ev4)):
            hue = 0.6*((ev4[i]['dorsal']-yMin) / (yMax-yMin))
            brushes.append(pg.hsvColor(hue, 1.0, 1.0, 0.3))
            #pts.append({
                #'pos': (ev4[i]['fitDecayTau'], ev4[i]['fitAmplitude']),
                #'brush': pg.hsvColor(hue, 1, 1, 0.3),
                #'data': ev4[i]
            #})
            
        sp4.setData(x=ev4['fitDecayTau'], y=ev4['fitAmplitude'], symbolBrush=brushes, data=ev4)
        
    else:
        sp1.show()
        sp2.show()
        #sp3.show()
        sp4.hide()
        
        ## excitatory
        if separateCheck.isChecked():
            pre = ev2[ev2['fitTime']< preRgnStop()]
            post = ev2[(ev2['fitTime'] > postRgnStart()) * (ev2['fitTime'] < postRgnStop())]
        else:
            pre = ev2
        
        sp1.setData(x=pre['fitDecayTau'], y=pre['fitAmplitude'], data=pre);
        #print "Cell ", cell
        #print "  excitatory:", np.median(ev2['fitDecayTau']), np.median(ev2['fitAmplitude'])
        
        ## inhibitory
        if separateCheck.isChecked():
            pre = ev3[ev3['fitTime']< preRgnStop()]
            post2 = ev3[(ev3['fitTime'] > postRgnStart()) * (ev3['fitTime'] < postRgnStop())]
            post = np.concatenate([post, post2])
        else:
            pre = ev3
        sp2.setData(x=pre['fitDecayTau'], y=pre['fitAmplitude'], data=pre);
        #print "  inhibitory:", np.median(ev2['fitDecayTau']), np.median(ev2['fitAmplitude'])
        
        if separateCheck.isChecked():
            sp3.setData(x=post['fitDecayTau'], y=post['fitAmplitude'], data=post)
            sp3.show()
        else:
            sp3.hide()
    
    try:
        typ = ev2[0]['CellType']
    except:
        typ = ev3[0]['CellType']
        
    sr = spontRate(ev2, numExSites)
    sri = spontRate(ev3, numInSites)
        
    title = "%s -- %s --- <span style='color: #99F;'>ex:</span> %s %s %s %0.1fHz --- <span style='color: #F99;'>in:</span> %s %s %s %0.1fHz" % (
        dh.name(relativeTo=dh.parent().parent().parent()), 
        typ,
        pg.siFormat(np.median(ev2['fitTimeToPeak']), error=np.std(ev2['fitTimeToPeak']), space=False, suffix='s'),
        pg.siFormat(np.median(ev2['fitDecayTau']), error=np.std(ev2['fitDecayTau']), space=False, suffix='s'),
        pg.siFormat(np.median(ev2['fitAmplitude']), error=np.std(ev2['fitAmplitude']), space=False, suffix='A'),
        sr,
        pg.siFormat(np.median(ev3['fitTimeToPeak']), error=np.std(ev3['fitTimeToPeak']), space=False, suffix='s'),
        pg.siFormat(np.median(ev3['fitDecayTau']), error=np.std(ev3['fitDecayTau']), space=False, suffix='s'),
        pg.siFormat(np.median(ev3['fitAmplitude']), error=np.std(ev3['fitAmplitude']), space=False, suffix='A'),
        sri)
    print re.sub(r'<[^>]+>', '', title)
    
    pw1.setTitle(title)

    
    ### show cell in atlas
    #rec = db.select('CochlearNucleus_Cell', where={'CellDir': cell})
    #pts = []
    #if len(rec) > 0:
        #pos = (rec[0]['right'], rec[0]['anterior'], rec[0]['dorsal'])
        #pts = [{'pos': pos, 'size': 100e-6, 'color': (0.7, 0.7, 1.0, 1.0)}]
        
    ### show event positions
    evSpots = {}
    for rec in ev:
        p = (rec['right'], rec['anterior'], rec['dorsal'])
        evSpots[p] = None
        
    pos = np.array(evSpots.keys())
    atlasPoints.setData(pos=pos, )
Beispiel #7
0
 def __init__(self, dev):
     self.dev = dev
     QtGui.QWidget.__init__(self)
     self.layout = QtGui.QVBoxLayout()
     self.setLayout(self.layout)
     chans = self.dev.listChannels()
     self.widgets = {}
     #self.uis = {}
     self.defaults = {}
     row = 0
     for ch in chans:
         wid = QtGui.QWidget()
         ui = DeviceTemplate.Ui_Form()
         ui.setupUi(wid)
         self.layout.addWidget(wid)
         ui.analogCtrls = [ui.scaleDefaultBtn, ui.scaleSpin, ui.offsetDefaultBtn, ui.offsetSpin, ui.scaleLabel, ui.offsetLabel]
         #ui.channel = ch
         for s in dir(ui):
             i = getattr(ui, s)
             if isinstance(i, QtGui.QWidget):
                 i.channel = ch
             
         self.widgets[ch] = ui
         ui.nameLabel.setText(str(ch))
         ui.channelCombo.addItem("%s (%s)" % (ch, chans[ch]['channel']))
         
         holding = chans[ch].get('holding', 0)
         
         
         
         if chans[ch]['type'] in ['ao', 'ai']:
             ui.inputRadio.setEnabled(False)
             ui.outputRadio.setEnabled(False)
             ui.invertCheck.hide()
             scale = chans[ch].get('scale', 1)
             units = chans[ch].get('units', 'V')
             offset = chans[ch].get('offset', 0)
             ui.offsetSpin.setOpts(suffix = 'V', siPrefix=True, dec=True, step=1.0, minStep=1e-4)
             ui.offsetSpin.setValue(offset)
             ui.offsetSpin.sigValueChanged.connect(self.offsetSpinChanged)
             ui.offsetDefaultBtn.setText("Default (%s)" % siFormat(offset, suffix='V'))
             ui.offsetDefaultBtn.clicked.connect(self.offsetDefaultBtnClicked)
             if chans[ch]['type'] == 'ao':
                 ui.outputRadio.setChecked(True)
                 ui.scaleDefaultBtn.setText("Default (%s)" % siFormat(scale, suffix='V/'+units))
                 ui.scaleSpin.setOpts(suffix= 'V/'+units, siPrefix=True, dec=True, step=1.0, minStep=1e-9)
                 ui.holdingSpin.setOpts(suffix=units, siPrefix=True, step=0.01)
                 ui.holdingSpin.setValue(holding)
                 ui.holdingSpin.sigValueChanged.connect(self.holdingSpinChanged)
             elif chans[ch]['type'] == 'ai':
                 ui.inputRadio.setChecked(True)
                 ui.holdingLabel.hide()
                 ui.holdingSpin.hide()
                 ui.scaleDefaultBtn.setText("Default (%s)" % siFormat(scale, suffix=units+'/V'))
                 #ui.scaleDefaultBtn.clicked.connect(self.scaleDefaultBtnClicked)
                 ui.scaleSpin.setOpts(suffix= units+'/V', siPrefix=True, dec=True)
             ui.scaleSpin.setValue(scale) 
             ui.scaleDefaultBtn.clicked.connect(self.scaleDefaultBtnClicked)
             ui.scaleSpin.sigValueChanged.connect(self.scaleSpinChanged)
             self.defaults[ch] = {
                 'scale': scale,
                 'offset': offset}
         elif chans[ch]['type'] in ['do', 'di']:
             for item in ui.analogCtrls:
                 item.hide()
             if chans[ch].get('invert', False):
                 ui.invertCheck.setChecked(True)
             if chans[ch]['type'] == 'do':
                 ui.outputRadio.setChecked(True)
                 ui.holdingSpin.setOpts(bounds=[0,1], step=1)
                 ui.holdingSpin.setValue(holding)
                 ui.holdingSpin.sigValueChanged.connect(self.holdingSpinChanged)
             elif chans[ch]['type'] == 'di':
                 ui.inputRadio.setChecked(True)
                 ui.holdingLabel.hide()
                 ui.holdingSpin.hide()
             ui.invertCheck.toggled.connect(self.invertToggled)
     #QtCore.QObject.connect(self.dev, QtCore.SIGNAL('holdingChanged'), self.holdingChanged)
     self.dev.sigHoldingChanged.connect(self.holdingChanged)