Пример #1
0
 def mode_change(self, i):
     self.activityMode = i
     if self.loaded:
         # activity used for correlations
         self.bin = int(self.binedit.text())
         nb = int(np.floor(float(self.Fcell.shape[1]) / float(self.bin)))
         if i == 0:
             f = self.Fcell
         elif i == 1:
             f = self.Fneu
         elif i == 2:
             f = self.Fcell - 0.7 * self.Fneu
         else:
             f = self.Spks
         ncells = len(self.stat)
         self.Fbin = f[:, :nb * self.bin].reshape(
             (ncells, nb, self.bin)).mean(axis=2)
         self.Fbin = self.Fbin - self.Fbin.mean(axis=1)[:, np.newaxis]
         self.Fstd = (self.Fbin**2).sum(axis=1)
         self.trange = np.arange(0, self.Fcell.shape[1])
         # if in correlation-view, recompute
         if self.ops_plot[2] == self.ops_plot[3].shape[1]:
             fig.corr_masks(self)
         elif self.ops_plot[2] == self.ops_plot[3].shape[1] + 1:
             fig.beh_masks(self)
         fig.plot_colorbar(self, self.ops_plot[2])
         M = fig.draw_masks(self)
         fig.plot_masks(self, M)
         fig.plot_trace(self)
         self.show()
Пример #2
0
 def press(self, parent, bid):
     for b in range(len(parent.colors)+2):
         if parent.colorbtns.button(b).isEnabled():
             parent.colorbtns.button(b).setStyleSheet(parent.styleUnpressed)
     self.setStyleSheet(parent.stylePressed)
     parent.ops_plot[2] = bid
     if not parent.sizebtns.button(1).isChecked():
         if bid==0:
             for b in [1,2]:
                 parent.topbtns.button(b).setEnabled(False)
                 parent.topbtns.button(b).setStyleSheet(parent.styleInactive)
         else:
             for b in [1,2]:
                 parent.topbtns.button(b).setEnabled(True)
                 parent.topbtns.button(b).setStyleSheet(parent.styleUnpressed)
     else:
         for b in range(3):
             parent.topbtns.button(b).setEnabled(False)
             parent.topbtns.button(b).setStyleSheet(parent.styleInactive)
     if bid==6:
         fig.corr_masks(parent)
     #elif bid==7:
     #    fig.beh_masks(parent)
     M = fig.draw_masks(parent)
     fig.plot_masks(parent,M)
     fig.plot_colorbar(parent,bid)
Пример #3
0
 def make_masks_and_buttons(self):
     self.loadBeh.setEnabled(True)
     self.bloaded = False
     self.ROI_remove()
     self.isROI = False
     self.ops_plot[1] = 0
     self.ops_plot[2] = 0
     self.ops_plot[3] = []
     self.ops_plot[4] = []
     self.setWindowTitle(self.fname)
     # set bin size to be 0.5s by default
     self.bin = int(self.ops['tau'] * self.ops['fs'] / 2)
     self.binedit.setText(str(self.bin))
     # add boundaries to stat for ROI overlays
     ncells = len(self.stat)
     for n in range(0, ncells):
         ypix = self.stat[n]['ypix'].flatten()
         xpix = self.stat[n]['xpix'].flatten()
         iext = fig.boundary(ypix, xpix)
         self.stat[n]['yext'] = ypix[iext]
         self.stat[n]['xext'] = xpix[iext]
         ycirc, xcirc = fig.circle(self.stat[n]['med'],
                                   self.stat[n]['radius'])
         goodi = (ycirc >= 0) & (xcirc >= 0) & (ycirc < self.ops['Ly']) & (
             xcirc < self.ops['Lx'])
         self.stat[n]['ycirc'] = ycirc[goodi]
         self.stat[n]['xcirc'] = xcirc[goodi]
     # enable buttons
     self.enable_views_and_classifier()
     # make color arrays for various views
     fig.make_colors(self)
     self.ichosen = int(0)
     self.imerge = [int(0)]
     self.iflip = int(0)
     self.ichosen_stats()
     self.comboBox.setCurrentIndex(2)
     # colorbar
     self.colormat = fig.make_colorbar()
     fig.plot_colorbar(self, self.ops_plot[2])
     tic = time.time()
     fig.init_masks(self)
     print(time.time() - tic)
     M = fig.draw_masks(self)
     fig.plot_masks(self, M)
     self.lcell1.setText('%d' % (ncells - self.iscell.sum()))
     self.lcell0.setText('%d' % (self.iscell.sum()))
     fig.init_range(self)
     fig.plot_trace(self)
     if (type(self.ops['diameter'])
             is not int) and (len(self.ops['diameter']) > 1):
         self.xyrat = self.ops['diameter'][0] / self.ops['diameter'][1]
     else:
         self.xyrat = 1.0
     self.p1.setAspectLocked(lock=True, ratio=self.xyrat)
     self.p2.setAspectLocked(lock=True, ratio=self.xyrat)
     self.loaded = True
     self.mode_change(2)
     self.show()
     # no classifier loaded
     classifier.activate(self, False)
Пример #4
0
    def suggest_merge(self, parent):
        parent.ichosen = self.merge_list[self.n][0]
        parent.imerge  = list(self.merge_list[self.n])
        if self.unmerged[self.n]:
            self.iMerge.setText('suggested ROIs to merge: %s'%parent.imerge)
            self.doMerge.setEnabled(True)
            self.p0.clear()
            cell0 = parent.imerge[0]
            sstring = ''
            for i in parent.imerge[1:]:
                rgb = hsv_to_rgb([parent.ops_plot[3][i,0],1,1])*255
                pen = pg.mkPen(rgb, width=3)
                scatter=pg.ScatterPlotItem(parent.Fbin[cell0], parent.Fbin[i], pen=pen)
                self.p0.addItem(scatter)
                sstring += ' %d '%i
            self.p0.setLabel('left', sstring)
            self.p0.setLabel('bottom', str(cell0))
        else:
            # set to the merged ROI index
            parent.ichosen = parent.stat[parent.ichosen]['inmerge']
            parent.imerge = [parent.ichosen]
            self.iMerge.setText('ROIs merged: %s'%list(parent.stat[parent.ichosen]['imerge']))
            self.doMerge.setEnabled(False)
            self.p0.clear()

        self.n+=1
        if self.n > len(self.merge_list)-1:
            self.n = 0
        parent.ichosen_stats()
        M = fig.draw_masks(parent)
        fig.plot_masks(parent, M)
        fig.plot_trace(parent)
        parent.zoom_to_cell()
        parent.win.show()
        parent.show()
Пример #5
0
    def do_merge(self, parent):
        merge_ROIs(parent)
        for ilist in self.merge_list:
            for n in range(ilist.size):
                if parent.stat[ilist[n]]['inmerge'] > 0:
                    ilist[n] = parent.stat[ilist[n]]['inmerge']
            ilist = np.unique(ilist)
        self.unmerged[self.n-1] = False

        self.cc_row  = np.matmul(parent.Fbin[parent.iscell], parent.Fbin[-1].T) / parent.Fbin.shape[-1]
        self.cc_row /= parent.Fstd[parent.iscell] * parent.Fstd[-1] + 1e-3
        self.cc_row[-1] = 0
        self.CC = np.concatenate((self.CC, self.cc_row[np.newaxis, :-1]), axis=0)
        self.CC = np.concatenate((self.CC, self.cc_row[:,np.newaxis]), axis=1)

        parent.ichosen = parent.stat.size-1
        parent.imerge = [parent.ichosen]
        self.iMerge.setText('ROIs merged: %s'%parent.stat[parent.ichosen]['imerge'])
        self.doMerge.setEnabled(False)
        parent.ichosen_stats()
        M = fig.draw_masks(parent)
        fig.plot_masks(parent, M)
        fig.plot_trace(parent)
        parent.win.show()
        parent.show()
Пример #6
0
 def ROIs_on(self, state):
     if state == QtCore.Qt.Checked:
         self.ops_plot[0] = True
     else:
         self.ops_plot[0] = False
     if self.loaded:
         M = fig.draw_masks(self)
         fig.plot_masks(self, M)
Пример #7
0
 def press(self, parent, bid):
     for b in parent.viewbtns.buttons():
         b.setStyleSheet(parent.styleUnpressed)
     self.setStyleSheet(parent.stylePressed)
     parent.ops_plot[1] = bid
     if parent.ops_plot[2] == parent.ops_plot[3].shape[1]:
         fig.draw_corr(parent)
     M = fig.draw_masks(parent)
     fig.plot_masks(parent, M)
Пример #8
0
 def press(self, parent, bid):
     for b in range(len(parent.views)):
         if parent.viewbtns.button(b).isEnabled():
             parent.viewbtns.button(b).setStyleSheet(parent.styleUnpressed)
     self.setStyleSheet(parent.stylePressed)
     parent.ops_plot[1] = bid
     if parent.ops_plot[2] == parent.ops_plot[3].shape[1]:
         fig.draw_corr(parent)
     M = fig.draw_masks(parent)
     fig.plot_masks(parent,M)
Пример #9
0
def merge_ROIs(parent):
    merge_activity_masks(parent)
    n = parent.iscell.size-1
    redraw_masks(parent, n)
    parent.ichosen = n
    parent.imerge = [n]
    M = fig.draw_masks(parent)
    fig.plot_masks(parent, M)
    fig.plot_trace(parent)
    parent.win.show()
    parent.show()
Пример #10
0
def apply(parent):
    classval = parent.probedit.value()
    iscell = parent.probcell > classval
    fig.flip_for_class(parent, iscell)
    M = fig.draw_masks(parent)
    fig.plot_masks(parent,M)
    np.save(parent.basename+'/iscell.npy',
            np.concatenate((np.expand_dims(parent.iscell,axis=1),
            np.expand_dims(parent.probcell,axis=1)), axis=1))
    parent.lcell0.setText(' %d'%parent.iscell.sum())
    parent.lcell1.setText(' %d'%(parent.iscell.size-parent.iscell.sum()))
Пример #11
0
 def top_selection(self, bid):
     self.ROI_remove()
     draw = False
     ncells = len(self.stat)
     icells = np.minimum(ncells, self.ntop)
     if bid == 1:
         top = True
     elif bid == 2:
         top = False
     if self.sizebtns.button(0).isChecked():
         wplot = 0
         draw = True
     elif self.sizebtns.button(2).isChecked():
         wplot = 1
         draw = True
     if draw:
         if self.ops_plot[2] != 0:
             # correlation view
             if self.ops_plot[2] == self.ops_plot[3].shape[1]:
                 istat = self.ops_plot[4]
             elif self.ops_plot[2] == self.ops_plot[3].shape[1] + 1:
                 istat = self.ops_plot[5]
             elif self.ops_plot[2] == self.ops_plot[3].shape[1] + 2:
                 istat = self.ops_plot[6]
             # statistics view
             else:
                 istat = self.ops_plot[3][:, self.ops_plot[2]]
             if wplot == 0:
                 icell = np.array(self.iscell.nonzero()).flatten()
                 istat = istat[self.iscell]
             else:
                 icell = np.array((~self.iscell).nonzero()).flatten()
                 istat = istat[~self.iscell]
             inds = istat.argsort()
             if top:
                 inds = inds[:icells]
                 self.ichosen = icell[inds[-1]]
             else:
                 inds = inds[-icells:]
                 self.ichosen = icell[inds[0]]
             self.imerge = []
             for n in inds:
                 self.imerge.append(icell[n])
             # draw choices
             if self.ops_plot[2] == self.ops_plot[3].shape[1]:
                 fig.corr_masks(self)
                 fig.plot_colorbar(self, self.ops_plot[2])
             self.ichosen_stats()
             M = fig.draw_masks(self)
             fig.plot_masks(self, M)
             fig.plot_trace(self)
             self.show()
Пример #12
0
 def select_cells(self,parent):
     parent.imerge = []
     if self.selected.size < 5000:
         for n in self.selected:
             parent.imerge.append(self.cells[self.isort[n]])
         parent.ichosen = parent.imerge[0]
         parent.ichosen_stats()
         M = fig.draw_masks(parent)
         fig.plot_masks(parent,M)
         fig.plot_trace(parent)
         parent.show()
     else:
         print('too many cells selected')
Пример #13
0
 def number_chosen(self):
     if self.loaded:
         self.ichosen = int(self.ROIedit.text())
         if self.ichosen >= len(self.stat):
             self.ichosen = len(self.stat) - 1
         self.imerge = [self.ichosen]
         if self.ops_plot[2] == self.ops_plot[3].shape[1]:
             fig.corr_masks(self)
             fig.plot_colorbar(self, self.ops_plot[2])
         self.ichosen_stats()
         M = fig.draw_masks(self)
         fig.plot_masks(self, M)
         fig.plot_trace(self)
         self.show()
Пример #14
0
def activate(parent, inactive):
    if inactive:
        parent.probcell = parent.model.apply(parent.stat)
    istat = parent.probcell
    parent.clabels[-2] = [istat.min(), (istat.max()-istat.min())/2, istat.max()]
    istat = istat - istat.min()
    istat = istat / istat.max()
    istat = istat / 1.3
    istat = istat + 0.1
    icols = 1 - istat
    parent.ops_plot[3][:,-1] = icols
    fig.class_masks(parent)
    M = fig.draw_masks(parent)
    fig.plot_masks(parent,M)
Пример #15
0
 def select_cells(self, ypix, xpix):
     i = self.ROIplot
     iROI0 = self.iROI[i, 0, ypix, xpix]
     icells = np.unique(iROI0[iROI0 >= 0])
     self.imerge = []
     for n in icells:
         if (self.iROI[i, :, ypix, xpix]
                 == n).sum() > 0.6 * self.stat[n]['npix']:
             self.imerge.append(n)
     if len(self.imerge) > 0:
         self.ichosen = self.imerge[0]
         if self.ops_plot[2] == self.ops_plot[3].shape[1]:
             fig.corr_masks(self)
             fig.plot_colorbar(self, self.ops_plot[2])
         self.ichosen_stats()
         M = fig.draw_masks(self)
         fig.plot_masks(self, M)
         fig.plot_trace(self)
         self.show()
Пример #16
0
 def plot_clicked(self, event):
     '''left-click chooses a cell, right-click flips cell to other view'''
     flip = False
     choose = False
     zoom = False
     replot = False
     items = self.win.scene().items(event.scenePos())
     posx = 0
     posy = 0
     iplot = 0
     if self.loaded:
         #print(event.modifiers() == QtCore.Qt.ControlModifier)
         for x in items:
             if x == self.img1:
                 pos = self.p1.mapSceneToView(event.scenePos())
                 posy = pos.x()
                 posx = pos.y()
                 iplot = 1
             elif x == self.img2:
                 pos = self.p2.mapSceneToView(event.scenePos())
                 posy = pos.x()
                 posx = pos.y()
                 iplot = 2
             elif x == self.p3:
                 iplot = 3
             elif (x == self.p1
                   or x == self.p2) and x != self.img1 and x != self.img2:
                 iplot = 4
                 if event.double():
                     zoom = True
             if iplot == 1 or iplot == 2:
                 if event.button() == 2:
                     flip = True
                 elif event.button() == 1:
                     if event.double():
                         zoom = True
                     else:
                         choose = True
             if iplot == 3 and event.double():
                 zoom = True
             posy = int(posy)
             posx = int(posx)
             if zoom:
                 self.zoom_plot(iplot)
             if (choose or flip) and (iplot == 1 or iplot == 2):
                 ichosen = int(self.iROI[iplot - 1, 0, posx, posy])
                 if ichosen < 0:
                     choose = False
                     flip = False
             if choose:
                 merged = False
                 if event.modifiers() == QtCore.Qt.ControlModifier:
                     if self.iscell[self.imerge[0]] == self.iscell[ichosen]:
                         if ichosen not in self.imerge:
                             self.imerge.append(ichosen)
                             self.ichosen = ichosen
                             merged = True
                         elif ichosen in self.imerge and len(
                                 self.imerge) > 1:
                             self.imerge.remove(ichosen)
                             self.ichosen = self.imerge[0]
                             merged = True
                 if not merged:
                     self.imerge = [ichosen]
                     self.ichosen = ichosen
             if flip:
                 if ichosen not in self.imerge:
                     self.imerge = [ichosen]
                     self.ichosen = ichosen
                 self.flip_plot(iplot)
             if choose or flip or replot:
                 if self.isROI:
                     self.ROI_remove()
                 if not self.sizebtns.button(1).isChecked():
                     for btn in self.topbtns.buttons():
                         if btn.isChecked():
                             btn.setStyleSheet(self.styleUnpressed)
                 if self.ops_plot[2] == self.ops_plot[3].shape[1]:
                     fig.corr_masks(self)
                     fig.plot_colorbar(self, self.ops_plot[2])
                 self.ichosen_stats()
                 M = fig.draw_masks(self)
                 fig.plot_masks(self, M)
                 fig.plot_trace(self)
                 self.show()