def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize): ''' Reimplements Qwt5.QwtLinearScaleEngine.divideScale :return: (Qwt5.QwtScaleDiv) a scale division whose ticks are aligned with the natural delta time units ''' interval = Qwt5.QwtDoubleInterval(x1, x2).normalized() if interval.width() <= 0: return Qwt5.QwtScaleDiv() d_range = interval.width() if d_range < 2: # 2s return Qwt5.QwtLinearScaleEngine.divideScale( self, x1, x2, maxMajSteps, maxMinSteps, stepSize) elif d_range < 20: # 20 s s = 1 elif d_range < 120: # =60s*2 = 2 minutes s = 10 elif d_range < 1200: # 60s*20 =20 minutes s = 60 elif d_range < 7200: # 3600s*2 = 2 hours s = 600 elif d_range < 172800: # 3600s24*2 = 2 days s = 3600 else: s = 86400 #1 day #calculate a step size that respects the base step (s) and also enforces the maxMajSteps stepSize = s * int(np.ceil(float(d_range // s) / maxMajSteps)) return Qwt5.QwtLinearScaleEngine.divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize)
def align(self, interval, stepSize): intv = self.log2(interval) x1 = Qwt.QwtScaleArithmetic.floorEps(intv.minValue(), stepSize) x2 = Qwt.QwtScaleArithmetic.ceilEps(intv.maxValue(), stepSize) return self.pow2(Qwt.QwtDoubleInterval(x1, x2))
def plot_spectrum(self): ''' Plot the histogram of the spectrum ''' #self.__spectrum.set_demo_mode(True) #print self.__spectrum #logger.debug("{0:s}.plot_spectrum():".format(self.__class__.__name__)) xarr = [] yarr = [] ordvals = self.__spectrum.get_spectrum_ord_values() x = 0 pos = -0.25 width = 0.5 numValues = len(self.__spectrum) intervals = [] values = Qwt.QwtArrayDouble(numValues) for (mass, p) in ordvals: # Lower limit for pressure set in HistogramItem.baseline() p = self.__barCurve.baseline( ) if p < self.__barCurve.baseline() else p xarr.append(x) yarr.append(p) intervals.append(Qwt.QwtDoubleInterval(pos, pos + width)) values[x] = p pos += (width + 0.5) x += 1 self.__barCurve.setData(Qwt.QwtIntervalData(intervals, values)) self.clear_zoom_stack()
def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize): ''' Reimplements Qwt5.QwtLinearScaleEngine.divideScale **Important**: The stepSize parameter is **ignored**. :return: (Qwt5.QwtScaleDiv) a scale division whose ticks are aligned with the natural time units ''' interval = Qwt5.QwtDoubleInterval(x1, x2).normalized() if interval.width() <= 0: return Qwt5.QwtScaleDiv() #dt1=datetime.fromtimestamp(interval.minValue()) #dt2=datetime.fromtimestamp(interval.maxValue()) #if dt1.year<1900 or dt2.year>9999 : #limits in time.mktime and datetime # return Qwt5.QwtScaleDiv() i1 = int(x1) i2 = int(x2) medticks = [] minticks = [] # major ticks if x2 > x1 + 15.01: # if greater than two weeks i1 += (3 - (i1 % 7)) majticks = [float(i) for i in range(i1, i2, 7)] elif x2 > x1 + 1.01: # if greater than a day majticks = [float(i) for i in range(i1, i2 + 1)] else: # if less than a day majticks = [float(i1)] for i in range(i1, i2 + 1): majticks.extend(self.dayrange + float(i)) i1 = int(x1) i2 = int(x2) # minor ticks if x2 > x1 + 30.01: # if greater than a month(ish) i1 += (3 - (i1 % 7)) minticks = [float(i) for i in range(i1, i2, 7)] elif x2 > x1 + 1.01: # if greater than a day minticks = [float(i) for i in range(i1, i2 + 1)] # make sure to comply with maxMajTicks L = len(majticks) if L > maxMajSteps: majticks = majticks[::int(np.ceil(float(L) / maxMajSteps))] scaleDiv = Qwt5.QwtScaleDiv(interval, minticks, medticks, majticks) #self.scaleDraw().setDatetimeLabelFormat(format) if x1 > x2: scaleDiv.invert() return scaleDiv
def updateCellInfo(self, elemrec): elem, fld, hdl = elemrec self.lblStep.setText(str(elem.stepSize(fld))) elem.updateBoundary() bd = elem.boundary(fld) if True: self.lblRange.setText(str(bd)) elif bd is None or bd[0] is None or bd[1] is None: self.valMeter.setEnabled(False) else: rg = Qwt.QwtDoubleInterval(bd[0], bd[1]) self.valMeter.setScale(rg, (bd[1] - bd[0]) / 2.01) self.valMeter.setValue(elem.get(fld, unitsys=None)) self.valMeter.setEnabled(True)
def setHistogramView(self): self.histogram = HistogramItem() self.histogram.setColor(Qt.darkCyan) numValues = 20 intervals = [] values = Qwt.QwtArrayDouble(numValues) pos = 0.0 for i in range(numValues): width = 5 + random.randint(0, 4) value = random.randint(0, 99) intervals.append(Qwt.QwtDoubleInterval(pos, pos + width)) values[i] = value pos += width
def updateCellInfo(self, elemrec): elem, ik, fld = elemrec self.lblStep.setText(str(elem.stepSize(fld))) elem.updateBoundary() bd = elem.boundary(fld) #self.lblInfo.setText("{0}.{1} in {2} ss={3}".format( # elem.name, fld, bd, elem.stepSize(fld))) self.lblNameField.setText("{0}.{1}".format(elem.name, fld)) if True: self.lblRange.setText(str(bd)) elif bd is None or bd[0] is None or bd[1] is None: self.valMeter.setEnabled(False) else: rg = Qwt.QwtDoubleInterval(bd[0], bd[1]) self.valMeter.setScale(rg, (bd[1] - bd[0]) / 2.01) self.valMeter.setValue(elem.get(fld, unitsys=None)) #print elem.get(fld, unitsys=None) #print self.valMeter.value() self.valMeter.setEnabled(True)
def addHistPlotData(self, _plotName, _values, _intervals): # print 'addHistPlotData' # print '_values=',_values # print '_intervals=',_intervals # self.plotData[_plotName]=[array([],dtype=double),array([],dtype=double),False] self.plotData[str(_plotName)] = [_intervals, _values, False, HISTOGRAM] intervals = [] valLength = len(_values) values = Qwt.QwtArrayDouble(valLength) for i in range(valLength): #width = _intervals[i+1]-_intervals[i]+2 intervals.append( Qwt.QwtDoubleInterval(_intervals[i], _intervals[i + 1])) #numpy automcatically adds extra element for edge values[i] = _values[i] self.plotHistData[_plotName].setData( Qwt.QwtIntervalData(intervals, values))
def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize): interval = Qwt.QwtDoubleInterval(x1, x2).normalized() interval = interval.limited(LOG2_MIN, LOG2_MAX) if interval.width() <= 0: return Qwt.QwtScaleDiv() base = 2. if interval.maxValue() / interval.minValue() < base: # scale width is less than one octave -> build linear scale linearScaler = Qwt.QwtLinearScaleEngine() linearScaler.setAttributes(self.attributes()) linearScaler.setReference(self.reference()) linearScaler.setMargins(self.lowerMargin(), self.upperMargin()) return linearScaler.divideScale(x1, x2, maxMajSteps, maxMinSteps, stepSize) stepSize = abs(stepSize) if stepSize == 0.: if maxMajSteps < 1: maxMajSteps = 1 stepSize = self.divideInterval( self.log2(interval).width(), maxMajSteps) if stepSize < 1.: stepSize = 1. # major step must be >= 1 decade scaleDiv = Qwt.QwtScaleDiv() if stepSize <> 0.: ticks = self.buildTicks(interval, stepSize, maxMinSteps) scaleDiv = Qwt.QwtScaleDiv(interval, ticks[0], ticks[1], ticks[2]) if x1 > x2: scaleDiv.invert() return scaleDiv
def autoScale(self, maxNumSteps, x1, x2): if x1 > x2: qswap(x1, x2) base = 2. interval = Qwt.QwtDoubleInterval(x1 / pow(base, self.lowerMargin()), x2 * pow(base, self.upperMargin())) logRef = 1. if self.reference() > LOG2_MIN / 2: logRef = min(self.reference(), LOG2_MAX / 2) if self.testAttribute(Qwt.QwtScaleEngine.Symmetric): delta = max(interval.maxValue() / logRef, logRef / interval.minValue()) interval.setInterval(logRef / delta, logRef * delta) if self.testAttribute(Qwt.QwtScaleEngine.IncludeReference): interval = interval.extend(logRef) interval = interval.limited(LOG2_MIN, LOG2_MAX) if interval.width() == 0.: interval = self.buildInterval(interval.minValue()) stepSize = self.divideInterval( self.log2(interval).width(), max(maxNumSteps, 1)) if stepSize < 1.: stepSize = 1. if not self.testAttribute(Qwt.QwtScaleEngine.Floating): interval = self.align(interval, stepSize) x1 = interval.minValue() x2 = interval.maxValue() if self.testAttribute(Qwt.QwtScaleEngine.Inverted): qSwap(x1, x2) stepSize = -stepSize return (x1, x2, stepSize)
def make(): demo = Qwt.QwtPlot() demo.setCanvasBackground(Qt.Qt.white) demo.setTitle("Histogram") grid = Qwt.QwtPlotGrid() grid.enableXMin(True) grid.enableYMin(True) grid.setMajPen(Qt.QPen(Qt.Qt.black, 0, Qt.Qt.DotLine)) grid.setMinPen(Qt.QPen(Qt.Qt.gray, 0, Qt.Qt.DotLine)) grid.attach(demo) histogram = HistogramItem() histogram.setColor(Qt.Qt.darkCyan) numValues = 20 intervals = [] values = Qwt.QwtArrayDouble(numValues) pos = 0.0 for i in range(numValues): width = 5 + random.randint(0, 4) value = random.randint(0, 99) intervals.append(Qwt.QwtDoubleInterval(pos, pos + width)) values[i] = value pos += width histogram.setData(Qwt.QwtIntervalData(intervals, values)) histogram.attach(demo) demo.setAxisScale(Qwt.QwtPlot.yLeft, 0.0, 100.0) demo.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, pos) demo.replot() demo.resize(600, 400) demo.show() return demo
def range(self): return Qwt.QwtDoubleInterval(self.sp.min(), self.sp.max())
def prepare_palette(self): self.colors = numpy.zeros((256)) for i in range(0, 256): self.colors[i] = self.colorMap.rgb(Qwt.QwtDoubleInterval(0, 255), i)
def log2(self, interval): base = 2. return Qwt.QwtDoubleInterval(math.log(interval.minValue(), base), math.log(interval.maxValue(), base))
def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize): ''' Reimplements Qwt5.QwtLinearScaleEngine.divideScale **Important**: The stepSize parameter is **ignored**. :return: (Qwt5.QwtScaleDiv) a scale division whose ticks are aligned with the natural time units ''' #if stepSize != 0: # scaleDiv = Qwt5.QwtLinearScaleEngine.divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize) # scaleDiv.datetimeLabelFormat = "%Y/%m/%d %H:%M%S.%f" # return scaleDiv interval = Qwt5.QwtDoubleInterval(x1, x2).normalized() if interval.width() <= 0: return Qwt5.QwtScaleDiv() dt1 = datetime.fromtimestamp(interval.minValue()) dt2 = datetime.fromtimestamp(interval.maxValue()) if dt1.year < 1900 or dt2.year > 9999: #limits in time.mktime and datetime return Qwt5.QwtScaleDiv() majticks = [] medticks = [] minticks = [] dx = interval.width() #if dx > 63072001: # = 3600s*24*(365+366) = 2 years (counting a leap year) # format = "%Y" # for y in range(dt1.year+1,dt2.year): # dt = datetime(year=y, month=1, day=1) # majticks.append(mktime(dt.timetuple())) #elif dx > 5270400: # = 3600s*24*61 = 61 days # format = "%Y %b" # d = timedelta(days=31) # dt = dt1.replace(day=1, hour=0, minute=0, second=0, microsecond=0)+d # while(dt<dt2): # dt = dt.replace(day=1) #make sure that we are on day 1 (even if always sum 31 days) # majticks.append(mktime(dt.timetuple())) # dt += d #elif dx > 172800: # 3600s24*2 = 2 days # put this back in if dx > 86400: # 1 day format = "%m-%d %H:%M" d = timedelta(hours=1) dt = dt1.replace(hour=0, minute=0, second=0, microsecond=0) + d while (dt < dt2): if dt.hour >= 9 and dt.hour <= 16: majticks.append(mktime(dt.timetuple())) dt += d #elif dx > 7200: # 3600s*2 = 2hours # format = "%b/%d-%Hh" # d = timedelta(hours=1) # dt = dt1.replace(minute=0, second=0, microsecond=0) + d # while(dt<dt2): # majticks.append(mktime(dt.timetuple())) # dt += d #elif dx > 1200: # 60s*20 =20 minutes # format = "%H:%M" # d = timedelta(minutes=10) # dt = dt1.replace(minute=(dt1.minute//10)*10, second=0, microsecond=0) + d # while(dt<dt2): # majticks.append(mktime(dt.timetuple())) # dt += d #elif dx > 120: # =60s*2 = 2 minutes else: format = "%H:%M" d = timedelta(hours=1) dt = dt1.replace(minute=0, second=0, microsecond=0) + d while (dt < dt2): majticks.append(mktime(dt.timetuple())) dt += d #elif dx > 20: # 20 s # format = "%H:%M:%S" # d = timedelta(seconds=10) # dt = dt1.replace(second=(dt1.second//10)*10, microsecond=0) + d # while(dt<dt2): # majticks.append(mktime(dt.timetuple())) # dt += d #elif dx > 2: # 2s # format = "%H:%M:%S" # majticks=range(int(x1)+1, int(x2)) #else: #less than 2s (show microseconds) # scaleDiv = Qwt5.QwtLinearScaleEngine.divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize) # self.scaleDraw().setDatetimeLabelFormat("%S.%f") # return scaleDiv #make sure to comply with maxMajTicks L = len(majticks) if L > maxMajSteps: majticks = majticks[::int(np.ceil(float(L) / maxMajSteps))] scaleDiv = Qwt5.QwtScaleDiv(interval, minticks, medticks, majticks) self.scaleDraw().setDatetimeLabelFormat(format) if x1 > x2: scaleDiv.invert() ##START DEBUG #print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" #for tk in scaleDiv.ticks(scaleDiv.MajorTick): # print datetime.fromtimestamp(tk).isoformat() #print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ##END DEBUG return scaleDiv
def pow2(self, interval): base = 2. return Qwt.QwtDoubleInterval(math.pow(base, interval.minValue()), pow(base, interval.maxValue()))
def setspecrange(self, spec_min, spec_max): self.rightAxis.setColorMap( Qwt.QwtDoubleInterval(spec_min, spec_max), self.plotImage.canvasscaledspectrogram.colorMap) self.setAxisScale(Qwt.QwtPlot.yRight, spec_min, spec_max) self.replot()
def range(self): return Qwt5.QwtDoubleInterval(self.data.min(), self.data.max())
def __init__(self, module, *args): ''' Constructor @param module: parent module ''' apply(Qt.QDialog.__init__, (self, ) + args) self.setupUi(self) self.module = module self.params = None # last received parameter block self.data = None # last received data block # create table view grid (10x16 eeg electrodes + 1 row for ground electrode) cc = 10 rc = 16 self.tableWidgetValues.setColumnCount(cc) self.tableWidgetValues.setRowCount(rc + 1) self.tableWidgetValues.horizontalHeader().setResizeMode( Qt.QHeaderView.Stretch) self.tableWidgetValues.horizontalHeader().setDefaultAlignment( Qt.Qt.Alignment(Qt.Qt.AlignCenter)) self.tableWidgetValues.verticalHeader().setResizeMode( Qt.QHeaderView.Stretch) self.tableWidgetValues.verticalHeader().setDefaultAlignment( Qt.Qt.Alignment(Qt.Qt.AlignCenter)) # add ground electrode row self.tableWidgetValues.setSpan(rc, 0, 1, cc) # row headers rheader = Qt.QStringList() for r in xrange(rc): rheader.append("%d - %d" % (r * cc + 1, r * cc + cc)) rheader.append("GND") self.tableWidgetValues.setVerticalHeaderLabels(rheader) # create cell items fnt = Qt.QFont() fnt.setPointSize(8) for r in xrange(rc): for c in xrange(cc): item = Qt.QTableWidgetItem() item.setTextAlignment(Qt.Qt.AlignCenter) item.setFont(fnt) self.tableWidgetValues.setItem(r, c, item) # GND electrode cell item = Qt.QTableWidgetItem() item.setTextAlignment(Qt.Qt.AlignCenter) item.setFont(fnt) item.setText("GND") self.tableWidgetValues.setItem(rc, 0, item) self.defaultColor = item.backgroundColor() # set range list self.comboBoxRange.clear() self.comboBoxRange.addItem("15") self.comboBoxRange.addItem("50") self.comboBoxRange.addItem("100") self.comboBoxRange.addItem("500") # set validators validator = Qt.QIntValidator(self) validator.setBottom(15) validator.setTop(500) self.comboBoxRange.setValidator(validator) self.comboBoxRange.setEditText(str(self.module.range_max)) # setup color scale self.linearscale = False self.scale_engine = Qwt.QwtLinearScaleEngine() self.scale_interval = Qwt.QwtDoubleInterval(0, self.module.range_max) self.scale_map = Qwt.QwtLinearColorMap(Qt.Qt.green, Qt.Qt.red) if self.linearscale: self.scale_map.addColorStop(0.45, Qt.Qt.yellow) self.scale_map.addColorStop(0.55, Qt.Qt.yellow) self.scale_map.setMode(Qwt.QwtLinearColorMap.ScaledColors) else: self.scale_map.addColorStop(0.33, Qt.Qt.yellow) self.scale_map.addColorStop(0.66, Qt.Qt.red) self.scale_map.setMode(Qwt.QwtLinearColorMap.FixedColors) self.ScaleWidget.setColorMap(self.scale_interval, self.scale_map) self.ScaleWidget.setColorBarEnabled(True) self.ScaleWidget.setColorBarWidth(30) self.ScaleWidget.setBorderDist(10, 10) # set default values self.setColorRange(0, self.module.range_max) self.checkBoxValues.setChecked(self.module.show_values) # actions self.connect(self.comboBoxRange, Qt.SIGNAL("editTextChanged(QString)"), self._rangeChanged) self.connect(self.checkBoxValues, Qt.SIGNAL("stateChanged(int)"), self._showvalues_changed) self.connect(self.module, Qt.SIGNAL('update(PyQt_PyObject)'), self._updateValues)
def range(self): return Qwt.QwtDoubleInterval(0.0, 10.0)
def range(self): # print "MIN CONTOUR = ", math.floor(self.intes_array.min()) return Qwt.QwtDoubleInterval(int(self.intes_array.min()), math.ceil(self.intes_array.max()))