Example #1
0
    def reset(self):
        self.first_update = True
        self.n = 0

        self.t = np.zeros(0)
        for var in self.data:
            self.data[var] = np.zeros(0)
Example #2
0
    def __init__(self, name, lines):
        self.name = name
        self.widget = Qwt.QwtPlot()
        self.widget.setCanvasBackground(Qt.Qt.white)
        #self.widget.setTitle(self.name)
        self.widget.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend);     
 
        self.lines = lines
        self.curves = {}
        self.data = {}

        grid = Qwt.QwtPlotGrid()
        grid.attach(self.widget)
        grid.setPen(Qt.QPen(Qt.Qt.black, 0, Qt.Qt.DotLine))

        self.t = np.zeros(0)
        
        for var, color in self.lines:
            self.data[var] = np.zeros(0)
            c = Qwt.QwtPlotCurve(var)
            c.setPen(Qt.QPen(color))
            c.attach(self.widget)
            self.curves[var] = c

        # in seconds, the amount of time on the x-axis.
        self.window = 120.0
        # the size of the shift (in seconds) when current time reaches the rhs of the graph.
        self.jump = 30.0
        # how close to the rhs before most recent sample must be before a shift occurs.
        self.jump_threshold = 0.1
        # how many samples to extend the arrays by when they run out of entries.
        self.extra_samples = 512
        
        self.first_update = True
Example #3
0
    def update_plot(self, new_t, new_vals):

        if self.first_update:            
            self.first_update = False
            self.n = 0            
            self.tmin = new_t
            self.tmax = self.tmin + self.window
            self.t = np.arange(self.tmin, self.tmax, 0.1)
            for var in self.data:
                self.data[var] = np.zeros(len(self.t))            
            self.widget.setAxisScale(Qwt.QwtPlot.xBottom, self.tmin, self.tmax)        

        self.t[self.n] = new_t

        for var, val in new_vals.iteritems():
            self.data[var][self.n] = val
            self.curves[var].setData(self.t[:self.n], self.data[var][:self.n])
            #self.curves[var].setData(self.t, self.data[var])

        if self.tmax - self.t[self.n] < self.jump_threshold:
            self.tmin += self.jump
            self.tmax += self.jump             
            self.widget.setAxisScale(Qwt.QwtPlot.xBottom, self.tmin, self.tmax)
            # drop old data the will not be displayed.
            # find the index of the largest value in self.t that is less than tmin.
            cut_index = len(np.nonzero(self.t[:self.n] < self.tmin)[0])
            debug("tmin=%f tmax=%f cut=%d n=%d -> %d array_lenth=%d" % (
                self.tmin, self.tmax, cut_index, self.n, self.n - cut_index, len(self.t)))

            self.t = self.t[cut_index:]
            for var in self.data:
                self.data[var] = self.data[var][cut_index:]
            self.n -= cut_index
            assert(self.t[self.n] == new_t)
        
        self.n += 1

        if self.n >= len(self.t):
            debug("Extending arrays by %d samples" % (self.extra_samples))
            self.t = np.concatenate((self.t, np.zeros(self.extra_samples)))
            for var in self.data:
                self.data[var] = np.concatenate((self.data[var], np.zeros(self.extra_samples)))

        #self.widget.setAxisScale(Qwt.QwtPlot.xBottom, t[-1]-10, t[-1])        
        self.widget.replot()
Example #4
0
def standard_map(x, y, kappa, n):
    if 'np' not in dir():
        import PyQt4.Qwt5.anynumpy as np
    xs = np.zeros(n, np.Float)
    ys = np.zeros(n, np.Float)
    for i in range(n):
        xs[i] = x
        ys[i] = y
        xn = y - kappa*np.sin(2.0*np.pi*x)
        yn = x + y
        if (xn > 1.0) or (xn < 0.0):
            x = xn - np.floor(xn)
        else:
            x = xn
        if (yn > 1.0) or (yn < 0.0):
            y = yn - np.floor(yn)
        else:
            y = yn
    return xs, ys
Example #5
0
 def addCurve(self, curveId, curveName):
     curveId = str(curveId)
     if self.curves.get(curveId):
         return
     curveObject = Qwt.QwtPlotCurve(curveName)
     curveObject.attach(self)
     curveObject.setPen(QPen(self.colors[len(self.curves.keys()) % len(self.colors)]))
     self.curves[curveId] = {
         'name': curveName,
         'data': zeros(self.dataNumValuesSaved),
         'object': curveObject,
     }
Example #6
0
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)

        self.lakeshore = lakeshore370.Lakeshore370(pad=13)
        self.time0 = time()
        self.timerstep = 500

        self.plot = DataPlot(self)
        self.plot.setMargin(5)

        self.setContextMenuPolicy(Qt.NoContextMenu)

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

        self.picker = QwtPlotPicker(
            QwtPlot.xBottom, QwtPlot.yLeft,
            QwtPicker.PointSelection | QwtPicker.DragSelection,
            QwtPlotPicker.CrossRubberBand, QwtPicker.AlwaysOn,
            self.plot.canvas())
        self.picker.setRubberBandPen(QPen(Qt.green))
        self.picker.setTrackerPen(QPen(Qt.red))

        self.central_widget = QWidget(self)
        self.setCentralWidget(self.central_widget)

        #self.setCentralWidget(self.plot)
        # Create the vertical layout widget
        self.layout_widget = QWidget(self.central_widget)
        self.layout = QVBoxLayout(self.central_widget)

        # Create the plot layout widget
        self.plot_layout_widget = QGroupBox("Plot", self.layout_widget)
        self.plot_layout = QHBoxLayout(self.plot_layout_widget)
        self.plot_layout_widget.setLayout(self.plot_layout)

        # Put the plot in the plot layout widget
        self.plot_layout.addWidget(self.plot)

        # Put plot layout widget in overall layout widget
        self.layout.addWidget(self.plot_layout_widget)

        #Buttons
        #Create the layout widget for the buttons
        self.buttons_layout_widget = QGroupBox("Buttons", self.layout_widget)
        self.buttons_layout = QHBoxLayout(self.buttons_layout_widget)
        self.buttons_layout_widget.setLayout(self.buttons_layout)

        #Create the buttons
        self.start_button = QPushButton('Start')
        self.stop_button = QPushButton('Stop')
        self.save_button = QPushButton('Save Data')
        self.resetDataButton = QPushButton('Reset Data')

        #Connect buttons to button events
        self.connect(self.start_button, SIGNAL("clicked()"), self.start_event)
        self.connect(self.stop_button, SIGNAL("clicked()"), self.stop_event)
        self.connect(self.save_button, SIGNAL("clicked()"), self.save_event)
        self.connect(self.resetDataButton, SIGNAL("clicked()"), self.resetData)

        #Add buttons to button layout
        self.buttons_layout.addWidget(self.start_button)
        self.buttons_layout.addWidget(self.stop_button)
        self.buttons_layout.addWidget(self.save_button)
        self.buttons_layout.addWidget(self.resetDataButton)

        # Add button layout to overall layout
        self.layout.addWidget(self.buttons_layout_widget)

        # Add GUI Actions
        # Exit Action
        exitAction = QtGui.QAction(QtGui.QIcon('icons/exitAction.png'), 'Exit',
                                   self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        self.connect(exitAction, QtCore.SIGNAL('triggered()'),
                     QtCore.SLOT('close()'))
        # Print Action
        printdata = QtGui.QAction(QtGui.QIcon('icons/exitAction.png'), 'Print',
                                  self)
        printdata.setShortcut('Ctrl+P')
        printdata.setStatusTip('Print data')
        self.connect(printdata, QtCore.SIGNAL('triggered()'), self.print_)
        # Export PDF Action
        exportpdfaction = QtGui.QAction(QtGui.QIcon('icons/exitAction.png'),
                                        'Export PDF', self)
        exportpdfaction.setStatusTip('Export Plot as PDF')
        self.connect(exportpdfaction, QtCore.SIGNAL('triggered()'),
                     self.exportPDF)

        # Add menubar
        menubar = self.menuBar()
        fileMenuItem = menubar.addMenu('&File')  #Add File Item
        fileMenuItem.addAction(printdata)
        fileMenuItem.addAction(exportpdfaction)
        fileMenuItem.addSeparator()
        fileMenuItem.addAction(exitAction)  #Add Exit

        # Toolbar
        # Create toolbar
        toolBar = QToolBar(self)
        # Add toolbar to main window
        self.addToolBar(toolBar)

        # Create button to toggle zoom on and off
        self.btnZoom = QToolButton(toolBar)
        self.btnZoom.setText("Zoom")
        self.btnZoom.setIcon(QIcon(QPixmap(zoom_xpm)))
        self.btnZoom.setCheckable(True)
        self.btnZoom.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(self.btnZoom)

        # Create e to autoscale
        btnautoscale = QToolButton(toolBar)
        btnautoscale.setText("Autoscale")
        btnautoscale.setIcon(QIcon(QPixmap(zoom_xpm)))
        btnautoscale.setCheckable(True)
        btnautoscale.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnautoscale)
        self.connect(btnautoscale, SIGNAL('toggled(bool)'), self.autoscale)
        btnautoscale.toggle()
        self.autoScaleOn = True
        #self.autoscale(True)

        toolBar.addSeparator()

        #Create  box for the timer button
        timerBox = QWidget(toolBar)
        #Create a loyout widget for the box
        timerBoxLayout = QHBoxLayout(timerBox)
        timerBoxLayout.setSpacing(0)
        timerBoxLayout.addWidget(QWidget(timerBox), 10)  # spacer
        timerBoxLayout.addWidget(QLabel("Time Between Samples (ms)", timerBox),
                                 0)
        timerBoxLayout.addSpacing(10)

        # Counter for Timing
        self.cntTimer = QwtCounter(timerBox)
        self.cntTimer.setRange(1, 100000, 1)
        self.cntTimer.setValue(self.timerstep)
        timerBoxLayout.addWidget(self.cntTimer, 10)

        # Add the box to timerBox to the toolbar
        toolBar.addWidget(timerBox)

        self.statusBar()

        self.zoom(False)
        self.showInfo()

        self.connect(self.cntTimer, SIGNAL('valueChanged(double)'),
                     self.setTimer)
        self.connect(self.btnZoom, SIGNAL('toggled(bool)'), self.zoom)
        self.connect(self.picker, SIGNAL('moved(const QPoint &)'), self.moved)
        self.connect(self.picker, SIGNAL('selected(const QaPolygon &)'),
                     self.selected)

        self.timeData = np.zeros(0, float)
        self.temperatureData = np.zeros(0, float)
        self.counter = 0.0
        self.phase = 0.0