class BaseCurveWidget(QSplitter): """ Construct a BaseCurveWidget object, which includes: * A plot (:py:class:`guiqwt.curve.CurvePlot`) * An `item list` panel (:py:class:`guiqwt.curve.PlotItemList`) This object does nothing in itself because plot and panels are not connected to each other. See children class :py:class:`guiqwt.plot.CurveWidget` """ def __init__(self, parent=None, title=None, xlabel=None, ylabel=None, xunit=None, yunit=None, section="plot", show_itemlist=False, gridparam=None, curve_antialiasing=None, **kwargs): if PYQT5: super(BaseCurveWidget, self).__init__(parent, **kwargs) self.setOrientation(Qt.Horizontal) else: QSplitter.__init__(self, Qt.Horizontal, parent) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.plot = CurvePlot(parent=self, title=title, xlabel=xlabel, ylabel=ylabel, xunit=xunit, yunit=yunit, section=section, gridparam=gridparam) if curve_antialiasing is not None: self.plot.set_antialiasing(curve_antialiasing) self.addWidget(self.plot) self.itemlist = PlotItemList(self) self.itemlist.setVisible(show_itemlist) self.addWidget(self.itemlist) configure_plot_splitter(self)
class FilterTestWidget(QWidget): """ Filter testing widget parent: parent widget (QWidget) x, y: NumPy arrays func: function object (the signal filter to be tested) """ def __init__(self, parent, x, y, func): QWidget.__init__(self, parent) self.setMinimumSize(320, 200) self.x = x self.y = y self.func = func # ---guiqwt related attributes: self.plot = None self.curve_item = None # --- def setup_widget(self, title): # ---Create the plot widget: self.plot = CurvePlot(self) self.curve_item = make.curve([], [], color="b") self.plot.add_item(self.curve_item) self.plot.set_antialiasing(True) # --- button = QPushButton("Test filter: %s" % title) button.clicked.connect(self.process_data) vlayout = QVBoxLayout() vlayout.addWidget(self.plot) vlayout.addWidget(button) self.setLayout(vlayout) self.update_curve() def process_data(self): self.y = self.func(self.y) self.update_curve() def update_curve(self): # ---Update curve self.curve_item.set_data(self.x, self.y) self.plot.replot()
class FilterTestWidget(QWidget): """ Filter testing widget parent: parent widget (QWidget) x, y: NumPy arrays func: function object (the signal filter to be tested) """ def __init__(self, parent, x, y, func): QWidget.__init__(self, parent) self.setMinimumSize(320, 200) self.x = x self.y = y self.func = func #---guiqwt related attributes: self.plot = None self.curve_item = None #--- def setup_widget(self, title): #---Create the plot widget: self.plot = CurvePlot(self) self.curve_item = make.curve([], [], color='b') self.plot.add_item(self.curve_item) self.plot.set_antialiasing(True) #--- button = QPushButton("Test filter: %s" % title) button.clicked.connect(self.process_data) vlayout = QVBoxLayout() vlayout.addWidget(self.plot) vlayout.addWidget(button) self.setLayout(vlayout) self.update_curve() def process_data(self): self.y = self.func(self.y) self.update_curve() def update_curve(self): #---Update curve self.curve_item.set_data(self.x, self.y) self.plot.replot()
class PlotWidget(qg.QWidget): """ """ def __init__(self, parent): qg.QWidget.__init__(self, parent) self.data = Dbase(DBaseName = None) self.y1Data = np.arange(0,100) #self.data.Query() self.y2Data = np.arange(0,100) self.xData = np.arange(0,100) #np.arange(0, len(self.yData)) self.setMinimumSize(700, 600) #---guiqwt related attributes: self.plot = None self.curve_item = None #--- def setup_widget(self, title): """Create the plot widget: """ self.plot = CurvePlot(self) self.curve_item = (make.curve([], [], color='b')) self.second_curve_item = (make.curve([], [], color='g')) self.plot.add_item(self.curve_item) self.plot.add_item(self.second_curve_item) self.plot.set_antialiasing(True) self.databaseScroll = treeList(DBaseName = None) self.databaseScroll.setSortingEnabled(True) spacer = qg.QSpacerItem(30,40) preprocessData = qg.QGroupBox(u"preprocess data") # create buttons listButton = qg.QPushButton(u"Refresh list") processButton = qg.QPushButton(u" run preprocessing ") addwaveletButton = qg.QPushButton(u" add wavelet spikes to DB ") self.checkAddData = qg.QMessageBox() self.wavelet = qg.QCheckBox(u"wavelet filter ") label1 = qg.QLabel("enter threshold value: ") self.waveletThreshold = qg.QLineEdit(u"10") # connect user actions with methods: self.connect(listButton, qc.SIGNAL('clicked()'), self.but_clicked) self.connect(processButton, qc.SIGNAL('clicked()'), self.run_preprocess) self.connect(self.databaseScroll, qc.SIGNAL("doubleClicked(QModelIndex)"), self.double_clicked) self.connect(addwaveletButton, qc.SIGNAL('clicked()'), self.add_data_to_DBase) vlayout = qg.QVBoxLayout() hlayout = qg.QHBoxLayout() vlayout.addWidget(self.databaseScroll) vlayout.addWidget(listButton) vlayout.addWidget(self.plot) vlayout.addSpacerItem(spacer) hlayout.addWidget(self.wavelet) hlayout.addWidget(label1) hlayout.addWidget(self.waveletThreshold) hlayout.addWidget(processButton) hlayout.addWidget(addwaveletButton) preprocessData.setLayout(hlayout) vlayout.addWidget(preprocessData) self.setLayout(vlayout) self.update_curve() def run_preprocess(self): """ """ if self.wavelet.isChecked(): try: yData = self.y1Data waveletFilt = pp.wavefilter(yData) self.y1Data = waveletFilt thresh = float(self.waveletThreshold.displayText()) foo = self.y1Data > thresh self.y2Data = self.spikes = pp.spikeThreshold(foo) self.y2Data = self.y2Data * max(self.y1Data) index = self.databaseScroll root = index.parent().parent().row() neuron = index.parent().row() epoch = index.row() r = self.databaseScroll self.data = Dbase(r, PRINT = 1) n = self.databaseScroll epochs = self.data.GetTree(n) e = epochs[epoch] self.spikeOverwriteLoc = [r, n + '.' + e + '.spikes', n + '.' + e, n, n + '_' + e + '_spikes'] self.data.Data.CloseDatabase(PRINT=1) print 'spike handle: ', self.spikeOverwriteLoc[0:2] self.update_curve() except ValueError: print 'ValueError. Could not compute wave filter' pass def add_data_to_DBase(self): """ """ self.checkAddData.setText("Are you sure you want to add filtered \ spikes (green trace) to the DB?") self.checkAddData.setInformativeText("This will overwrite the existing\ spike data.") self.checkAddData.setStandardButtons(qg.QMessageBox.Yes | qg.QMessageBox.No ) self.checkAddData.setDefaultButton(qg.QMessageBox.Yes) choice = self.checkAddData.exec_() == qg.QMessageBox.Yes if choice: tim = dt.datetime.utcnow().ctime() self.data = Dbase(self.spikeOverwriteLoc[0], PRINT = 1) self.data.Data.RemoveChild(self.spikeOverwriteLoc[1], option=1) self.data.Data.AddData2Database('spikes', self.spikes, self.spikeOverwriteLoc[2]) self.data.Data.AddGitVersion(self.spikeOverwriteLoc[3], Action = 'updated_{0}'.format( self.spikeOverwriteLoc[4] + str(tim.day) + '_' + str(tim.month) + '_' + str(tim.year) )) self.data.Data.CloseDatabase(PRINT=1) """ add git version here """ print 'spike data successfully overwritten.' def update_curve(self): """Update curve """ self.curve_item.set_data(self.xData, self.y1Data) self.second_curve_item.set_data(self.xData, self.y2Data) self.plot.replot() self.plot.do_autoscale() def but_clicked(self): """ when refresh button is clicked, the tree is refreshed """ self.databaseScroll.refreshTree() def double_clicked(self): """ when a name button is clicked, iterate over the model, find the neuron with this name, and set the treeviews current item """ index = self.databaseScroll.currentIndex() item = self.databaseScroll.currentItem() clickedCol = index.column() hasChild = True ind = index.parent() colCount = 1 parents = [] while hasChild: #find root index and parents root = ind.row() if root != -1: parent = str(self.databaseScroll.itemFromIndex( ind).text(clickedCol - colCount)) parents.insert(0, parent) if root == -1: hasChild = False if parents == []: parent = str(self.databaseScroll.itemFromIndex( index).text(0)) parents.insert(0, parent) ind = ind.parent() colCount += 1 name = str(item.text(clickedCol)) print 'name: ', name print 'parents: ', parents if len(parents) == 1: parents.append('') if name[:-3] == '.h5': name = '/' kind = self.databaseScroll.GetDtype(parents[0], name, parents[1:]) print kind #if dtype_ == 'np.array': # clickedData = self.databaseScroll.GetData(parents[0], name, # parents[1:]) # print clickedData '''
class iScopeWidget(QWidget): """ Filter testing widget parent: parent widget (QWidget) x, y: NumPy arrays func: function object (the signal filter to be tested) """ def __init__(self, parent, x, y): QWidget.__init__(self, parent) self.setMinimumSize(320, 200) self.x = x self.y = y # ---guiqwt related attributes: self.plot = None self.curve_item = None # --- def setup_widget(self): # ---Create the plot widget: x = self.x y = self.y self.plot = CurvePlot(self) self.curve_item = make.curve([], [], color="b") self.plot.add_item(self.curve_item) self.plot.set_antialiasing(True) width = x[-1] - x[0] self.intrange = make.range(x[0] + 0.4 * width, x[-1] - 0.4 * width) self.plot.add_item(self.intrange) self.lbgrange = make.range(x[0] + 0.3 * width, x[-1] - 0.65 * width) self.plot.add_item(self.lbgrange) self.lbgrange.pen = Qt.QPen(Qt.QColor("blue")) self.lbgrange.brush = Qt.QBrush(Qt.QColor(0, 0, 120, 100)) self.rbgrange = make.range(x[0] + 0.7 * width, x[-1] - 0.1 * width) self.rbgrange.pen = Qt.QPen(Qt.QColor("blue")) self.rbgrange.brush = Qt.QBrush(Qt.QColor(0, 0, 120, 100)) self.label1 = make.label(r"", "TR", (0, 0), "TR") self.plot.add_item(self.rbgrange) self.bg_item = make.curve([], [], color="r") self.plot.add_item(self.bg_item) self.fit_bg() self.plot.add_item(self.label1) self.connect(self.plot, SIG_RANGE_CHANGED, self.fit_bg) # --- vlayout = QVBoxLayout() vlayout.addWidget(self.plot) self.setLayout(vlayout) self.update_curve() def fit_bg(self): degree = 3 table = array([self.x, self.y]) low, high = self.lbgrange.get_range() idxlower = set(where(table[0] <= high)[0]) idxhigher = set(where(table[0] >= low)[0]) idx1 = list(idxhigher.intersection(idxlower)) low, high = self.rbgrange.get_range() idxlower = set(where(table[0] <= high)[0]) idxhigher = set(where(table[0] >= low)[0]) idx2 = list(idxhigher.intersection(idxlower)) idx = idx1 + idx2 x, y = table[:, idx] self.coeff = polyfit(x, y, degree) left, right = self.intrange.get_range() # bg = abs(quad(lambda x: polyval(self.coeff, x), left, right)[0]) idxlower = set(where(table[0] <= right)[0]) idxhigher = set(where(table[0] >= left)[0]) idx = list(idxhigher.intersection(idxlower)) x, y = table[:, idx] self.int = abs(trapz(y - polyval(self.coeff, x), x=x)) self.update_label() self.update_curve() def update_label(self): self.label1.set_text(u"""trapz(red) - int(blue) = %e""" % self.int) def update_curve(self): # ---Update curve self.curve_item.set_data(self.x, self.y) self.plot.replot() y = polyval(self.coeff, self.x) self.bg_item.set_data(self.x, y)