Esempio n. 1
0
class RandomWalkPlot:
    def __init__(self, win):
        #self.plot = pg.plot()
        self.plot = win.addPlot(title="Updating plot")

        self.ptr = 0

        #pen = 'r'
        pen = pg.mkPen('b', style=QtCore.Qt.SolidLine)
        self.curve = self.plot.plot(pen=pen, symbol='+')
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(50)

        self.value = 1000  # initial value
        N = 100  # number of elements into circular buffer

        self.data_y = RingBuffer(N, self.value)

    def update(self):
        self.value += np.random.uniform(-1, 1)

        self.data_y.append(self.value)

        self.curve.setData(y=self.data_y)  #  size is increasing up to N
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        super(MyApplication, self).__init__(*args, **kwargs)
        #self.t = QTime()
        #self.t.start()

        maxlen = 50
        self.data_x = RingBuffer(maxlen)
        self.data_y = RingBuffer(maxlen)

        self.win = pg.GraphicsWindow(title="Basic plotting examples")
        self.win.resize(1000, 600)
        self.win.setWindowTitle('Plot with PyQtGraph')

        self.plot = self.win.addPlot(title='Timed data', axisItems={'bottom': TimeAxisItem(orientation='bottom')})
        #self.plot.setYRange(0, 150)

        #self.curve = self.plot.plot()

        pen = pg.mkPen('r', style=QtCore.Qt.SolidLine)
        self.curve = self.plot.plot(pen=pen, symbol='+')

        self.timer = QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(100)

        self.y = 100
Esempio n. 3
0
def test_min_max():
    N = 5
    ring = RingBuffer(size_max=N, default_value=-1)
    ring.append(2)
    ring.append(1)
    ring.append(4)
    ring.append(3)
    assert ring.min() == 1
    assert ring.min(all=True) == -1
    assert ring.max() == 4
Esempio n. 4
0
def test_ring():
    N = 10
    def print_overflow(*args, **kwargs):
        print("OVERFLOW of %s" % args[0])
        #raise NotImplementedError
    ring = RingBuffer(size_max=N, default_value=0.0, dtype=float, overflow=print_overflow)
    for i in range(1, N + 5):
        ring.append(i)
        assert ring[0] == i
        if i < N:
            assert not ring.full
        else:
            assert ring.full

    assert isinstance(ring.all, np.ndarray)
    assert isinstance(ring.partial, np.ndarray)
def main():
    maxlen = 50
    #data_x = RingBuffer(maxlen)
    data_y = RingBuffer(maxlen)

    y = 100  # initial value

    fig, ax = plt.subplots()
    line, = ax.plot(data_y.all[::-1])
    delta_y = 20
    ax.set_ylim([y - delta_y, y + delta_y])

    while True:
        y = y + np.random.uniform(-1, 1)
        data_y.append(y)
        line.set_ydata(data_y.all[::-1])
        plt.pause(0.001)
Esempio n. 6
0
    def __init__(self, win):
        #self.plot = pg.plot()
        self.plot = win.addPlot(title="Updating plot")

        self.ptr = 0

        #pen = 'r'
        pen = pg.mkPen('b', style=QtCore.Qt.SolidLine)
        self.curve = self.plot.plot(pen=pen, symbol='+')
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(50)

        self.value = 1000  # initial value
        N = 100  # number of elements into circular buffer

        self.data_y = RingBuffer(N, self.value)
Esempio n. 7
0
def test_min_max():
    N = 5
    ring = RingBuffer(size_max=N, default_value=-1)
    ring.append(2)
    ring.append(1)
    ring.append(4)
    ring.append(3)
    assert ring.min() == 1
    assert ring.min(all=True) == -1
    assert ring.max() == 4
Esempio n. 8
0
def test_ring():
    N = 10

    def print_overflow(*args, **kwargs):
        print("OVERFLOW of %s" % args[0])
        #raise NotImplementedError

    ring = RingBuffer(size_max=N,
                      default_value=0.0,
                      dtype=float,
                      overflow=print_overflow)
    for i in range(1, N + 5):
        ring.append(i)
        assert ring[0] == i
        if i < N:
            assert not ring.full
        else:
            assert ring.full

    assert isinstance(ring.all, np.ndarray)
    assert isinstance(ring.partial, np.ndarray)
class MyApplication(QtGui.QApplication):
    def __init__(self, *args, **kwargs):
        super(MyApplication, self).__init__(*args, **kwargs)
        #self.t = QTime()
        #self.t.start()

        maxlen = 50
        self.data_x = RingBuffer(maxlen)
        self.data_y = RingBuffer(maxlen)

        self.win = pg.GraphicsWindow(title="Basic plotting examples")
        self.win.resize(1000, 600)
        self.win.setWindowTitle('Plot with PyQtGraph')

        self.plot = self.win.addPlot(title='Timed data')
        #self.plot.setYRange(0, 150)

        #self.curve = self.plot.plot()

        pen = pg.mkPen('r', style=QtCore.Qt.SolidLine)
        self.curve = self.plot.plot(pen=pen, symbol='+')

        self.timer = QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(100)

        self.y = 100

    def update(self):
        #self.data.append({'x': self.t.elapsed(), 'y': np.random.randint(0, 100)})
        x = now_timestamp()
        self.y = self.y + np.random.uniform(-1, 1)

        self.data_x.append(x)
        self.data_y.append(self.y)

        #self.curve.setData(x=self.data_x, y=self.data_y)
        self.curve.setData(y=self.data_y)
class MyApplication(QtGui.QApplication):
    def __init__(self, *args, **kwargs):
        super(MyApplication, self).__init__(*args, **kwargs)
        #self.t = QTime()
        #self.t.start()

        maxlen = 50
        self.data_x = RingBuffer(maxlen)
        self.data_y = RingBuffer(maxlen)

        self.win = pg.GraphicsWindow(title="Basic plotting examples")
        self.win.resize(1000, 600)
        self.win.setWindowTitle('Plot with PyQtGraph')

        self.plot = self.win.addPlot(title='Timed data', axisItems={'bottom': TimeAxisItem(orientation='bottom')})
        #self.plot.setYRange(0, 150)

        #self.curve = self.plot.plot()

        pen = pg.mkPen('r', style=QtCore.Qt.SolidLine)
        self.curve = self.plot.plot(pen=pen, symbol='+')

        self.timer = QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(100)

        self.y = 100

    def update(self):
        #self.data.append({'x': self.t.elapsed(), 'y': np.random.randint(0, 100)})
        x = now_timestamp()
        self.y = self.y + np.random.uniform(-1, 1)

        self.data_x.append(x)
        self.data_y.append(self.y)

        self.curve.setData(x=self.data_x, y=self.data_y)
Esempio n. 11
0
def main(device, baudrate):
    logging.basicConfig(level=logging.INFO)
    
    sensors00 = SensorsArduino(device=device, baudrate=baudrate, adc_channels_number=2)
    print("capabilities: %s" % sensors00.capabilities)
    sensors00.connect()
    sensors00.ADC[0].calibrate(lambda value: linear_function_with_limit(value, 520.0, 603.0, 0.0, 100.0))
        
    maxlen = 100
    data_x = RingBuffer(maxlen, datetime.datetime.utcnow(), dtype=datetime.datetime)
    data_y = RingBuffer(maxlen)

    y = 100 # initial value

    fig, ax = plt.subplots()
    line, = ax.plot(data_x.all[::-1], data_y.all[::-1], linestyle='-', marker='+', color='r', markeredgecolor='b')
    #ax.set_ylim([0, 1023])
    ax.set_ylim([0, 100])

    t_last = datetime.datetime.utcnow()
    while True:
        t = datetime.datetime.utcnow()
        try:
            if sensors00.update() and sensors00.ADC[0].has_new_data:
                print(sensors00._bin_msg._data)
                y = sensors00.ADC[0].value
                #y = limit(y, 1800.0, 24000.0, 0.0, 100.0)
                logger.info("%s %s %s" % (t, y, t - t_last))
                data_x.append(t)
                data_y.append(y)
                line.set_xdata(data_x.all[::-1])
                xmin, xmax = data_x.min(), data_x.max()
                if xmax > xmin:
                    ax.set_xlim([xmin, xmax])
                    line.set_ydata(data_y.all[::-1])
                    #ymin, ymax = data_y.min(), data_y.max()
                    #if ymax > ymin:
                    #    ax.set_ylim([ymin, ymax])
                plt.pause(0.001)
        except Exception as e:
            logger.error(traceback.format_exc())
            #raise e
        t_last = t
def main():
    maxlen = 500
    data_x = RingBuffer(maxlen,
                        datetime.datetime.utcnow(),
                        dtype=datetime.datetime)
    data_y = RingBuffer(maxlen)

    y = 100  # initial value

    fig, ax = plt.subplots()
    line, = ax.plot(data_x.all[::-1],
                    data_y.all[::-1],
                    linestyle='-',
                    marker='+',
                    color='r',
                    markeredgecolor='b')
    delta_y = 20
    ax.set_ylim([y - delta_y, y + delta_y])

    while True:
        x = datetime.datetime.utcnow()
        y = y + np.random.uniform(-1, 1)
        data_x.append(x)
        data_y.append(y)
        line.set_xdata(data_x.all[::-1])
        xmin, xmax = data_x.min(), data_x.max()
        if xmax > xmin:
            ax.set_xlim([xmin, xmax])
        line.set_ydata(data_y.all[::-1])
        ymin, ymax = data_y.min(), data_y.max()
        if ymax > ymin:
            ax.set_ylim([ymin, ymax])
        plt.pause(0.001)