Exemplo n.º 1
0
    def __init__(self, parent=None):

        Qwt.QwtPlot.__init__(self, parent)
        self.__spectrogram = Qwt.QwtPlotSpectrogram()

        self.zoomer = Qwt.QwtPlotZoomer(self.canvas())
        self.zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect2,
                                    Qt.Qt.RightButton, Qt.Qt.ControlModifier)
        self.zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect3,
                                    Qt.Qt.RightButton)
        self.zoomer.setRubberBandPen(Qt.Qt.darkBlue)
        self.zoomer.setTrackerPen(Qt.Qt.darkBlue)

        xmin = -10
        ymin = -10
        xmax = 10
        ymax = 10
        x_a = []
        y_a = []
        intes = []
        for x in np.linspace(xmin, xmax, 50):
            for y in np.linspace(ymin, ymax, 50):
                x_a.append(x)
                y_a.append(y)  # I just used a random function from https://www.physicsforums.com/threads/cool-3-d-functions-for-graphing.140087/ to display
                # intes.append(x+y) # This is the actual function I used for testing. It is much simplier and you can tell where every point should be
                intes.append(max([-2*(round(math.e**(-(x*2)**2)) + round(math.e**(-(y*2)**2)))+ 2+2*math.cos((x**2+y**2)/4), 25*math.e**(-1*(x**2+y**2)*3)]))
        #
        # x_a = sorted(x_a, reverse= True)
        # y_a = sorted(y_a, reverse=True)
        intes = np.asarray(intes)



        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)

        # LeftButton for the zooming
        # MidButton for the panning
        # RightButton: zoom out by 1
        # Ctrl+RighButton: zoom out to full size
        #
        panner = Qwt.QwtPlotPanner(self.canvas())
        panner.setAxisEnabled(Qwt.QwtPlot.yRight, False)
        panner.setMouseButton(Qt.Qt.MidButton)

        # Avoid jumping when labels with more/less digits
        # appear/disappear when scrolling vertically
        #
        fm = Qt.QFontMetrics(self.axisWidget(Qwt.QwtPlot.yLeft).font())
        self.axisScaleDraw(
            Qwt.QwtPlot.yLeft).setMinimumExtent(fm.width("100.00"))
Exemplo n.º 2
0
    def __init__(self, parent=None):
        Qwt.QwtPlot.__init__(self, parent)
        self.__spectrogram = Qwt.QwtPlotSpectrogram()

        colorMap = Qwt.QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red)
        colorMap.addColorStop(0.1, Qt.Qt.cyan)
        colorMap.addColorStop(0.6, Qt.Qt.green)
        colorMap.addColorStop(0.95, Qt.Qt.yellow)

        self.__spectrogram.setColorMap(colorMap)

        self.__spectrogram.setData(SpectrogramData())
        self.__spectrogram.attach(self)

        self.__spectrogram.setContourLevels(
            [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5])

        rightAxis = self.axisWidget(Qwt.QwtPlot.yRight)
        rightAxis.setTitle("Intensity")
        rightAxis.setColorBarEnabled(True)
        rightAxis.setColorMap(self.__spectrogram.data().range(),
                              self.__spectrogram.colorMap())

        self.setAxisScale(Qwt.QwtPlot.yRight,
                          self.__spectrogram.data().range().minValue(),
                          self.__spectrogram.data().range().maxValue())
        self.enableAxis(Qwt.QwtPlot.yRight)

        self.plotLayout().setAlignCanvasToScales(True)
        self.replot()

        # LeftButton for the zooming
        # MidButton for the panning
        # RightButton: zoom out by 1
        # Ctrl+RighButton: zoom out to full size

        zoomer = Qwt.QwtPlotZoomer(self.canvas())
        zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect2,
                               Qt.Qt.RightButton, Qt.Qt.ControlModifier)
        zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect3,
                               Qt.Qt.RightButton)
        zoomer.setRubberBandPen(Qt.Qt.darkBlue)
        zoomer.setTrackerPen(Qt.Qt.darkBlue)

        panner = Qwt.QwtPlotPanner(self.canvas())
        panner.setAxisEnabled(Qwt.QwtPlot.yRight, False)
        panner.setMouseButton(Qt.Qt.MidButton)

        # Avoid jumping when labels with more/less digits
        # appear/disappear when scrolling vertically

        fm = Qt.QFontMetrics(self.axisWidget(Qwt.QwtPlot.yLeft).font())
        self.axisScaleDraw(Qwt.QwtPlot.yLeft).setMinimumExtent(
            fm.width("100.00"))
Exemplo n.º 3
0
 def new_element(self, key, element_type, **kwargs):
     # SHOULD CHECK TO SEE IF AN ELEMENT WITH THIS NAME ALREADY EXISTS!
     if key in self._elements:
         # an element with that key already exists
         # should raise an exception or warning
         pass
     else:
         if element_type == 'curve':
             new_pen = QtGui.QPen(QtCore.Qt.black)
             e = Qwt.QwtPlotCurve()
             e.setPen(new_pen)
             e.attach(self._widget)
             self._set_curve_properties(e, **kwargs)
         elif element_type == 'contours':
             pass
         elif element_type == 'image':
             e = Qwt.QwtPlotSpectrogram()
         self._elements[key] = (element_type, e)
Exemplo n.º 4
0
    def __init__(self, parent=None, **kwargs):
        """
        :Parameters:
            parent : QObject
                QT parent.
            cmap : tuple
                colormap tuples. [0] from (req.), [1] to (req), [2:] color stops
                as (stop, qt-color)
        """

        # super
        super(MatShow, self).__init__(parent)

        # layout
        self.plotLayout().setMargin(0)
        self.plotLayout().setCanvasMargin(0)
        self.plotLayout().setAlignCanvasToScales(True)
        self.setFrameStyle(QtGui.QFrame.NoFrame)
        self.setLineWidth(0)
        self.setCanvasLineWidth(0)
        self.setAutoReplot(False)

        # matplot
        cmap = kwargs.get('cmap', (QtCore.Qt.white, QtCore.Qt.blue))
        colmap = Qwt5.QwtLinearColorMap(cmap[0], cmap[1])
        if len(cmap) > 2:
            for item in cmap[2:]:
                colmap.addColorStop(item[0], item[1])
        self._mat = Qwt5.QwtPlotSpectrogram()
        self._mat.setColorMap(colmap)
        self._mat.attach(self)

        # matdata
        self._data = MatrixData()
        self._mat.setData(self._data)

        # axis and scales
        self.axisWidget(Qwt5.QwtPlot.yRight).setColorBarEnabled(True)
        self.enableAxis(Qwt5.QwtPlot.yRight, True)
        self.enableAxis(Qwt5.QwtPlot.yLeft, True)
        self.enableAxis(Qwt5.QwtPlot.xTop, False)
        self.enableAxis(Qwt5.QwtPlot.xBottom, True)
Exemplo n.º 5
0
    def __init__(self, *args, **kwargs):

        self.monitor = kwargs['monitor']
        del kwargs['monitor']

        self.VAR = kwargs['VAR']
        del kwargs['VAR']

        Qwt.QwtPlot.__init__(self, *args)
        self.contour = True
        self.__spectrogram = Qwt.QwtPlotSpectrogram()
        # LeftButton for the zooming
        # MidButton for the panning
        # RightButton: zoom out by 1
        # Ctrl+RighButton: zoom out to full size
        self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft,
                                        Qwt.QwtPicker.DragSelection,
                                        Qwt.QwtPicker.AlwaysOn, self.canvas())
        self.zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect2,
                                    Qt.Qt.RightButton, Qt.Qt.ControlModifier)
        self.zoomer.setMousePattern(Qwt.QwtEventPattern.MouseSelect3,
                                    Qt.Qt.RightButton)
        self.zoomer.setRubberBandPen(Qt.Qt.darkBlue)
        self.zoomer.setTrackerPen(Qt.Qt.darkBlue)

        if not hasattr(self, 'log'):
            self.log = False

        xmin = -10
        ymin = -10
        xmax = 10
        ymax = 10
        x_a = []
        y_a = []
        intes = []
        for x in np.linspace(xmin, xmax, 50):
            for y in np.linspace(ymin, ymax, 50):
                x_a.append(x)
                y_a.append(
                    y
                )  # I just used a random function from https://www.physicsforums.com/threads/cool-3-d-functions-for-graphing.140087/ to display
                # intes.append(x+y) # This is the actual function I used for testing. It is much simplier and you can tell where every point should be
                intes.append(
                    max([
                        -2 *
                        (round(math.e**(-(x * 2)**2)) + round(math.e**
                                                              (-(y * 2)**2))) +
                        2 + 2 * math.cos((x**2 + y**2) / 4),
                        25 * math.e**(-1 * (x**2 + y**2) * 3)
                    ]))

        self.plot(x_a, y_a, intes)

        panner = Qwt.QwtPlotPanner(self.canvas())
        panner.setAxisEnabled(Qwt.QwtPlot.yRight, False)
        panner.setMouseButton(Qt.Qt.MidButton)

        # Avoid jumping when labels with more/less digits
        # appear/disappear when scrolling vertically
        #
        fm = Qt.QFontMetrics(self.axisWidget(Qwt.QwtPlot.yLeft).font())
        self.axisScaleDraw(Qwt.QwtPlot.yLeft).setMinimumExtent(
            fm.width("100.00"))
Exemplo n.º 6
0
    def __init__(self, qapp, filename, options, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.gui = Ui_MainWindow()
        self.gui.setupUi(self)
                       
        self.filename = None
        self.block_length = options.block_length
        self.start = options.start
        self.sample_rate = options.sample_rate
        self.psdfftsize = options.psd_size
        self.specfftsize = options.spec_size
        self.winfunc = scipy.blackman
        self.sizeof_data = 8
        self.datatype = scipy.complex64
        self.pen_width = 1
        self.iq = list()
        self.time = list()

        # Set up basic plot attributes
        self.gui.timePlot.setAxisTitle(self.gui.timePlot.xBottom, "Time (sec)")
        self.gui.timePlot.setAxisTitle(self.gui.timePlot.yLeft, "Amplitude (V)")
        self.gui.freqPlot.setAxisTitle(self.gui.freqPlot.xBottom, "Frequency (Hz)")
        self.gui.freqPlot.setAxisTitle(self.gui.freqPlot.yLeft, "Magnitude (dB)")
        self.gui.specPlot.setAxisTitle(self.gui.specPlot.xBottom, "Frequency (Hz)")
        self.gui.specPlot.setAxisTitle(self.gui.specPlot.yLeft, "Time (sec)")

        # Set up FFT size combo box
        self.fftsizes = ["128", "256", "512", "1024", "2048",
                         "4096", "8192", "16384", "32768"]
        self.gui.psdFFTComboBox.addItems(self.fftsizes)
        self.gui.specFFTComboBox.addItems(self.fftsizes)
        pos = self.gui.psdFFTComboBox.findText(Qt.QString("%1").arg(self.psdfftsize))
        self.gui.psdFFTComboBox.setCurrentIndex(pos)
        pos = self.gui.specFFTComboBox.findText(Qt.QString("%1").arg(self.specfftsize))
        self.gui.specFFTComboBox.setCurrentIndex(pos)

        self.connect(self.gui.psdFFTComboBox,
                     Qt.SIGNAL("activated (const QString&)"),
                     self.psdFFTComboBoxEdit)
        self.connect(self.gui.specFFTComboBox,
                     Qt.SIGNAL("activated (const QString&)"),
                     self.specFFTComboBoxEdit)

        # Set up color scheme box
        self.color_modes = {"Black on White" : self.color_black_on_white,
                            "White on Black" : self.color_white_on_black,
                            "Blue on Black"  : self.color_blue_on_black,
                            "Green on Black" : self.color_green_on_black}
        self.gui.colorComboBox.addItems(self.color_modes.keys())
        pos = self.gui.colorComboBox.findText("Blue on Black")
        self.gui.colorComboBox.setCurrentIndex(pos)
        self.connect(self.gui.colorComboBox,
                     Qt.SIGNAL("activated (const QString&)"),
                     self.colorComboBoxEdit)
        
        
        # Set up line style combo box
        self.line_styles = {"None" : Qwt.QwtSymbol.NoSymbol,
                            "Circle" : Qwt.QwtSymbol.Ellipse,
                            "Diamond"  : Qwt.QwtSymbol.Rect,
                            "Triangle" : Qwt.QwtSymbol.Triangle}
        self.gui.lineStyleComboBox.addItems(self.line_styles.keys())
        pos = self.gui.lineStyleComboBox.findText("None")
        self.gui.lineStyleComboBox.setCurrentIndex(pos)
        self.connect(self.gui.lineStyleComboBox,
                     Qt.SIGNAL("activated (const QString&)"),
                     self.lineStyleComboBoxEdit)

        # Create zoom functionality for the plots
        self.timeZoomer = Qwt.QwtPlotZoomer(self.gui.timePlot.xBottom,
                                            self.gui.timePlot.yLeft,
                                            Qwt.QwtPicker.PointSelection,
                                            Qwt.QwtPicker.AlwaysOn,
                                            self.gui.timePlot.canvas())

        self.freqZoomer = Qwt.QwtPlotZoomer(self.gui.freqPlot.xBottom,
                                            self.gui.freqPlot.yLeft,
                                            Qwt.QwtPicker.PointSelection,
                                            Qwt.QwtPicker.AlwaysOn,
                                            self.gui.freqPlot.canvas())

        self.specZoomer = Qwt.QwtPlotZoomer(self.gui.specPlot.xBottom,
                                            self.gui.specPlot.yLeft,
                                            Qwt.QwtPicker.PointSelection,
                                            Qwt.QwtPicker.AlwaysOn,
                                            self.gui.specPlot.canvas())

        # Set up action when tab is changed
        self.connect(self.gui.tabGroup,
                     Qt.SIGNAL("currentChanged (int)"),
                     self.tabChanged)

        # Add a legend to the Time plot
        legend_real = Qwt.QwtLegend()
        self.gui.timePlot.insertLegend(legend_real)

        # Set up slider
        self.gui.plotHBar.setSingleStep(1)
        self.gui.plotHBar.setPageStep(self.block_length)
        self.gui.plotHBar.setMinimum(0)
        self.gui.plotHBar.setMaximum(self.block_length)
        self.connect(self.gui.plotHBar,
                     Qt.SIGNAL("valueChanged(int)"),
                     self.sliderMoved)

        # Connect Open action to Open Dialog box
        self.connect(self.gui.action_open,
                     Qt.SIGNAL("activated()"),
                     self.open_file)

        # Connect Reload action to reload the file
        self.connect(self.gui.action_reload,
                     Qt.SIGNAL("activated()"),
                     self.reload_file)
        self.gui.action_reload.setShortcut(QtGui.QApplication.translate("MainWindow", "Ctrl+R",
                                                                        None, QtGui.QApplication.UnicodeUTF8))

        # Set up file position boxes to update current figure
        self.connect(self.gui.filePosStartLineEdit,
                     Qt.SIGNAL("editingFinished()"),
                     self.file_position_changed)
        self.connect(self.gui.filePosStopLineEdit,
                     Qt.SIGNAL("editingFinished()"),
                     self.file_position_changed)
        self.connect(self.gui.filePosLengthLineEdit,
                     Qt.SIGNAL("editingFinished()"),
                     self.file_length_changed)

        self.connect(self.gui.fileTimeStartLineEdit,
                     Qt.SIGNAL("editingFinished()"),
                     self.file_time_changed)
        self.connect(self.gui.fileTimeStopLineEdit,
                     Qt.SIGNAL("editingFinished()"),
                     self.file_time_changed)
        self.connect(self.gui.fileTimeLengthLineEdit,
                     Qt.SIGNAL("editingFinished()"),
                     self.file_time_length_changed)

        stylestr = str(self.gui.lineStyleComboBox.currentText().toAscii())
        style = self.line_styles[stylestr]

        self.rcurve = Qwt.QwtPlotCurve("Real")
        self.icurve = Qwt.QwtPlotCurve("Imaginary")
        self.rsym = Qwt.QwtSymbol()
        self.rsym.setStyle(style)
        self.rsym.setSize(10)
        self.isym = Qwt.QwtSymbol()
        self.isym.setStyle(style)
        self.isym.setSize(10)
        self.rcurve.setSymbol(self.rsym)
        self.icurve.setSymbol(self.isym)


        self.icurve.attach(self.gui.timePlot)
        self.rcurve.attach(self.gui.timePlot)

        self.psdcurve = Qwt.QwtPlotCurve("PSD")
        self.psdcurve.attach(self.gui.freqPlot)

        # Set up specTab plot as a spectrogram
        self.specdata = SpectrogramData(range(0, 10), range(0, 10))

        colorMap = Qwt.QwtLinearColorMap(Qt.Qt.darkCyan, Qt.Qt.red)
        colorMap.addColorStop(0.1, Qt.Qt.cyan)
        colorMap.addColorStop(0.6, Qt.Qt.green)
        colorMap.addColorStop(0.95, Qt.Qt.yellow)

        self.spec = Qwt.QwtPlotSpectrogram()
        self.spec.setColorMap(colorMap)
        self.spec.attach(self.gui.specPlot)
        self.spec.setDisplayMode(Qwt.QwtPlotSpectrogram.ImageMode, True)
        self.spec.setData(self.specdata)

        self.rightAxis = self.gui.specPlot.axisWidget(Qwt.QwtPlot.yRight)
        self.rightAxis.setTitle("Magnitude (dBm)")
        self.rightAxis.setColorBarEnabled(True)
        self.rightAxis.setColorMap(self.spec.data().range(),
                                   self.spec.colorMap())
        self.gui.specPlot.enableAxis(Qwt.QwtPlot.yRight)

        # Set up initial color scheme
        self.color_modes["Blue on Black"]()

        # When line width spin box changes, update the pen size
        self.connect(self.gui.lineWidthSpinBox,
                     Qt.SIGNAL("valueChanged(int)"),
                     self.change_pen_width)
        self.gui.lineWidthSpinBox.setRange(1, 10)

        # When style size spin box changes, update the pen size
        self.connect(self.gui.styleSizeSpinBox,
                     Qt.SIGNAL("valueChanged(int)"),
                     self.change_style_size)
        self.gui.styleSizeSpinBox.setRange(1, 20)
        self.gui.styleSizeSpinBox.setValue(5)


        # Connect a signal for when the sample rate changes
        self.set_sample_rate(self.sample_rate)
        self.connect(self.gui.sampleRateLineEdit,
                     Qt.SIGNAL("editingFinished()"),
                     self.sample_rate_changed)

        if(filename is not None):
            self.initialize(filename)

        self.show()
Exemplo n.º 7
0
    def __init__(self, grblock, *args):
        Qwt.QwtPlot.__init__(self, *args)
        self.grblock = grblock
        self.scatter = np.zeros((self.grblock.nt, self.grblock.ntau))

        # set plot title
        self.setTitle('Scattering Function')

        # set plot layout
        self.plotLayout().setMargin(0)
        self.plotLayout().setCanvasMargin(0)
        self.plotLayout().setAlignCanvasToScales(True)

        # set legend
        legend = Qwt.QwtLegend()
        legend.setItemMode(Qwt.QwtLegend.ClickableItem)
        self.insertLegend(legend, Qwt.QwtPlot.RightLegend)

        # set axis titles
        self.setAxisTitle(Qwt.QwtPlot.xBottom, 'Delay (s)')
        self.setAxisTitle(Qwt.QwtPlot.yLeft, 'Doppler Spectrum (Hz)')

        # scale x-axis
        t_scale = time_scale(self.grblock.t_symbol)
        self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, t_scale)

        # scale y-axis
        f_scale = freq_scale(self.grblock.prf, self.grblock.nt)
        self.setAxisScaleDraw(Qwt.QwtPlot.yLeft, f_scale)

        # create a QwtRasterData instance to store the numpy array
        # produced by the GNU Radio Python sink block
        self.scatter_data = ScatterData(self.scatter)

        # create a QwtPlotSpectrogram instance to plot the QwtRasterData
        self.plot_scatter = Qwt.QwtPlotSpectrogram()

        # create a greyscale colormap
        colorMap = Qwt.QwtLinearColorMap(Qt.Qt.black, Qt.Qt.white)
        self.plot_scatter.setColorMap(colorMap)

        # attach and pass the data
        self.plot_scatter.attach(self)
        self.plot_scatter.setData(self.scatter_data)

        # replot
        self.replot()

        # zoomer
        self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft,
                                        Qwt.QwtPicker.DragSelection,
                                        Qwt.QwtPicker.AlwaysOff, self.canvas())
        self.zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.green))

        # picker showing the coordinates at the mouse pointer
        self.picker = QwtPlotPicker(self.grblock.t_symbol, self.grblock.nt,
                                    self.grblock.prf, Qwt.QwtPlot.xBottom,
                                    Qwt.QwtPlot.yLeft,
                                    Qwt.QwtPicker.PointSelection,
                                    Qwt.QwtPlotPicker.CrossRubberBand,
                                    Qwt.QwtPicker.AlwaysOn, self.canvas())
        self.picker.setTrackerPen(Qt.QPen(Qt.Qt.cyan))