def __init__(self, *args): Qwt.QwtPlot.__init__(self, *args) self.setCanvasBackground(Qt.Qt.white) #self.alignScales() # self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend); self.curve = Qwt.QwtPlotCurve('Unfiltered Spectrum') self.curve.setPen(Qt.QPen(Qt.Qt.red)) self.curve.attach(self) # Make 100 "gray" curves self.curve_gray = [] for i in xrange(50): curve = Qwt.QwtPlotCurve('Cumulative Filter Attenuation') if i > 0: curve.setItemAttribute(Qwt.QwtPlotItem.Legend, False) curve.setPen(Qt.QPen(Qt.Qt.gray)) curve.attach(self) self.curve_gray.append(curve) self.curve2 = Qwt.QwtPlotCurve('Filtered Spectrum') self.curve2.setPen(Qt.QPen(Qt.Qt.blue)) self.curve2.attach(self) self.curve3 = Qwt.QwtPlotCurve() self.curve3.setItemAttribute(Qwt.QwtPlotItem.Legend, False) self.curve3.setPen(Qt.QPen(Qt.Qt.green)) self.curve3.attach(self) self.curve_white = Qwt.QwtPlotCurve() self.curve_white.setItemAttribute(Qwt.QwtPlotItem.Legend, False) self.curve_white.setPen(Qt.QPen(Qt.Qt.white)) self.curve_white.attach(self) self.curve_green = Qwt.QwtPlotCurve('Mono Energy') self.curve_green.setPen(Qt.QPen(Qt.Qt.darkGreen)) self.curve_green.attach(self) mY = Qwt.QwtPlotMarker() mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop) mY.setLineStyle(Qwt.QwtPlotMarker.HLine) mY.setYValue(0.0) mY.attach(self) self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) self.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) # Add grid to plot grid = Qwt.QwtPlotGrid() pen = Qt.QPen(Qt.Qt.DotLine) pen.setColor(Qt.Qt.black) pen.setWidth(0) grid.setPen(pen) grid.attach(self)
def showAxisDialog(self): # todo : converting to double ... check b dialog = pyVacGraphAxesDialog(self) if type(self.axisScaleEngine(Qwt.QwtPlot.yLeft)) == type( Qwt.QwtLog10ScaleEngine()): dialog.ui.LogRadioButton_1.setChecked(True) else: dialog.ui.LinRadioButton_1.setChecked(True) if type(self.axisScaleEngine(Qwt.QwtPlot.yRight)) == type( Qwt.QwtLog10ScaleEngine()): dialog.ui.LogRadioButton_2.setChecked(True) else: dialog.ui.LinRadioButton_2.setChecked(True) if self.axisAutoScale(Qwt.QwtPlot.yLeft): dialog.ui.AutoRangeCheckBox_1.setChecked(True) if self.axisAutoScale(Qwt.QwtPlot.yRight): dialog.ui.AutoRangeCheckBox_2.setChecked(True) if dialog.exec_() == QDialog.Accepted: # Set the axes if dialog.ui.LogRadioButton_1.isChecked(): self.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) else: self.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLinearScaleEngine()) if dialog.ui.LogRadioButton_2.isChecked(): self.setAxisScaleEngine(Qwt.QwtPlot.yRight, Qwt.QwtLog10ScaleEngine()) else: self.setAxisScaleEngine(Qwt.QwtPlot.yRight, Qwt.QwtLinearScaleEngine()) if dialog.ui.AutoRangeCheckBox_1.isChecked(): self.setAxisAutoScale(Qwt.QwtPlot.yLeft) else: min, b = dialog.ui.MinLineEdit_1.text().toDouble() max, b = dialog.ui.MaxLineEdit_1.text().toDouble() self.setAxisScale(Qwt.QwtPlot.yLeft, min, max) if dialog.ui.AutoRangeCheckBox_2.isChecked(): self.setAxisAutoScale(Qwt.QwtPlot.yRight) else: min, b = dialog.ui.MinLineEdit_2.text().toDouble() max, b = dialog.ui.MaxLineEdit_2.text().toDouble() self.setAxisScale(Qwt.QwtPlot.yRight, min, max) self.replot()
def setlogfreqscale(self): self.logx = True self.horizontalScaleEngine = Qwt.QwtLog10ScaleEngine() self.horizontalScale.setScaleDiv( self.horizontalScaleEngine.transformation(), self.horizontalScaleEngine.divideScale(self.xmin, self.xmax, 8, 5)) self.needtransform = True self.draw()
def lock(self, state): if state == True: print "plotter lock scale" xScale = self.axisScaleDiv(Qwt.QwtPlot.xBottom) self.setAxisScaleDiv(Qwt.QwtPlot.xBottom, xScale) yScale = self.axisScaleDiv(Qwt.QwtPlot.yLeft) self.setAxisScaleDiv(Qwt.QwtPlot.yLeft, yScale) else: print "plotter unlock scale" self.setAxisAutoScale(Qwt.QwtPlot.xBottom) self.setAxisAutoScale(Qwt.QwtPlot.yLeft) self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) self.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine())
def preparePlot(self): """Prepare the plotting window""" if self.figure: return self.figure = Qwt.QwtPlot() self.figure.setCanvasBackground(Qt.Qt.white) self.figure.canvas().setFrameStyle(Qt.QFrame.Box | Qt.QFrame.Plain) self.figure.canvas().setLineWidth(1) for i in range(Qwt.QwtPlot.axisCnt): scaleWidget = self.figure.axisWidget(i) if scaleWidget: scaleWidget.setMargin(0) scaleDraw = self.figure.axisScaleDraw(i) if scaleDraw: scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Backbone, False) self.figure.setTitle("Figure: %d - %s" % (self.figNr, self.title)) self.figure.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend) self.figure.setAxisTitle(Qwt.QwtPlot.xBottom, "Time") self.figure.setAxisTitle(Qwt.QwtPlot.yLeft, self.ylabel) self.axis1 = Qwt.QwtPlot.yLeft if len(self.alternate) > 0: self.figure.enableAxis(Qwt.QwtPlot.yRight) self.figure.setAxisTitle(Qwt.QwtPlot.yRight, self.ylabel2) self.axis2 = Qwt.QwtPlot.yRight if self.spec.logscale: self.figure.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) if len(self.alternate) > 0: self.figure.setAxisScaleEngine(Qwt.QwtPlot.yRight, Qwt.QwtLog10ScaleEngine()) mY = Qwt.QwtPlotMarker() mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop) mY.setLineStyle(Qwt.QwtPlotMarker.HLine) mY.setYValue(0.0) mY.attach(self.figure) self.figure.resize(500, 300) self.figure.show()
def toggleLogScale(self): """Change the scale to base 10 or log scale.""" if self.logScaleAct.isChecked(): self.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.replot() else: self.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLinearScaleEngine()) self.replot()
def createSlider(self, parent, sliderType): if sliderType == 0: slider = Qwt.QwtSlider(parent, Qt.Qt.Horizontal, Qwt.QwtSlider.TopScale, Qwt.QwtSlider.BgTrough) slider.setThumbWidth(10) slider.setRange(-10.0, 10.0, 1.0, 0) # paging disabled return slider if sliderType == 1: slider = Qwt.QwtSlider(parent, Qt.Qt.Horizontal, Qwt.QwtSlider.NoScale, Qwt.QwtSlider.BgBoth) slider.setRange(0.0, 1.0, 0.01, 5) return slider if sliderType == 2: slider = Qwt.QwtSlider(parent, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) slider.setThumbWidth(25) slider.setThumbLength(12) slider.setRange(1000.0, 3000.0, 10.0, 10) return slider if sliderType == 3: slider = Qwt.QwtSlider(parent, Qt.Qt.Vertical, Qwt.QwtSlider.LeftScale, Qwt.QwtSlider.BgSlot) slider.setRange(0.0, 100.0, 1.0, 5) slider.setScaleMaxMinor(5) return slider if sliderType == 4: slider = Qwt.QwtSlider(parent, Qt.Qt.Vertical, Qwt.QwtSlider.NoScale, Qwt.QwtSlider.BgTrough) slider.setRange(0.0, 100.0, 1.0, 10) return slider if sliderType == 5: slider = Qwt.QwtSlider(parent, Qt.Qt.Vertical, Qwt.QwtSlider.RightScale, Qwt.QwtSlider.BgBoth) slider.setScaleEngine(Qwt.QwtLog10ScaleEngine()) slider.setThumbWidth(20) slider.setBorderWidth(1) slider.setRange(0.0, 4.0, 0.01) slider.setScale(1.0, 1.0e4) slider.setScaleMaxMinor(10) return slider return None
def checkbox_log_change(self, state): if state == QtCore.Qt.Checked: # Set plot to logarithmic self.qwtPlotFullScan.setAxisAutoScale(Qwt.QwtPlot.yLeft) self.qwtPlotFullScan.setAxisScaleEngine( Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) else: # Set plot to linear #self.qwtPlotFullScan.setAxisAutoScale(Qwt.QwtPlot.yLeft) self.qwtPlotFullScan.setAxisScaleEngine( Qwt.QwtPlot.yLeft, Qwt.QwtLinearScaleEngine()) self.qwtPlotFullScan.replot()
def log_check(self, log, replot=True): self.log = log min_intes = self.data.intes_array.min() max_intes = math.ceil(self.data.intes_array.max()) + 1.0 if log: # most of this is changing color scaling for logarithimc colorMap = Qwt.QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red) if min_intes <= 0: logmin = 0.01 else: logmin = min_intes self.setAxisScale(Qwt.QwtPlot.yRight, logmin, max_intes) oom = int( math.log10(max_intes) ) # for log scale we will add in colours depnding on order of magnatiude (oom) map = [[1.0 / (10**oom), Qt.Qt.cyan], [0.1, Qt.Qt.yellow], [0.01, Qt.Qt.darkGreen], [1.0 / (10**(oom - 1)), Qt.Qt.blue], [1.0 / (10**(oom - 2)), Qt.Qt.darkBlue], [1.0 / (10**(oom - 3)), Qt.Qt.green]] for i in range(oom): colorMap.addColorStop(map[i][0], map[i][1]) self.__spectrogram.setColorMap(colorMap) self.setAxisScaleEngine(Qwt.QwtPlot.yRight, Qwt.QwtLog10ScaleEngine()) else: colorMap = Qwt.QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red) self.setAxisScale(Qwt.QwtPlot.yRight, math.floor(min_intes), math.ceil(max_intes)) colorMap.addColorStop(0.25, Qt.Qt.cyan) colorMap.addColorStop(0.5, Qt.Qt.darkGreen) colorMap.addColorStop(0.75, Qt.Qt.yellow) self.setAxisScaleEngine(Qwt.QwtPlot.yRight, Qwt.QwtLinearScaleEngine()) self.__spectrogram.setColorMap(colorMap) self.__spectrogram.attach(self) rightAxis = self.axisWidget(Qwt.QwtPlot.yRight) rightAxis.setTitle("Intensity") rightAxis.setColorBarEnabled(True) rightAxis.setColorMap(self.__spectrogram.data().range(), self.__spectrogram.colorMap()) self.enableAxis(Qwt.QwtPlot.yRight) if replot: self.replot()
def __init__(self, *args): Qwt.QwtPlot.__init__(self, *args) self.setCanvasBackground(QColor("LightGrey")) self.colors = itertools.cycle([ Qt.red, Qt.green, Qt.blue, Qt.cyan, Qt.magenta, Qt.yellow, Qt.darkRed, Qt.darkGreen, Qt.darkBlue, Qt.darkCyan, Qt.darkMagenta, Qt.darkYellow ]) # legend self.legend = Qwt.QwtLegend() self.legend.setItemMode(Qwt.QwtLegend.ClickableItem) self.legend.setFrameStyle(QFrame.Box | QFrame.Sunken) self.insertLegend(self.legend, Qwt.QwtPlot.RightLegend) self.connect(self, SIGNAL("legendClicked(QwtPlotItem *)"), self.legendClicked) # Axes self.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.setAxisScaleEngine(Qwt.QwtPlot.yRight, Qwt.QwtLinearScaleEngine()) self.axisScaleEngine(Qwt.QwtPlot.yLeft).setAttribute( Qwt.QwtScaleEngine.Floating) self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time [h:m:s]") sd = TimeScaleDraw() self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, sd) self.enableAxis(Qwt.QwtPlot.yRight) # Setup list of plots to hold self.curve = {}
def setlogfreqscale(self): self.logfreqscale = True self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) self.update_xscale() self.needfullreplot = True
def setlog10freqscale(self): self.plotImage.erase() self.logfreqscale = 1 self.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.replot()
def setYAxisLogScale(self): self.pW.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.logScaleFlag = True
def __init__(self, *args): apply(Qwt.QwtKnob.__init__, (self, ) + args) self.setScaleEngine(Qwt.QwtLog10ScaleEngine())
def __init__(self, parent): DialogBase.__init__(self, "Adjust Contrast", ok=True, apply=True, cancel=True, user1=True, modal=False, parent=parent) self.parent = parent curDoc = self.parent.getCurrentDocument() # TESTING if curDoc.getURL == None: print "url is none" print curDoc.getURL() print curDoc.getURL().getFileName() # END TEST self.setWindowTitle("Adjust Contrast - " + str(curDoc.getURL().getFileName())) max = curDoc.getHistogram().shape[0] brightRange = curDoc.getBrightRange() self.setUser1ButtonText("Auto") w = QtGui.QWidget() layout = QtGui.QVBoxLayout() w.setLayout(layout) page = self.makeVBoxMainWidget() self.qhist1 = Qwt5.QwtPlot(Qwt5.QwtText("Entire Image")) layout.addWidget(self.qhist1) self.curve1 = Qwt5.QwtPlotCurve("Entire Image") self.curve1.attach(self.qhist1) self.curve1.setData( range(len(curDoc.getHistogram())), numpy.clip(curDoc.getHistogram(), 1, curDoc.getHistogram().max())) # set data and set zeros to ones because the logarithmic graphing does weird stuff with the zeros self.qhist1.setAxisTitle(Qwt5.QwtPlot.xBottom, "Pixel Value") self.qhist1.setAxisTitle(Qwt5.QwtPlot.yLeft, "Number of Pixels") self.qhist1.setAxisScaleEngine(Qwt5.QwtPlot.yLeft, Qwt5.QwtLog10ScaleEngine()) self.qhist1.replot() self.qhist2 = Qwt5.QwtPlot(Qwt5.QwtText("Selection")) layout.addWidget(self.qhist2) self.curve2 = Qwt5.QwtPlotCurve("Selection") self.curve2.attach(self.qhist2) tmpHist = curDoc.getHistogram() t2m = int(brightRange[0]) t2ma = int(brightRange[1] + 1) self.curve2.setData( range(t2m, t2ma), numpy.clip(tmpHist[t2m:t2ma], 1, tmpHist[t2m:t2ma].max())) self.qhist2.setAxisTitle(Qwt5.QwtPlot.xBottom, "Pixel Value") self.qhist2.setAxisTitle(Qwt5.QwtPlot.yLeft, "Number of Pixels") self.qhist2.setAxisScaleEngine(Qwt5.QwtPlot.yLeft, Qwt5.QwtLog10ScaleEngine()) self.qhist2.replot() # Blue marker historgram 1 self.blue1min = Qwt5.QwtPlotMarker() self.blue1min.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.blue1min.setLinePen(QtGui.QPen(Qt.blue, 1, Qt.DashDotLine)) self.blue1min.setValue(t2m, 1) self.blue1min.attach(self.qhist1) self.blue1max = Qwt5.QwtPlotMarker() self.blue1max.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.blue1max.setLinePen(QtGui.QPen(Qt.blue, 1, Qt.DashDotLine)) self.blue1max.setValue(t2ma, 1) self.blue1max.attach(self.qhist1) self.qhist1.replot() # Bluemarker histogram 2 self.blue2min = Qwt5.QwtPlotMarker() self.blue2min.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.blue2min.setLinePen(QtGui.QPen(Qt.blue, 1, Qt.DashDotLine)) self.blue2min.setValue(t2m, 1) self.blue2min.attach(self.qhist2) self.blue2max = Qwt5.QwtPlotMarker() self.blue2max.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.blue2max.setLinePen(QtGui.QPen(Qt.blue, 1, Qt.DashDotLine)) self.blue2max.setValue(t2ma, 1) self.blue2max.attach(self.qhist2) self.qhist2.replot() hlayout = QtGUI.QHBoxLayout() layout.addLayout(hlayout) minLabel = QtGui.QLabel("Min:") hlayout.addWidget(minLabel) self.minSlider = QtGui.QSlider() self.minSlider.setMinimum(0) self.minSlider.setMaximum(max) self.minSlider.setValue(brightRange[0]) self.minSlider.setOrientation(Qt.Horizontal) hlayout.addWidget(self.minSlider) layout.addWidget(w1) hlayout = QtGui.QHBoxLayout() layout.addLayout(hlayout) hlayout.addWidget(QtGui.QLabel("Max:")) self.maxSlider = QtGui.QSlider() self.maxSlider.setMinimum(0) self.maxSlider.setMaximum(max) self.maxSlider.setValue(brightRange[1]) self.maxSlider.setOrientation(Qt.Horizontal) hlayout.addWidget(self.maxSlider) hlayout = QtGui.QHBoxLayout() layout.addLayout(hlayout) self.allCheck = QtGui.QCheckBox("Changes Effect All Images") hlayout.addWidget(self.allCheck) # QLabel("Changes Effect All Images", bottomBox) hlayout = QtGui.QGridLayout() layout.addLayout(hlayout) hlayout.addWidget(QtGui.QLabel("Min:"), 0, 0) self.minSpinBox = QtGui.QSpinBox() self.minSpinBox.setMinimum(0) self.minSpinBox.setMaximum(max) self.minSpinBox.setValue(brightRange[0]) hlayout.addWidget(self.minSpinBox, 0, 1) hlayout.addWidget(QtGui.QLabel("Max:"), 1, 0) self.maxSpinBox = QSpinBox() self.maxSpinBox.setMinimum(0) self.maxSpinBox.setMaximum(max) self.maxSpinBox.setValue(brightRange[1]) self.minSlider.sliderMoved.connect(self.minSpinBox.setValue) self.maxSlider.sliderMoved.connect(self.maxSpinBox.setValue) self.minSpinBox.valueChanged.connect(self.minSlider.setValue) self.maxSpinBox.valueChanged.connect(self.maxSlider.setValue) self.minSpinBox.valueChanged.connect(self.slotChangeHist) self.maxSpinBox.valueChanged.connect(self.slotChangeHist) self.addWidget(w)
def setXAxisLogScale(self): self.pW.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) self.logScaleFlag = True
def updateGraph(self): if self.qcombo_units.currentIndex() == 0: bGraphIndBs = True else: bGraphIndBs = False # System sign: if self.qradio_signp.isChecked(): sign = 1 else: sign = -1 # add looping over many curves... print "updateGraph: %d curves in list." % (len(self.curve_mag_list)) for kCurve in range(len(self.curve_mag_list)): print "updateGraph: curve %d of %d." % (kCurve, len(self.curve_mag_list)) self.curve_phase_list[kCurve].setData( self.frequency_axis_list[kCurve], np.angle(sign * (self.transfer_function_list[kCurve])) ) # phase graph is usually just the phase of the transfer function, except for a few scalings if bGraphIndBs == True: self.curve_mag_list[kCurve].setData( self.frequency_axis_list[kCurve], 20 * np.log10(np.abs(self.transfer_function_list[kCurve]))) self.qplt_mag.setAxisTitle( Qwt.QwtPlot.yLeft, 'dB[(%s)^2]' % self.vertical_units_list[kCurve]) self.qplt_mag.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLinearScaleEngine()) else: if self.qcombo_units.currentIndex() == 2: # Linear real part self.curve_mag_list[kCurve].setData( self.frequency_axis_list[kCurve], (np.real(self.transfer_function_list[kCurve]))) self.qplt_mag.setAxisTitle( Qwt.QwtPlot.yLeft, '%s' % self.vertical_units_list[kCurve]) self.qplt_mag.setAxisScaleEngine( Qwt.QwtPlot.yLeft, Qwt.QwtLinearScaleEngine()) elif self.qcombo_units.currentIndex() == 3: # Linear imag part self.curve_mag_list[kCurve].setData( self.frequency_axis_list[kCurve], (np.imag(self.transfer_function_list[kCurve]))) self.qplt_mag.setAxisTitle( Qwt.QwtPlot.yLeft, '%s' % self.vertical_units_list[kCurve]) self.qplt_mag.setAxisScaleEngine( Qwt.QwtPlot.yLeft, Qwt.QwtLinearScaleEngine()) elif self.qcombo_units.currentIndex() == 1: # linear magnitude and phase self.curve_mag_list[kCurve].setData( self.frequency_axis_list[kCurve], (np.abs(self.transfer_function_list[kCurve]))) self.qplt_mag.setAxisTitle( Qwt.QwtPlot.yLeft, '%s' % self.vertical_units_list[kCurve]) self.qplt_mag.setAxisScaleEngine( Qwt.QwtPlot.yLeft, Qwt.QwtLinearScaleEngine()) elif self.qcombo_units.currentIndex() == 4: # 'Ohms, 50*Vin/Vout' Zsource = 50 test_impedance = (Zsource / (self.transfer_function_list[kCurve])) self.curve_mag_list[kCurve].setData( self.frequency_axis_list[kCurve], np.abs(test_impedance)) self.qplt_mag.setAxisTitle(Qwt.QwtPlot.yLeft, 'Ohms') self.qplt_mag.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.curve_phase_list[kCurve].setData( self.frequency_axis_list[kCurve], np.angle(-sign * (test_impedance))) elif self.qcombo_units.currentIndex() == 5: # 'Ohms, shunt DUT']) Zsource = 50. Zinput = 50. load_impedance = ( Zsource * (self.transfer_function_list[kCurve] / (1 - self.transfer_function_list[kCurve]))) # load impedance consists of the impedance that we want to measure in parallel with 50 ohms so we need to invert this too load_admittance = 1 / load_impedance unknown_admittance = load_admittance - 1 / Zinput unknown_impedance = 1 / unknown_admittance print load_admittance[0] print load_impedance[0] print unknown_admittance[0] print unknown_impedance[0] self.curve_mag_list[kCurve].setData( self.frequency_axis_list[kCurve], np.abs(unknown_impedance)) self.qplt_mag.setAxisTitle(Qwt.QwtPlot.yLeft, 'Ohms') self.qplt_mag.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.curve_phase_list[kCurve].setData( self.frequency_axis_list[kCurve], np.angle(sign * (unknown_impedance))) print kCurve print len(self.curve_mag_list) - 1 if kCurve == len(self.curve_mag_list) - 1: strNotes = '' for kFreq in range( len(self.frequency_axis_list[kCurve])): strNotes += '%.2e Hz: Z = %.2e + j*%.2e\n' % ( self.frequency_axis_list[kCurve][kFreq], np.real(unknown_impedance[kFreq]), np.imag(unknown_impedance[kFreq])) self.qedit_comment.setText(strNotes) print strNotes elif self.qcombo_units.currentIndex() == 6: # 'Ohms, Shunt DUT, high-Z probe + Series source impedance' try: Zsource = float(self.qedit_SeriesImpedance.text()) except: Zsource = 100e3 + 50. pass # load_impedance = (Zsource*(10.*self.transfer_function_list[kCurve]/(1-10.*self.transfer_function_list[kCurve]))) load_impedance = ( -Zsource * (10. * self.transfer_function_list[kCurve] / (10. * self.transfer_function_list[kCurve] - 1.))) self.curve_mag_list[kCurve].setData( self.frequency_axis_list[kCurve], np.abs(load_impedance)) self.qplt_mag.setAxisTitle(Qwt.QwtPlot.yLeft, 'Ohms') self.qplt_mag.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.curve_phase_list[kCurve].setData( self.frequency_axis_list[kCurve], np.angle(sign * (load_impedance))) if kCurve == len(self.curve_mag_list) - 1: strNotes = '' for kFreq in range( len(self.frequency_axis_list[kCurve])): strNotes += '%.2e Hz: Z = %.2e + j*%.2e\n' % ( self.frequency_axis_list[kCurve][kFreq], np.real(load_impedance[kFreq]), np.imag(load_impedance[kFreq])) self.qedit_comment.setText(strNotes) print "update curve complete." self.qplt_phase.setAxisTitle(Qwt.QwtPlot.yLeft, 'Phase [rad]') self.qplt_mag.replot() self.qplt_phase.replot()
def __init__(self, options, parent=None): QtGui.QMainWindow.__init__(self, parent) self.options = options # load and uic the file right away, no additional step necessary self.gui = uic.loadUi(os.path.join(os.path.dirname(__file__),'ofdm_mrrc_rx_gui_window.ui'), self) # GUI update timer self.update_timer = Qt.QTimer() # ZeroMQ self.probe_manager = zeromq.probe_manager() self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5555", 'float32', self.plot_snr) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5554", 'float32', self.plot_snr2) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5556", 'float32', self.plot_ber) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5557", 'float32', self.plot_freqoffset) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5553", 'float32', self.plot_freqoffset2) self.probe_manager.add_socket("tcp://"+self.options.tx_hostname+":4445", 'uint8', self.plot_rate) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5559", 'float32', self.plot_csi) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5558", 'float32', self.plot_csi2) self.probe_manager.add_socket("tcp://"+self.options.rx_hostname+":5560", 'complex64', self.plot_scatter) self.rpc_mgr_tx = zeromq.rpc_manager() self.rpc_mgr_tx.set_request_socket("tcp://"+self.options.tx_hostname+":6660") self.rpc_mgr_rx = zeromq.rpc_manager() self.rpc_mgr_rx.set_request_socket("tcp://"+self.options.rx_hostname+":5550") # Window Title self.gui.setWindowTitle("Receiver") #Plots self.gui.qwtPlotSNR.setAxisTitle(Qwt.QwtPlot.yLeft, "Rx 1 SNR[dB]") self.gui.qwtPlotSNR.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotSNR.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotSNR.setAxisScale(Qwt.QwtPlot.yLeft, 0, 30) self.snr_x = range(0,128) self.snr_y = [0.0] self.curve_snr = Qwt.QwtPlotCurve() self.curve_snr.setPen(Qt.QPen(Qt.Qt.red, 1)) self.curve_snr.setBrush(Qt.Qt.red) self.curve_snr.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_snr.attach(self.gui.qwtPlotSNR) #Plots self.gui.qwtPlotSNR2.setAxisTitle(Qwt.QwtPlot.yLeft, "Rx 2 SNR[dB]") self.gui.qwtPlotSNR2.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotSNR2.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotSNR2.setAxisScale(Qwt.QwtPlot.yLeft, 0, 30) self.snr2_x = range(0,128) self.snr2_y = [0.0] self.curve_snr2 = Qwt.QwtPlotCurve() self.curve_snr2.setPen(Qt.QPen(Qt.Qt.red, 1)) self.curve_snr2.setBrush(Qt.Qt.red) self.curve_snr2.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_snr2.attach(self.gui.qwtPlotSNR2) self.gui.qwtPlotBER.setAxisTitle(Qwt.QwtPlot.yLeft, "BER") self.gui.qwtPlotBER.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotBER.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotBER.setAxisScale(Qwt.QwtPlot.yLeft, 0.0001, 0.5) scale_engine = Qwt.QwtLog10ScaleEngine() self.gui.qwtPlotBER.setAxisScaleEngine(Qwt.QwtPlot.yLeft, scale_engine) self.ber_x = range(0,128) self.ber_y = [0.0] self.curve_ber = Qwt.QwtPlotCurve() self.curve_ber.setBaseline(1e-100) self.curve_ber.setPen(Qt.QPen(Qt.Qt.green, 1)) self.curve_ber.setBrush(Qt.Qt.green) self.curve_ber.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_ber.attach(self.gui.qwtPlotBER) self.gui.qwtPlotFreqoffset.setAxisTitle(Qwt.QwtPlot.yLeft, "RX 1 Frequency Offset") self.gui.qwtPlotFreqoffset.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotFreqoffset.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotFreqoffset.setAxisScale(Qwt.QwtPlot.yLeft, -1, 1) self.freqoffset_x = range(0,128) self.freqoffset_y = [0.0] self.curve_freqoffset = Qwt.QwtPlotCurve() self.curve_freqoffset.setPen(Qt.QPen(Qt.Qt.black, 1)) self.curve_freqoffset.attach(self.gui.qwtPlotFreqoffset) self.gui.qwtPlotFreqoffset2.setAxisTitle(Qwt.QwtPlot.yLeft, "RX 2 Frequency Offset") self.gui.qwtPlotFreqoffset2.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotFreqoffset2.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotFreqoffset2.setAxisScale(Qwt.QwtPlot.yLeft, -1, 1) self.freqoffset2_x = range(0,128) self.freqoffset2_y = [0.0] self.curve_freqoffset2 = Qwt.QwtPlotCurve() self.curve_freqoffset2.setPen(Qt.QPen(Qt.Qt.black, 1)) self.curve_freqoffset2.attach(self.gui.qwtPlotFreqoffset2) self.gui.qwtPlotRate.setAxisTitle(Qwt.QwtPlot.yLeft, "Datarate[Mbits/s]") self.gui.qwtPlotRate.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotRate.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotRate.setAxisScale(Qwt.QwtPlot.yLeft, 0, 10) self.rate_x = range(0,128) self.rate_y = [0]*len(self.rate_x) self.curve_rate = Qwt.QwtPlotCurve() self.curve_rate.setPen(Qt.QPen(Qt.Qt.lightGray, 1)) self.curve_rate.setBrush(Qt.Qt.lightGray) self.curve_rate.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_rate.attach(self.gui.qwtPlotRate) self.gui.qwtPlotCSI.setTitle("Rx 1 Normalized CTF") self.gui.qwtPlotCSI.setAxisTitle(Qwt.QwtPlot.xBottom, "Subcarrier") self.gui.qwtPlotCSI.setAxisScale(Qwt.QwtPlot.xBottom, -99, 100) self.gui.qwtPlotCSI.setAxisScale(Qwt.QwtPlot.yLeft, 0, 2) self.csi_x = range(-99,101) self.csi_y = [0]*len(self.csi_x) self.curve_csi = Qwt.QwtPlotCurve() self.curve_csi.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_csi.setBrush(Qt.Qt.blue) self.curve_csi.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_csi.attach(self.gui.qwtPlotCSI) self.gui.qwtPlotCSI2.setTitle("Rx 2 Normalized CTF") self.gui.qwtPlotCSI2.setAxisTitle(Qwt.QwtPlot.xBottom, "Subcarrier") self.gui.qwtPlotCSI2.setAxisScale(Qwt.QwtPlot.xBottom, -99, 100) self.gui.qwtPlotCSI2.setAxisScale(Qwt.QwtPlot.yLeft, 0, 2) #self.csi_x = range(-99,101) #self.csi_y = [0]*len(self.csi_x) self.curve_csi2 = Qwt.QwtPlotCurve() self.curve_csi2.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_csi2.setBrush(Qt.Qt.blue) self.curve_csi2.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_csi2.attach(self.gui.qwtPlotCSI2) self.gui.qwtPlotScatter.setTitle("Scatterplot (Subcarrier -99)") self.gui.qwtPlotScatter.setAxisTitle(Qwt.QwtPlot.xBottom, "I") self.gui.qwtPlotScatter.setAxisTitle(Qwt.QwtPlot.yLeft, "Q") self.gui.qwtPlotScatter.setAxisScale(Qwt.QwtPlot.xBottom, -1.5, 1.5) self.gui.qwtPlotScatter.setAxisScale(Qwt.QwtPlot.yLeft, -1.5, 1.5) self.scatter_buffer = numpy.complex64([0+0j]) self.curve_scatter = Qwt.QwtPlotCurve() self.curve_scatter.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_scatter.setStyle(Qwt.QwtPlotCurve.Dots) self.curve_scatter.attach(self.gui.qwtPlotScatter) self.marker = Qwt.QwtSymbol() self.marker.setStyle(Qwt.QwtSymbol.XCross) self.marker.setSize(Qt.QSize(3,3)) self.curve_scatter.setSymbol(self.marker) # plot picker self.plot_picker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.VLineRubberBand, Qwt.QwtPicker.AlwaysOff, self.gui.qwtPlotCSI.canvas(), #self.gui.qwtPlotCSI2.canvas() ) #Signals self.connect(self.update_timer, QtCore.SIGNAL("timeout()"), self.probe_manager.watcher) self.connect(self.gui.pushButtonMeasure, QtCore.SIGNAL("clicked()"), self.measure_average) self.connect(self.gui.pushButtonUpdate, QtCore.SIGNAL("clicked()"), self.update_modulation) self.connect(self.gui.horizontalSliderAmplitude, QtCore.SIGNAL("valueChanged(int)"), self.slide_amplitude) self.connect(self.gui.lineEditAmplitude, QtCore.SIGNAL("editingFinished()"), self.edit_amplitude) self.connect(self.gui.horizontalSliderOffset, QtCore.SIGNAL("valueChanged(int)"), self.slide_freq_offset) self.connect(self.gui.lineEditOffset, QtCore.SIGNAL("editingFinished()"), self.edit_freq_offset) self.connect(self.plot_picker, QtCore.SIGNAL("selected(const QwtDoublePoint &)"), self.subcarrier_selected) self.connect(self.gui.comboBoxChannelModel, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_channel_profile) # start GUI update timer self.update_timer.start(33) # get transmitter settings self.update_tx_params()
def plotSelection(self): if not self.measurementIsSelected() or not self.parameterIsSelected(): return # Clear already plotted Curves self.qwtPlot.detachItems() data = self.selectedParameterData() frequencies = self.currentProject().fft_frequencies() if self.useFrequencyRangeLimits: # We cast to float64 - equality on python-floats is a very risky thing lowerDisplayedFrequency = np.float64(self.dsbLowerDisplayedFrequency.value()) upperDisplayedFrequency = np.float64(self.dsbUpperDisplayedFrequency.value()) fftRes = self.currentProject().fft_resolution start_index = np.where(np.isclose(frequencies, lowerDisplayedFrequency))[0][0] stop_index = np.where(np.isclose(frequencies, upperDisplayedFrequency))[0][0] + 1 data = data[start_index:stop_index] frequencies = frequencies[start_index:stop_index] # Set Y Axis Title self.qwtPlot.setAxisTitle(Qwt5.QwtPlot.yLeft, self.selectedParameterName()) if self.graphConfig.showReal: curve = Qwt5.QwtPlotCurve('Realteil') curve.setData(frequencies, data.real) curve.setPen(QtGui.QPen(QtCore.Qt.red)) curve.setRenderHint(Qwt5.QwtPlotItem.RenderAntialiased) curve.attach(self.qwtPlot) if self.graphConfig.showImag: curve = Qwt5.QwtPlotCurve('Imaginaerteil') curve.setData(frequencies, data.imag) curve.setPen(QtGui.QPen(QtCore.Qt.yellow)) curve.setRenderHint(Qwt5.QwtPlotItem.RenderAntialiased) curve.attach(self.qwtPlot) if self.graphConfig.showAbs: curve = Qwt5.QwtPlotCurve('Betrag') curve.setData(frequencies, np.abs(data)) curve.setPen(QtGui.QPen(QtCore.Qt.blue)) curve.setRenderHint(Qwt5.QwtPlotItem.RenderAntialiased) curve.attach(self.qwtPlot) if self.graphConfig.showPhase: curve = Qwt5.QwtPlotCurve('Phase') if self.graphConfig.unwrapPhase: curve.setData(frequencies, np.unwrap(np.angle(data), self.graphConfig.unwrapDiscont)) else: curve.setData(frequencies, np.angle(data)) curve.setPen(QtGui.QPen(QtCore.Qt.green)) curve.setRenderHint(Qwt5.QwtPlotItem.RenderAntialiased) curve.attach(self.qwtPlot) # Build Legend legend = Qwt5.QwtLegend() legend.setFrameStyle(QtGui.QFrame.Box | QtGui.QFrame.Sunken) self.qwtPlot.insertLegend(legend, Qwt5.QwtPlot.RightLegend) # Set Axis Scaling if self.graphConfig.xAxisLinear: self.qwtPlot.setAxisScaleEngine(Qwt5.QwtPlot.xBottom, Qwt5.QwtLinearScaleEngine()) else: self.qwtPlot.setAxisScaleEngine(Qwt5.QwtPlot.xBottom, Qwt5.QwtLog10ScaleEngine()) if self.graphConfig.yAxisLinear: self.qwtPlot.setAxisScaleEngine(Qwt5.QwtPlot.yLeft, Qwt5.QwtLinearScaleEngine()) else: self.qwtPlot.setAxisScaleEngine(Qwt5.QwtPlot.yLeft, Qwt5.QwtLog10ScaleEngine()) # See this: http://stackoverflow.com/questions/14685010/qwt-plot-auto-scale-not-working self.qwtPlot.axisScaleEngine(Qwt5.QwtPlot.xBottom).setAttribute(Qwt5.QwtScaleEngine.Floating, True) self.qwtPlot.axisScaleEngine(Qwt5.QwtPlot.yLeft).setAttribute(Qwt5.QwtScaleEngine.Floating, True) self.qwtPlot.replot()
def initUI(self): # Add a first QwtPlot to the UI: self.qplt_mag = Qwt.QwtPlot() self.qplt_mag.setTitle('Magnitude response') self.qplt_mag.setCanvasBackground(Qt.Qt.white) self.qplt_mag.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) plot_grid = Qwt.QwtPlotGrid() plot_grid.setMajPen(Qt.QPen(Qt.Qt.black, 0, Qt.Qt.DotLine)) plot_grid.attach(self.qplt_mag) self.colors_order = [ [0.0000e+000, 114.0000e+000, 189.0000e+000], [217.0000e+000, 83.0000e+000, 25.0000e+000], [237.0000e+000, 177.0000e+000, 32.0000e+000], [126.0000e+000, 47.0000e+000, 142.0000e+000], [119.0000e+000, 172.0000e+000, 48.0000e+000], [77.0000e+000, 190.0000e+000, 238.0000e+000], [162.0000e+000, 20.0000e+000, 47.0000e+000], ] # Add a second QwtPlot to the UI: self.qplt_phase = Qwt.QwtPlot() self.qplt_phase.setTitle('Phase response') self.qplt_phase.setCanvasBackground(Qt.Qt.white) self.qplt_phase.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) plot_grid = Qwt.QwtPlotGrid() plot_grid.setMajPen(Qt.QPen(Qt.Qt.black, 0, Qt.Qt.DotLine)) plot_grid.attach(self.qplt_phase) # create the lists to hold the curve objects as they get added to the plots: self.curve_mag_list = [] self.curve_phase_list = [] ###################################################################### # Controls to adjust the model ###################################################################### # Units select units_label = Qt.QLabel('Units:') self.qcombo_units = Qt.QComboBox() self.qcombo_units.addItems([ 'dB', 'Linear', 'real part', 'imag part', 'Ohms, 50*Vin/Vout', 'Ohms, shunt DUT, 50 ohms probe', 'Ohms, Shunt DUT, high-Z probe + Series source impedance' ]) self.qcombo_units.setCurrentIndex(0) # self.qcombo_units.changeEvent.connect(self.updateGraph) self.qcombo_units.currentIndexChanged.connect(self.updateGraph) self.qlabel_SeriesImpedance = Qt.QLabel('Series Impedance [Ohms]:') self.qedit_SeriesImpedance = Qt.QLineEdit('100e3') self.qedit_SeriesImpedance.editingFinished.connect(self.updateGraph) self.qchk_display_model = Qt.QCheckBox('Display model') self.qchk_display_model.setChecked(False) self.qchk_DDCFilter = Qt.QCheckBox('DDC sinc filter') self.qchk_DDCFilter.clicked.connect(self.updateGraph) self.qradio_signp = Qt.QRadioButton('+ Sign') self.qradio_signp.setChecked(True) self.qradio_signn = Qt.QRadioButton('- Sign') button_group = Qt.QButtonGroup() button_group.addButton(self.qradio_signp) button_group.addButton(self.qradio_signn) self.qradio_signp.clicked.connect(self.updateGraph) self.qradio_signn.clicked.connect(self.updateGraph) # set the default DC gain to the value of the transfer function at the lowest frequency: self.qlabel_k = Qt.QLabel('DC Gain [dB]') self.qedit_k = Qt.QLineEdit(str(0)) self.qedit_k.setMaximumWidth(60) self.qedit_k.textChanged.connect(self.updateGraph) self.qlabel_f1 = Qt.QLabel('1st order poles') self.qedit_f1 = Qt.QLineEdit('20e3,600e3') self.qedit_f1.setMaximumWidth(120) self.qedit_f1.textChanged.connect(self.updateGraph) self.qlabel_f0 = Qt.QLabel('2nd order poles') self.qedit_f0 = Qt.QLineEdit('1.5e6') self.qedit_f0.setMaximumWidth(120) self.qedit_f0.textChanged.connect(self.updateGraph) self.qlabel_zeta = Qt.QLabel('zeta') self.qedit_zeta = Qt.QLineEdit('0.1') self.qedit_zeta.setMaximumWidth(120) self.qedit_zeta.textChanged.connect(self.updateGraph) self.qlabel_T = Qt.QLabel('Pure delay') self.qedit_T = Qt.QLineEdit('570e-9') self.qedit_T.setMaximumWidth(60) self.qedit_T.textChanged.connect(self.updateGraph) self.qchk_controller = Qt.QCheckBox('Closed-loop prediction') self.qchk_controller.clicked.connect(self.updateGraph) self.qlabel_pgain = Qt.QLabel('P gain [dB]') self.qedit_pgain = Qt.QLineEdit('-100') self.qedit_pgain.setMaximumWidth(60) self.qedit_pgain.textChanged.connect(self.updateGraph) self.qlabel_icorner = Qt.QLabel('I corner [Hz]') self.qedit_icorner = Qt.QLineEdit('0') self.qedit_icorner.setMaximumWidth(60) self.qedit_icorner.textChanged.connect(self.updateGraph) self.qedit_comment = Qt.QTextEdit('') # self.qedit_comment.setMaximumWidth(80) #self.qedit_comment.textChanged.connect(self.updateGraph) # Put all the widgets into a grid layout grid = Qt.QGridLayout() grid.addWidget(units_label, 0, 0) grid.addWidget(self.qcombo_units, 0, 1) grid.addWidget(self.qlabel_SeriesImpedance, 1, 0) grid.addWidget(self.qedit_SeriesImpedance, 1, 1) grid.addWidget(self.qchk_display_model, 2, 1) grid.addWidget(self.qradio_signp, 3, 0) grid.addWidget(self.qradio_signn, 3, 1) grid.addWidget(self.qlabel_k, 4, 0) grid.addWidget(self.qedit_k, 4, 1) grid.addWidget(self.qlabel_f1, 5, 0) grid.addWidget(self.qedit_f1, 5, 1) grid.addWidget(self.qlabel_f0, 6, 0) grid.addWidget(self.qedit_f0, 6, 1) grid.addWidget(self.qlabel_zeta, 7, 0) grid.addWidget(self.qedit_zeta, 7, 1) grid.addWidget(self.qlabel_T, 8, 0) grid.addWidget(self.qedit_T, 8, 1) grid.addWidget(self.qchk_controller, 9, 0, 1, 2) grid.addWidget(self.qlabel_pgain, 10, 0) grid.addWidget(self.qedit_pgain, 10, 1) grid.addWidget(self.qlabel_icorner, 12, 0) grid.addWidget(self.qedit_icorner, 12, 1) grid.addWidget(self.qchk_DDCFilter, 13, 0, 1, 2) grid.addWidget(self.qedit_comment, 14, 0, 1, 2) grid.setRowStretch(15, 0) # grid.addWidget(Qt.QLabel(''), 12, 0, 1, 2) # grid.setRowStretch(14, 1) vbox = Qt.QVBoxLayout() vbox.addWidget(self.qplt_mag) vbox.addWidget(self.qplt_phase) hbox = Qt.QHBoxLayout() hbox.addLayout(grid) hbox.addLayout(vbox, 1) # hbox.setStretch(2, 1) self.setLayout(hbox) # Adjust the size and position of the window self.resize(1200, 500) self.center() self.setWindowTitle('Transfer function #%d' % self.window_number) self.show()
def _init_logscales(self, left_log, right_log, right_plotlist): """Init log scales""" if left_log: self.setAxisScaleEngine(QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) if right_log and (right_plotlist is not None): self.setAxisScaleEngine(QwtPlot.yRight, Qwt.QwtLog10ScaleEngine())
def __init__(self, parent, logger): Qwt.QwtPlot.__init__(self) # store the logger instance self.logger = logger # we do not need caching self.canvas().setPaintAttribute(Qwt.QwtPlotCanvas.PaintCached, False) self.canvas().setPaintAttribute(Qwt.QwtPlotCanvas.PaintPacked, False) self.setAxisScale(Qwt.QwtPlot.yLeft, -140., 0.) xtitle = Qwt.QwtText('Frequency (Hz)') xtitle.setFont(QtGui.QFont(8)) self.setAxisTitle(Qwt.QwtPlot.xBottom, xtitle) # self.setAxisTitle(Qwt.QwtPlot.xBottom, 'Frequency (Hz)') ytitle = Qwt.QwtText('PSD (dB A)') ytitle.setFont(QtGui.QFont(8)) self.setAxisTitle(Qwt.QwtPlot.yLeft, ytitle) # self.setAxisTitle(Qwt.QwtPlot.yLeft, 'PSD (dB)') # attach a grid grid = Qwt.QwtPlotGrid() grid.enableXMin(True) grid.setMajPen(Qt.QPen(Qt.QPen(Qt.Qt.gray))) grid.setMinPen(Qt.QPen(Qt.QPen(Qt.Qt.lightGray))) grid.attach(self) self.needfullreplot = False self.setAxisScale(Qwt.QwtPlot.xBottom, 63., 16000.) #self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, ) self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) #try: # s = Qwt.QwtLog10ScaleEngine() # s.autoScale(1,1.,1.) #except: # print "The loaded PyQwt library has buggy QwtScaleEngine (and friends) SIP declarations" # print "... use a log10 scale engine instead of a log2 scale engine" # self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) #else: # self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, log2scale.CustomScaleEngine()) self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, FreqScaleDraw()) self.paint_time = 0. # picker used to display coordinates when clicking on the canvas self.picker = picker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.ActiveOnly, self.canvas()) # insert an additional plot item for the peak bar self.bar_peak = HistogramPeakBarItem() self.bar_peak.attach(self) self.peak = zeros((1,)) self.peak_int = 0 self.peak_decay = PEAK_DECAY_RATE self.histogram = HistogramItem() self.histogram.setColor(Qt.Qt.darkGreen) self.histogram.setBaseline(-200.) pos = [0.1, 1., 10.] self.histogram.setData(pos[:-1], pos[1:], pos[:-1]) self.histogram.attach(self) self.cached_canvas = self.canvas() # set the size policy to "Preferred" to allow the widget to be shrinked under the default size, which is quite big self.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) #need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.replot()
def __init__(self, parent, title, histData, rangePoints): QtGui.QWidget.__init__(self, parent) self.histData = histData min = 0 max = histData.shape[0] grid = QtGui.QGridLayout(self) self.graph = Qwt5.QwtPlot(Qwt5.QwtText(title)) grid.addWidget(self.graph, 0, 0) self.curve = Qwt5.QwtPlotCurve("Selection") self.curveFunc = Qwt5.QwtPlotCurve("SelectionFunc") self.curve.attach(self.graph) self.curveFunc.attach(self.graph) selectMin = int(rangePoints[0]) selectMax = int(rangePoints[1]) # if(selectMax < 1000): self.curve.setData( range(selectMin, selectMax), numpy.clip(histData[selectMin:selectMax + 1], 1, histData[selectMin:selectMax].max())) # else: # a=int(selectMax/1000) # sm=int(selectMin/a) # sx=int(selectMax/a) # self.curve.setData(range(sm, sx, a), self.histData[sm:sx]) # self.curveFunc.setData(range(selectMin,selectMax), numpy.array(range(0, selectMax-selectMin), numpy.float32)*255.0/(selectMax-selectMin)) self.graph.setAxisTitle(Qwt5.QwtPlot.xBottom, "Pixel Value") self.graph.setAxisTitle(Qwt5.QwtPlot.yLeft, "Number of Pixels") self.graph.setAxisScaleEngine(Qwt5.QwtPlot.yLeft, Qwt5.QwtLog10ScaleEngine()) # self.graph.enableAxis(Qwt5.QwtPlot.yRight) # self.graph.setAxisScale(Qwt5.QwtPlot.yRight, 0, 255) # Markers self.minMarker = Qwt5.QwtPlotMarker() self.minMarker.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.minMarker.setLinePen( QtGui.QPen(QtCore.Qt.blue, 1, QtCore.Qt.DashDotLine)) self.minMarker.setValue(selectMin, 1) self.minMarker.attach(self.graph) self.maxMarker = Qwt5.QwtPlotMarker() self.maxMarker.setLineStyle(Qwt5.QwtPlotMarker.VLine) self.maxMarker.setLinePen( QtGui.QPen(QtCore.Qt.blue, 1, QtCore.Qt.DashDotLine)) self.maxMarker.setValue(selectMax, 1) self.maxMarker.attach(self.graph) # Slider # XXX: Sliders shouldn't be so exact so could have a larger range than int. self.graph.replot() minLayout = QtGui.QHBoxLayout() grid.addLayout(minLayout, 1, 0) minLabel = QtGui.QLabel("Min:") minLayout.addWidget(minLabel) self.minSlider = QtGui.QSlider(QtCore.Qt.Horizontal) self.minSlider.setRange(0, max) self.minSlider.setValue(selectMin) minLayout.addWidget(self.minSlider) maxLayout = QtGui.QHBoxLayout() grid.addLayout(maxLayout, 2, 0) maxLabel = QtGui.QLabel("Max:") maxLayout.addWidget(maxLabel) self.maxSlider = QtGui.QSlider(QtCore.Qt.Horizontal) self.maxSlider.setRange(0, max) self.maxSlider.setValue(selectMax) maxLayout.addWidget(self.maxSlider) # Spin boxes spinLayout = QtGui.QHBoxLayout() grid.addLayout(spinLayout, 3, 0) spinMinLabel = QtGui.QLabel("Min:") spinLayout.addWidget(spinMinLabel) self.minSpinBox = QtGui.QSpinBox() self.minSpinBox.setMinimum(0) self.minSpinBox.setMaximum(max) self.minSpinBox.setValue(selectMin) spinLayout.addWidget(self.minSpinBox) spinLayout = QtGui.QHBoxLayout() spinMaxLabel = QtGui.QLabel("Max:") grid.addLayout(spinLayout, 4, 0) spinLayout.addWidget(spinMaxLabel) self.maxSpinBox = QtGui.QSpinBox() self.maxSpinBox.setMinimum(0) self.maxSpinBox.setMaximum(max) self.maxSpinBox.setValue(selectMax) spinLayout.addWidget(self.maxSpinBox) # Connect slider and spinbox together self.minSlider.sliderMoved.connect(self.minSpinBox.setValue) self.maxSlider.sliderMoved.connect(self.maxSpinBox.setValue) self.minSpinBox.valueChanged.connect(self.minSlider.setValue) self.maxSpinBox.valueChanged.connect(self.maxSlider.setValue) # Connect spinbox with histogram self.minSpinBox.valueChanged.connect(self.slotChangeHist) self.maxSpinBox.valueChanged.connect(self.slotChangeHist)
def initUI(self): # print('initUI()') # First create the plot: self.qplot_tf = Qwt.QwtPlot() # self.qplot_tf.enableAxis(Qwt.QwtPlot.xBottom, False) # self.qplot_tf.enableAxis(Qwt.QwtPlot.yLeft, False) self.qplot_tf.setMinimumHeight(100) self.qplot_tf.setCanvasBackground(Qt.Qt.white) self.qplot_tf.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLog10ScaleEngine()) #self.qplot_tf.setTitle('Loop filter #%d' % self.filter_number) qPolicy = Qt.QSizePolicy(Qt.QSizePolicy.Expanding, Qt.QSizePolicy.Expanding) # qPolicy.setHeightForWidth(True) self.qplot_tf.setSizePolicy(qPolicy) self.curve_0dB = Qwt.QwtPlotCurve() #FEATURE #self.curve_0dB.attach(self.qplot_tf) pen = Qt.QPen(Qt.Qt.DashLine) pen.setColor(Qt.Qt.black) self.curve_0dB.setPen(pen) self.curve_kp = Qwt.QwtPlotCurve() self.curve_kp.attach(self.qplot_tf) self.curve_kp.setPen(Qt.QPen(Qt.Qt.black)) self.curve_fi = Qwt.QwtPlotCurve() self.curve_fi.attach(self.qplot_tf) self.curve_fi.setPen(Qt.QPen(Qt.Qt.black)) self.curve_fii = Qwt.QwtPlotCurve() self.curve_fii.attach(self.qplot_tf) self.curve_fii.setPen(Qt.QPen(Qt.Qt.black)) self.curve_fd = Qwt.QwtPlotCurve() self.curve_fd.attach(self.qplot_tf) self.curve_fd.setPen(Qt.QPen(Qt.Qt.black)) self.curve_fdf = Qwt.QwtPlotCurve() self.curve_fdf.attach(self.qplot_tf) pen2 = Qt.QPen(Qt.Qt.DashLine) pen2.setColor(Qt.Qt.black) self.curve_fdf.setPen(pen2) self.curve_composite = Qwt.QwtPlotCurve() self.curve_composite.attach(self.qplot_tf) self.curve_composite.setPen(Qt.QPen(Qt.Qt.red)) self.curve_actual = Qwt.QwtPlotCurve() self.curve_actual.attach(self.qplot_tf) self.curve_actual.setPen(Qt.QPen(Qt.Qt.blue, 2)) # self.curve_0dB.setPen(self.qplot_tf) self.qlabel_spacerh = Qt.QLabel('') self.qlabel_spacerh.setMinimumWidth(30) self.qlabel_spacerh2 = Qt.QLabel('') self.qlabel_spacerh2.setMinimumWidth(7) self.qlabel_spacerv = Qt.QLabel('') self.qlabel_spacerv.setMinimumHeight(25) self.qchk_lock = Qt.QCheckBox('Lock On') self.qchk_lock.clicked.connect(self.updateGraph) self.qchk_lock.setEnabled(self.bDisplayLockChkBox) self.qchk_kp = Qt.QCheckBox('Kp On') self.qchk_kp.clicked.connect(self.updateGraph) self.qchk_kd = Qt.QCheckBox('Kd On') self.qchk_kd.clicked.connect(self.updateGraph) # Labels and controls to show the settings: self.qlabel_kp = Qt.QLabel('Kp:') self.qlabel_fi = Qt.QLabel('fi:') self.qlabel_fii = Qt.QLabel('fii:') self.qlabel_fd = Qt.QLabel('fd:') self.qlabel_fdf = Qt.QLabel('fdf:') self.qedit_kp = user_friendly_QLineEdit('-60') self.qedit_fi = user_friendly_QLineEdit('1e3') self.qedit_fii = user_friendly_QLineEdit('1e1') self.qedit_fd = user_friendly_QLineEdit('1e6') self.qedit_fdf = user_friendly_QLineEdit('1e6') self.qedit_kp.setMaximumWidth(60) self.qedit_fi.setMaximumWidth(60) self.qedit_fii.setMaximumWidth(60) self.qedit_fd.setMaximumWidth(60) self.qedit_fdf.setMaximumWidth(60) self.qedit_kp.returnPressed.connect(self.textboxChanged) self.qedit_fi.returnPressed.connect(self.textboxChanged) self.qedit_fii.returnPressed.connect(self.textboxChanged) self.qedit_fd.returnPressed.connect(self.textboxChanged) self.qedit_fdf.returnPressed.connect(self.textboxChanged) self.qchk_bKpCrossing = Qt.QCheckBox('fi refer to kp crossover') self.qchk_bKpCrossing.setChecked(False) self.qchk_bKpCrossing.clicked.connect(self.updateGraph) self.qchk_lockSlider = Qt.QCheckBox('Lock D sliders') self.qchk_lockSlider.setChecked(False) self.qchk_lockSlider.clicked.connect(self.lockSlider) self.slider_locked = False self.slider_ratio = 10 self.slider_inhibit = False # The sliders: self.qslider_kp = Qt.QSlider() self.qslider_fi = Qt.QSlider() self.qslider_fii = Qt.QSlider() self.qslider_fd = Qt.QSlider() self.qslider_fdf = Qt.QSlider() self.qslider_kp.setOrientation(Qt.Qt.Vertical) self.qslider_fi.setOrientation(Qt.Qt.Horizontal) self.qslider_fii.setOrientation(Qt.Qt.Horizontal) self.qslider_fd.setOrientation(Qt.Qt.Horizontal) self.qslider_fdf.setOrientation(Qt.Qt.Horizontal) # Set bounds: (kp, fi, fii, fd, fdf, fmin, fmax, gain_min, gain_max, bLock) = self.getSettings() # The fi and fii sliders will contain the value in 100*log10(f) units (similar to dBHz, but with a different scaling - this is because we can only use integer units) self.qslider_fi.setMinimum(100 * np.log10(fmin)) self.qslider_fii.setMinimum(100 * np.log10(fmin)) self.qslider_fd.setMinimum(100 * np.log10(fmin)) self.qslider_fdf.setMinimum(100 * np.log10(fmin)) self.qslider_fi.setMaximum(100 * np.log10(fmax)) self.qslider_fii.setMaximum(100 * np.log10(fmax)) self.qslider_fd.setMaximum(100 * np.log10(fmax)) self.qslider_fdf.setMaximum(100 * np.log10(fmax)) self.qslider_kp.setMinimum(10 * gain_min) self.qslider_kp.setMaximum(10 * gain_max) self.qslider_fi.setValue((100 * np.log10(fi))) self.qslider_fii.setValue((100 * np.log10(fii))) self.qslider_fd.setValue((100 * np.log10(fd))) self.qslider_fdf.setValue((100 * np.log10(fdf))) self.qslider_kp.setValue((10 * kp)) # print('10*gain_min = %f, 10*gain_min = %f, 10*kp = %f' % (10*gain_min, 10*gain_min, 10*kp)) self.qslider_kp.valueChanged.connect(self.kpSliderEvent) self.qslider_fi.valueChanged.connect(self.fiSliderEvent) self.qslider_fii.valueChanged.connect(self.fiiSliderEvent) self.qslider_fd.valueChanged.connect(self.fdSliderEvent) self.qslider_fdf.valueChanged.connect(self.fdfSliderEvent) # Put everything in a grid layout: grid = Qt.QGridLayout() #grid.addWidget(self.qplot_tf, 0, 3, 4, 3) # grid.setRowStretch(0, 1) #grid.setColumnStretch(4, 1) grid.addWidget(self.qplot_tf, 0, 6, 8, 3) grid.setColumnStretch(6, 1) #FEATURE #grid.addWidget(self.qchk_lock, 0, 0, 1, 2) grid.addWidget(Qt.QLabel(''), 1, 0, 1, 2) # spacer below the lock checkbox # grid.setRowStretch(1, 1) grid.addWidget(self.qlabel_kp, 3, 0) grid.addWidget(self.qlabel_fi, 4, 0) grid.addWidget(self.qlabel_fii, 5, 0) # grid.addWidget(self.qlabel_fd, 6, 0) # grid.addWidget(self.qlabel_fdf, 7, 0) grid.addWidget(self.qedit_kp, 3, 1, 1, 2) grid.addWidget(self.qedit_fi, 4, 1, 1, 2) grid.addWidget(self.qedit_fii, 5, 1, 1, 2) # grid.addWidget(self.qedit_fd, 6, 1, 1, 2) # grid.addWidget(self.qedit_fdf, 7, 1, 1, 2) grid.addWidget(self.qchk_bKpCrossing, 8, 0, 1, 3) # grid.addWidget(self.qchk_lockSlider, 8, 3, 1, 3) grid.addWidget(self.qslider_kp, 0, 2, 3, 1) grid.addWidget(self.qlabel_spacerv, 0, 2, 1, 1) grid.addWidget(self.qchk_kp, 2, 0, 1, 2) # grid.addWidget(self.qchk_kd, 2, 0, 1, 2) grid.addWidget(self.qlabel_spacerh, 4, 3, 1, 1) grid.addWidget(self.qslider_fi, 4, 3, 1, 1) grid.addWidget(self.qslider_fii, 5, 3, 1, 1) # grid.addWidget(self.qslider_fd, 6, 3, 1, 1) # grid.addWidget(self.qslider_fdf, 7, 3, 1, 1) grid.addWidget(self.qlabel_spacerh2, 4, 5, 1, 1) self.setLayout(grid) qPolicy = Qt.QSizePolicy(Qt.QSizePolicy.MinimumExpanding, Qt.QSizePolicy.MinimumExpanding) # qPolicy.setHeightForWidth(True) self.setSizePolicy(qPolicy)
def updateTransferFunctionDisplay(self): if hasattr(self, 'transfer_function_dictionary') == False: return # Get which curve we should be displaying: (input_select, output_select, first_modulation_frequency_in_hz, last_modulation_frequency_in_hz, number_of_frequencies, System_settling_time, output_amplitude) = self.readSystemIdentificationSettings() try: H_measured_openloop = -self.transfer_function_dictionary[ (input_select, output_select, 0)] freq_axis_openloop = self.transfer_freq_axis_dictionary[( input_select, output_select, 0)] except: H_measured_openloop = np.array((1, 1)) freq_axis_openloop = np.array((1, 1)) try: H_measured_fll = -self.transfer_function_dictionary[ (input_select, output_select, 1)] freq_axis_fll = self.transfer_freq_axis_dictionary[(input_select, output_select, 1)] except: H_measured_fll = np.array((1, 1)) freq_axis_fll = np.array((1, 1)) # Predicted closed-loop response: # Add the PLL loop filter's transfer function ###### TODO: Have the sl object return the loop filters' transfer function instead of re-deriving it everywhere. P_gain = 0 I_gain = 0 N_delay_p = 5 # TODO: put the correct values here N_delay_i = 6 # TODO: put the correct values here H_cumsum = 1 / ( 1 - np.exp(-1j * 2 * np.pi * freq_axis_openloop / self.sl.fs)) phase_ramp = 2 * np.pi * freq_axis_openloop / self.sl.fs H_controller = P_gain * np.exp( -1j * N_delay_p * phase_ramp) + I_gain * H_cumsum * np.exp( -1j * N_delay_i * phase_ramp) H_measured_openloop = H_measured_openloop * np.exp( 1j * 2 * np.pi * 3 * freq_axis_openloop / self.sl.fs ) # we cancel 3 samples delay because these come from the VNA itself H_measured_fll = H_measured_fll * np.exp( 1j * 2 * np.pi * 3 * freq_axis_fll / self.sl.fs ) # we cancel 3 samples delay because these come from the VNA itself H_predicted_fll = H_measured_openloop / ( 1 + H_measured_openloop * H_controller) if len(freq_axis_openloop) > 2: self.curve_openloop.setData( freq_axis_openloop, 20 * np.log10(np.abs(H_measured_openloop * H_controller))) self.curve_openloop_closed.setData( freq_axis_openloop, 20 * np.log10(np.abs(1 / (1 + H_measured_openloop * H_controller)))) # Handle the units # magnitude is currently in linear a linear scale units/units. # The units choices for the graph are: # self.qcombo_transfer_units.addItems(['dBunits/units', 'Hz/fullscale', 'Hz/V']) if self.qcombo_transfer_units.currentIndex() == 0: # dB units/units if len(freq_axis_openloop) > 2: self.curve_transfer_openloop.setData( freq_axis_openloop, 20 * np.log10(np.abs(H_measured_openloop))) self.curve_transfer_closedloop_predicted.setData( freq_axis_openloop, 20 * np.log10(np.abs(H_predicted_fll))) if len(freq_axis_fll) > 2: self.curve_transfer_closedloop.setData( freq_axis_fll, 20 * np.log10(np.abs(H_measured_fll))) self.qplt_transfer.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLinearScaleEngine()) self.qplt_transfer.setAxisTitle(Qwt.QwtPlot.yLeft, 'Gain [dBunits/units]') elif self.qcombo_transfer_units.currentIndex() == 1: # Hz/fullscale # 2**10 is the number of fractional bits on the phase, while 2**16 is the fullscale output range in counts conversion_factor = self.sl.fs / 2**10 * 2**16 if len(freq_axis_openloop) > 2: self.curve_transfer_openloop.setData( freq_axis_openloop, conversion_factor * (np.abs(H_measured_openloop))) self.curve_transfer_closedloop_predicted.setData( freq_axis_openloop, conversion_factor * (np.abs(H_predicted_fll))) if len(freq_axis_fll) > 2: self.curve_transfer_closedloop.setData( freq_axis_fll, conversion_factor * (np.abs(H_measured_fll))) # if len(H_closedloop) > 2: # self.curve_transfer_gainwithcontroller.setData(freq_axis, np.abs(H_closedloop) * conversion_factor) # else: # self.curve_transfer_gainwithcontroller.setData(freq_axis, magnitude * conversion_factor) self.qplt_transfer.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.qplt_transfer.setAxisTitle(Qwt.QwtPlot.yLeft, 'Gain [Hz/fullscale]') elif self.qcombo_transfer_units.currentIndex() == 2: # Hz/V, assumes 1V fullscale DAC output (which might be incorrect depending on which DAC and the output PGA gain setting) # 2**10 is the number of fractional bits on the phase, while 2**16 is the fullscale output range in counts # The 1 at the end represents 1V/fullscale conversion_factor = self.sl.fs / 2**10 * 2**16 * 1 if len(freq_axis_openloop) > 2: self.curve_transfer_openloop.setData( freq_axis_openloop, conversion_factor * (np.abs(H_measured_openloop))) self.curve_transfer_closedloop_predicted.setData( freq_axis_openloop, conversion_factor * (np.abs(H_predicted_fll))) if len(freq_axis_fll) > 2: self.curve_transfer_closedloop.setData( freq_axis_fll, conversion_factor * (np.abs(H_measured_fll))) # if len(H_closedloop) > 2: # self.curve_transfer_gainwithcontroller.setData(freq_axis, np.abs(H_closedloop) * conversion_factor) # else: # self.curve_transfer_gainwithcontroller.setData(freq_axis, magnitude * conversion_factor) self.qplt_transfer.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.qplt_transfer.setAxisTitle(Qwt.QwtPlot.yLeft, 'Gain [Hz/V]') # The phase is unaffected by the units, it is always in radians: self.curve_transfer_phase.setData(freq_axis_openloop, np.angle(H_measured_openloop)) # Refresh the display: self.qplt_transfer.replot() self.qplt_openloop.replot() return
def __init__(self, parent=None, epics_device_name=None): rga_base_class.__init__(self, parent) #super(QtGui.QMainWindow, self).__init__(parent) self.setupUi(self) self.connect(self, QtCore.SIGNAL('epics_connection_change()'), QtCore.SLOT('slot_epics_connection_changed()')) # Connect EPICS notification signals to slots self.epics_connection.connect(self.slot_epics_connected) self.epics_massmap_update.connect(self.slot_massmap_udate) self.epics_data.connect(self.slot_spectrum_update) self.rga_mode_change.connect(self.slot_rga_mode_change) print( "RgaControl.__init__: constructing rga_dlg <=================================================" ) #uic adds a function to our class called setupUi, calling this creates all the widgets from the .ui file self._redirname = "FE-QT4-GUI" self.__epics_device_name = epics_device_name self.setObjectName('rgaControlWindow') self.setWindowTitle("RGA Control") toolBar = QtGui.QToolBar(self) self.addToolBar(toolBar) printButton = QtGui.QToolButton(toolBar) printButton.setText("Print") printButton.setIcon(QtGui.QIcon(QtGui.QPixmap(print_xpm))) toolBar.addWidget(printButton) toolBar.addSeparator() self.__initZooming() #self.__barCurve = BarCurve() self.__barCurve = HistogramItem() # self.__barCurve.setItemAttribute(Qwt.QwtPlotItem.AutoScale, False) self.__barCurve.attach(self.qwtPlotFullScan) #self.__barCurve.setBaseline(-11.0) self.__barCurve.setBaseline(1.00e-11) self.__barCurve.setColor(QtGui.QColor('#00a000')) self.connect(printButton, QtCore.SIGNAL('clicked()'), self.print_plot) self.connect(self.checkBoxLog, QtCore.SIGNAL('stateChanged(int)'), self.checkbox_log_change) self.connect(self.ButtonPJSelect, QtCore.SIGNAL('clicked()'), self.clickedPJSelect) self.connect(self.ButtonPJST, QtCore.SIGNAL('clicked()'), self.clickedPJST) # __spectrum holds a dictionary of mass vs pressure self.__spectrum = RgaSpectrum() # EPICS stuff... # If we have been given a RGA device name then set the title text self._pv_mass_pressure = [] self._pv_mass_mass = [] self._pv_mass_label = [] for i in range(0, 16): self._pv_mass_mass.append(None) self._pv_mass_label.append(None) self._pv_mass_pressure.append(None) # PV for the :MASSMAP record self._pvkeyMasses = None self._pvkeyHeadCon = None self._pv_connected = False if self.__epics_device_name is not None: self.EPICSAppTitleWidget.setText(self.__epics_device_name) self.epics_connect() self.start_monitor_set() # Get the MASSMAP record data self._edm_process_pjstriptool = None # Instantiate the Peak Jump Masses selection dialogue, ready for showing when needed #self._pjmassdlg = pjmass_dlg.PeakJumpSelectDlg(self, self.__epics_device_name) PJMassDlg = pjmass_dlg.get_pjmass_dialogue_class() self._pjmassdlg = PJMassDlg( epics_device_name=self.__epics_device_name) # Connect the peak Jump masses selection dialogue 'changed' signal to local function self._pjmassdlg.pjchanged_signal.connect( self.on_pjmass_list_changed) # self.qwtPlotFullScan.setAxisTitle(Qwt.QwtPlot.xBottom, 'Atomic Mass') self.qwtPlotFullScan.setAxisTitle(Qwt.QwtPlot.yLeft, 'Pressure (mbar)') self.grid = Qwt.QwtPlotGrid() self.grid.attach(self.qwtPlotFullScan) self.grid.setPen(QtGui.QPen(QtCore.Qt.black, 0, QtCore.Qt.DotLine)) legend = Qwt.QwtLegend() legend.setItemMode(Qwt.QwtLegend.ClickableItem) self.qwtPlotFullScan.insertLegend(legend, Qwt.QwtPlot.RightLegend) self.qwtPlotFullScan.plotLayout().setCanvasMargin(0) self.qwtPlotFullScan.plotLayout().setAlignCanvasToScales(True) font = self.qwtPlotFullScan.axisFont(Qwt.QwtPlot.xBottom) font.setPointSize(8) self.qwtPlotFullScan.setAxisFont(Qwt.QwtPlot.xBottom, font) #self.qwtPlotFullScan.setAxisAutoScale(Qwt.QwtPlot.xBottom) self.qwtPlotFullScan.setAxisAutoScale(Qwt.QwtPlot.yLeft) self.qwtPlotFullScan.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine()) self.qwtPlotFullScan.setAxisMaxMinor(Qwt.QwtPlot.xBottom, 0) # attach a grid grid = Qwt.QwtPlotGrid() grid.enableXMin(True) grid.setMajPen(QtGui.QPen(QtGui.QPen(QtCore.Qt.gray))) grid.setMinPen(QtGui.QPen(QtGui.QPen(QtCore.Qt.lightGray))) grid.attach(self.qwtPlotFullScan) # picker used to display coordinates when clicking on the canvas self.qwtPlotFullScan.picker = RgaPicker( self.__spectrum, Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.CrossRubberBand, #Qwt.QwtPicker.ActiveOnly, Qwt.QwtPicker.AlwaysOn, self.qwtPlotFullScan.canvas()) self.qwtPlotFullScan.setAxisScaleDraw( Qwt.QwtPlot.xBottom, MassScaleDraw(self.__spectrum)) self.plot_spectrum() logger.debug( "{0:s}.__init__(): Base class: {1!r} Form class: {2!r}". format(self.__class__.__name__, rga_base_class, rga_form_class))
def __init__(self, options, parent=None): QtGui.QMainWindow.__init__(self, parent) self.options = options # load and uic the file right away, no additional step necessary self.gui = uic.loadUi( os.path.join(os.path.dirname(__file__), 'ofdm_rx_gui_window.ui'), self) # GUI update timer self.update_timer = Qt.QTimer() # ZeroMQ self.probe_manager = zeromq.probe_manager() self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5555", 'float32', self.plot_snr) self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5556", 'float32', self.plot_ber) if options.measurement: self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5556", 'float32', self.take_measurement) self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5557", 'float32', self.plot_freqoffset) self.probe_manager.add_socket( "tcp://" + self.options.tx_hostname + ":4445", 'uint8', self.plot_rate) self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5559", 'float32', self.plot_csi) self.probe_manager.add_socket( "tcp://" + self.options.rx_hostname + ":5560", 'complex64', self.plot_scatter) self.rpc_mgr_tx = zeromq.rpc_manager() self.rpc_mgr_tx.set_request_socket("tcp://" + self.options.tx_hostname + ":6660") self.rpc_mgr_rx = zeromq.rpc_manager() self.rpc_mgr_rx.set_request_socket("tcp://" + self.options.rx_hostname + ":5550") # Window Title self.gui.setWindowTitle("Receiver") #Plots self.gui.qwtPlotSNR.setAxisTitle(Qwt.QwtPlot.yLeft, "SNR[dB]") self.gui.qwtPlotSNR.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotSNR.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotSNR.setAxisScale(Qwt.QwtPlot.yLeft, 0, 30) self.snr_x = range(0, 128) self.snr_y = [0.0] self.curve_snr = Qwt.QwtPlotCurve() self.curve_snr.setPen(Qt.QPen(Qt.Qt.red, 1)) self.curve_snr.setBrush(Qt.Qt.red) self.curve_snr.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_snr.attach(self.gui.qwtPlotSNR) self.gui.qwtPlotBER.setAxisTitle(Qwt.QwtPlot.yLeft, "BER") self.gui.qwtPlotBER.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotBER.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotBER.setAxisScale(Qwt.QwtPlot.yLeft, 0.0001, 0.5) scale_engine = Qwt.QwtLog10ScaleEngine() self.gui.qwtPlotBER.setAxisScaleEngine(Qwt.QwtPlot.yLeft, scale_engine) self.ber_x = range(0, 128) self.ber_y = [0.0] self.curve_ber = Qwt.QwtPlotCurve() self.curve_ber.setBaseline(1e-100) self.curve_ber.setPen(Qt.QPen(Qt.Qt.green, 1)) self.curve_ber.setBrush(Qt.Qt.green) self.curve_ber.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_ber.attach(self.gui.qwtPlotBER) self.gui.qwtPlotFreqoffset.setAxisTitle(Qwt.QwtPlot.yLeft, "Frequency Offset") self.gui.qwtPlotFreqoffset.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotFreqoffset.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotFreqoffset.setAxisScale(Qwt.QwtPlot.yLeft, -1, 1) self.freqoffset_x = range(0, 128) self.freqoffset_y = [0.0] self.curve_freqoffset = Qwt.QwtPlotCurve() self.curve_freqoffset.setPen(Qt.QPen(Qt.Qt.black, 1)) self.curve_freqoffset.attach(self.gui.qwtPlotFreqoffset) self.gui.qwtPlotRate.setAxisTitle(Qwt.QwtPlot.yLeft, "Datarate[Mbits/s]") self.gui.qwtPlotRate.setAxisScale(Qwt.QwtPlot.xBottom, 0, 127) self.gui.qwtPlotRate.enableAxis(Qwt.QwtPlot.xBottom, False) self.gui.qwtPlotRate.setAxisScale(Qwt.QwtPlot.yLeft, 0, 10) self.rate_x = range(0, 128) self.rate_y = [0] * len(self.rate_x) self.curve_rate = Qwt.QwtPlotCurve() self.curve_rate.setPen(Qt.QPen(Qt.Qt.lightGray, 1)) self.curve_rate.setBrush(Qt.Qt.lightGray) self.curve_rate.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_rate.attach(self.gui.qwtPlotRate) self.gui.qwtPlotCSI.setTitle("Normalized Channel State Information") self.gui.qwtPlotCSI.setAxisTitle(Qwt.QwtPlot.xBottom, "Subcarrier") self.gui.qwtPlotCSI.setAxisScale(Qwt.QwtPlot.xBottom, -99, 100) self.gui.qwtPlotCSI.setAxisScale(Qwt.QwtPlot.yLeft, 0, 2) self.csi_x = range(-99, 101) self.csi_y = [0] * len(self.csi_x) self.curve_csi = Qwt.QwtPlotCurve() self.curve_csi.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_csi.setBrush(Qt.Qt.blue) self.curve_csi.setStyle(Qwt.QwtPlotCurve.Steps) self.curve_csi.attach(self.gui.qwtPlotCSI) self.gui.qwtPlotScatter.setTitle("Scatterplot (Subcarrier -99)") self.gui.qwtPlotScatter.setAxisTitle(Qwt.QwtPlot.xBottom, "I") self.gui.qwtPlotScatter.setAxisTitle(Qwt.QwtPlot.yLeft, "Q") self.gui.qwtPlotScatter.setAxisScale(Qwt.QwtPlot.xBottom, -1.5, 1.5) self.gui.qwtPlotScatter.setAxisScale(Qwt.QwtPlot.yLeft, -1.5, 1.5) self.scatter_buffer = numpy.complex64([0 + 0j]) self.curve_scatter = Qwt.QwtPlotCurve() self.curve_scatter.setPen(Qt.QPen(Qt.Qt.blue, 1)) self.curve_scatter.setStyle(Qwt.QwtPlotCurve.Dots) self.curve_scatter.attach(self.gui.qwtPlotScatter) self.marker = Qwt.QwtSymbol() self.marker.setStyle(Qwt.QwtSymbol.XCross) self.marker.setSize(Qt.QSize(3, 3)) self.curve_scatter.setSymbol(self.marker) # plot picker self.plot_picker = Qwt.QwtPlotPicker(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PointSelection, Qwt.QwtPlotPicker.VLineRubberBand, Qwt.QwtPicker.AlwaysOff, self.gui.qwtPlotCSI.canvas()) #Signals self.connect(self.update_timer, QtCore.SIGNAL("timeout()"), self.probe_manager.watcher) self.connect(self.gui.pushButtonMeasure, QtCore.SIGNAL("clicked()"), self.measure_average) #self.connect(self.gui.pushButtonUpdate, QtCore.SIGNAL("clicked()"), self.update_modulation) self.connect(self.gui.horizontalSliderAmplitude, QtCore.SIGNAL("valueChanged(int)"), self.slide_amplitude) self.connect(self.gui.lineEditAmplitude, QtCore.SIGNAL("editingFinished()"), self.edit_amplitude) self.connect(self.gui.horizontalSliderOffset, QtCore.SIGNAL("valueChanged(int)"), self.slide_freq_offset) self.connect(self.gui.lineEditOffset, QtCore.SIGNAL("editingFinished()"), self.edit_freq_offset) self.connect(self.plot_picker, QtCore.SIGNAL("selected(const QwtDoublePoint &)"), self.subcarrier_selected) self.connect(self.gui.comboBoxChannelModel, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_channel_profile) self.connect(self.gui.horizontalSliderTxGain, QtCore.SIGNAL("valueChanged(int)"), self.slide_tx_gain) self.connect(self.gui.horizontalSliderRxGain, QtCore.SIGNAL("valueChanged(int)"), self.slide_rx_gain) self.connect(self.gui.comboBoxScheme, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_allocation_scheme) self.connect(self.gui.horizontalSliderDataRate, QtCore.SIGNAL("valueChanged(int)"), self.slide_data_rate) self.connect(self.gui.lineEditDataRate, QtCore.SIGNAL("editingFinished()"), self.edit_data_rate) self.connect(self.gui.horizontalSliderGap, QtCore.SIGNAL("valueChanged(int)"), self.slide_gap) self.connect(self.gui.lineEditGap, QtCore.SIGNAL("editingFinished()"), self.edit_gap) self.connect(self.gui.horizontalSliderResourceBlockSize, QtCore.SIGNAL("valueChanged(int)"), self.slide_resource_block_size) self.connect(self.gui.lineEditResourceBlockSize, QtCore.SIGNAL("editingFinished()"), self.edit_resource_block_size) self.connect(self.gui.comboBoxResourceBlocksScheme, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_resource_block_scheme) self.connect(self.gui.comboBoxModulation, QtCore.SIGNAL("currentIndexChanged(QString)"), self.set_modulation_scheme) if options.measurement: self.rpc_mgr_tx.request("set_amplitude", [0.018]) self.rpc_mgr_tx.request("set_amplitude_ideal", [0.018]) self.i = 0 self.ii = 0 self.iii = 1 self.ber = 0.0 self.snr = 0.0 self.snrsum = 0.0 self.datarate = 0.0 self.ratesum = 0.0 self.dirname = "Simulation_" + strftime("%Y_%m_%d_%H_%M_%S", gmtime()) + "/" print self.dirname if not os.path.isdir("./" + self.dirname): os.mkdir("./" + self.dirname + "/") self.iter_points = 60 self.snr_points = 30 amp_min_log = numpy.log10(0.018**2) amp_max_log = numpy.log10(0.7**2) self.txpow_range = numpy.logspace(amp_min_log, amp_max_log, self.snr_points) self.meas_ber = 0.5 self.change_mod = 1 # start GUI update timer (33ms for 30 FPS) self.update_timer.start(33) # get transmitter settings self.update_tx_params()