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)
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()
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()
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()
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()
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()