Beispiel #1
0
 def roiChanged(self, roi):
     if isinstance(roi, int):
         roi = self.currentRoi
     self.plot.clearPlots()
     c = 0
     lineScans = []
     for imgSet in self.data:
         data = roi.getArrayRegion(imgSet['procMean'], self.view.imageItem, axes=(1,2))
         m = data.mean(axis=1).mean(axis=1)
         lineScans.append(data.mean(axis=2))
         spacer = np.empty((lineScans[-1].shape[0], 1), dtype = lineScans[-1].dtype)
         spacer[:] = lineScans[-1].min()
         lineScans.append(spacer)
         
         data = roi.getArrayRegion(imgSet['procStd'], self.view.imageItem, axes=(1,2))
         s = data.mean(axis=1).mean(axis=1)
         
         self.plot.plot(m, pen=pg.hsvColor(c*0.2, 1.0, 1.0))
         self.plot.plot(m-s, pen=pg.hsvColor(c*0.2, 1.0, 0.4))
         self.plot.plot(m+s, pen=pg.hsvColor(c*0.2, 1.0, 0.4))
         
         c += 1
         
     lineScan = np.hstack(lineScans)
     self.getElement('Line Scan').setImage(lineScan)
     self.currentRoi = roi
Beispiel #2
0
 def updateAnalysis(self):
     roi = self.currentRoi
     plot = self.getElement('Trial Plot')
     plot.clearPlots()
     c = 0
     for img in self.normData:
         #img = img.mean(axis=1)
         rgn = self.lr.getRegion()
         img = img[:, rgn[0]:rgn[1]].mean(axis=1)
         data = roi.getArrayRegion(img, self.view.imageItem, axes=(1,2))
         m = data.mean(axis=1).mean(axis=1)
         #data = roi.getArrayRegion(img, self.view.imageItem, axes=(1,2))
         #s = data.mean(axis=1).mean(axis=1)
         plot.plot(m, pen=pg.hsvColor(c*0.2, 1.0, 1.0))
         #self.plot.plot(m-s, pen=pg.hsvColor(c*0.2, 1.0, 0.4))
         #self.plot.plot(m+s, pen=pg.hsvColor(c*0.2, 1.0, 0.4))
         c += 1
Beispiel #3
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 #4
0
def showCell(**kwds):
    pw2.clear()
    reloadData = kwds.get('reloadData', False)
    #global lock
    #if lock:
    #return
    #lock = True
    Qt.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(list(evSpots.keys()))
    atlasPoints.setData(pos=pos, )