Beispiel #1
0
        def _iter(self):
            st = time.time()
            ys = [random.random(), random.random(), random.random()]
            self.g.record_multiple(ys)
            # self.g.record(random.random())

            do_after_timer(999.5 - (time.time() - st) * 1000, self._iter)
Beispiel #2
0
        def _iter(self):
            st = time.time()
            ys = [random.random(), random.random(), random.random()]
            self.g.record_multiple(ys)
            # self.g.record(random.random())

            do_after_timer(999.5 - (time.time() - st) * 1000, self._iter)
Beispiel #3
0
        def _test_fired(self):
            s = StreamGraph()
            s.new_plot(scan_width=5)
            s.new_series(type="scatter")
            s.new_series(type="line", plotid=0)
            s.new_series(type="line", plotid=0)

            s.edit_traits()
            self.g = s
            do_after_timer(1000, self._iter)
Beispiel #4
0
        def _test_fired(self):
            s = StreamGraph()
            s.new_plot(scan_width=5)
            s.new_series(type='scatter')
            s.new_series(type='line', plotid=0)
            s.new_series(type='line', plotid=0)

            s.edit_traits()
            self.g = s
            do_after_timer(1000, self._iter)
Beispiel #5
0
    def add_aux_datum(self, datum, plotid=0, series=1, do_after=False):
        '''
        '''
        def add():
            plot = self.plots[plotid]

            si = plot.plots['aux{:03n}'.format(series)][0]

            oi = si.index.get_data()
            ov = si.value.get_data()

            si.index.set_data(hstack((oi, [datum[0]])))
            si.value.set_data(hstack((ov, [datum[1]])))

        if do_after:
            do_after_timer(do_after, add)
        else:
            add()
Beispiel #6
0
    def add_aux_datum(self, datum, plotid=0, series=1, do_after=False):
        '''
        '''
        def add():
            plot = self.plots[plotid]

            si = plot.plots['aux{:03n}'.format(series)][0]

            oi = si.index.get_data()
            ov = si.value.get_data()

            si.index.set_data(np.hstack((oi, [datum[0]])))
            si.value.set_data(np.hstack((ov, [datum[1]])))

        if do_after:
            do_after_timer(do_after, add)
        else:
            add()
Beispiel #7
0
    def add_datum(self, datum, plotid=0, series=0, update_y_limits=False,
                   ypadding=10,
                   ymin_anchor=None, do_after=None, **kw):
        '''
        '''
        def add():
#            print plotid, series, self.series
            names = self.series[plotid][series]
            plot = self.plots[plotid]
            for i, name in enumerate(names):
                d = plot.data.get_data(name)
                nd = np.hstack((d, float(datum[i])))
                plot.data.set_data(name, nd)

                if i == 1:
                    # y values
                    mi = min(nd)
                    ma = max(nd)

            if update_y_limits:
                if isinstance(ypadding, str):

                    ypad = max(0.1, abs(mi - ma)) * float(ypadding)
                else:
                    ypad = ypadding
                mi -= ypad
                if ymin_anchor is not None:
                    mi = max(ymin_anchor, mi)


#                if ypadding / ma > 0.5:
#                    ypadding = 0

                self.set_y_limits(min=mi,
                                  max=ma + ypad,
                                  plotid=plotid)

        if do_after:
            do_after_timer(do_after, add)
        else:
            add()
Beispiel #8
0
    def record(self, y, x=None, series=0, plotid=0,
               track_x=True, track_y=True, do_after=None, track_y_pad=5,
               aux=False, pad=0.1, **kw):

        xn, yn = self.series[plotid][series]

        plot = self.plots[plotid]

        xd = plot.data.get_data(xn)
        yd = plot.data.get_data(yn)

        if x is None:
            try:
                tg = self.time_generators[plotid]
            except IndexError:
                tg = time_generator(self.scan_delays[plotid])
                self.time_generators.append(tg)

            nx = tg.next()
        else:
            nx = x

        ny = float(y)
        # update raw data
        #        rx = self.raw_x[plotid][series]
        #        ry = self.raw_y[plotid][series]
        #
        #        self.raw_x[plotid][series] = hstack((rx[MAX_LIMIT:], [nx]))
        #        self.raw_y[plotid][series] = hstack((ry[MAX_LIMIT:], [ny]))

        dl = self.data_limits[plotid]
        sd = self.scan_delays[plotid]
        pad = dl * pad
        #        lim = MAX_LIMIT
        #         pad = 100
        #        print lim, nx, ny
        lim = -dl * sd - 1000
        new_xd = hstack((xd[lim:], [nx]))
        new_yd = hstack((yd[lim:], [ny]))
        #        print new_xd
        self.cur_max[plotid] = max(self.cur_max[plotid], max(new_yd))
        self.cur_min[plotid] = min(self.cur_min[plotid], min(new_yd))

        def _record_():
            if track_x and (self.track_x_min or self.track_x_max) \
                or self.force_track_x_flag:
                ma = new_xd[-1]
                sd = self.scan_delays[plotid]
                mi = ma - dl * sd + pad
                if self.force_track_x_flag or \
                                ma >= dl * sd - pad:

                    if self.force_track_x_flag:
                        self.force_track_x_flag = False
                        ma = dl * sd

                    if not self.track_x_max:
                        ma = None
                    else:
                        ma = ma + pad

                    if not self.track_x_min:
                        mi = None
                    else:
                        mi = max(1, mi)

                    self.set_x_limits(max_=ma,
                                      min_=mi,
                                      plotid=plotid,
                                      #                              force=False
                                      #                              pad=10 * self.scan_delays[plotid]
                    )

            if track_y and (self.track_y_min[plotid] or self.track_y_max[plotid]):
                if isinstance(track_y, tuple):
                    mi, ma = track_y
                    if ma is None:
                        ma = self.cur_max[plotid]

                    if mi is None:
                        mi = self.cur_min[plotid]

                else:
                    if not self.track_y_max[plotid]:
                        ma = None
                    else:
                        ma = self.cur_max[plotid]

                    if not self.track_y_min[plotid]:
                        mi = None
                    else:
                        mi = self.cur_min[plotid]
                self.set_y_limits(max_=ma,
                                  min_=mi,
                                  plotid=plotid,
                                  pad=track_y_pad,
                                  force=False
                )

            if aux:
                self.add_datum_to_aux_plot((nx, ny), plotid, series)
            else:
                plot.data.set_data(xn, new_xd)
                plot.data.set_data(yn, new_yd)
            #            self.redraw()

        if do_after:
            do_after_timer(do_after, _record_)
        else:
            _record_()

        return nx
Beispiel #9
0
 def show(self):
     do_after_timer(1, self.edit_traits)
Beispiel #10
0
 def show(self):
     do_after_timer(1, self.edit_traits)
Beispiel #11
0
    def record(self,
               y,
               x=None,
               series=0,
               plotid=0,
               track_x=True,
               track_y=True,
               do_after=None,
               track_y_pad=5,
               aux=False,
               pad=0.1,
               **kw):

        xn, yn = self.series[plotid][series]

        plot = self.plots[plotid]

        xd = plot.data.get_data(xn)
        yd = plot.data.get_data(yn)

        if x is None:
            try:
                tg = self.time_generators[plotid]
            except IndexError:
                tg = time_generator(self.scan_delays[plotid])
                self.time_generators.append(tg)

            nx = tg.next()
        else:
            nx = x

        ny = float(y)
        # update raw data
        #        rx = self.raw_x[plotid][series]
        #        ry = self.raw_y[plotid][series]
        #
        #        self.raw_x[plotid][series] = hstack((rx[MAX_LIMIT:], [nx]))
        #        self.raw_y[plotid][series] = hstack((ry[MAX_LIMIT:], [ny]))

        dl = self.data_limits[plotid]
        sd = self.scan_delays[plotid]
        pad = dl * pad
        #        lim = MAX_LIMIT
        #         pad = 100
        #        print lim, nx, ny
        lim = -dl * sd - 1000
        new_xd = hstack((xd[lim:], [nx]))
        new_yd = hstack((yd[lim:], [ny]))
        #        print new_xd
        self.cur_max[plotid] = max(self.cur_max[plotid], max(new_yd))
        self.cur_min[plotid] = min(self.cur_min[plotid], min(new_yd))

        def _record_():
            if track_x and (self.track_x_min or self.track_x_max) \
                or self.force_track_x_flag:
                ma = new_xd[-1]
                sd = self.scan_delays[plotid]
                mi = ma - dl * sd + pad
                if self.force_track_x_flag or \
                                ma >= dl * sd - pad:

                    if self.force_track_x_flag:
                        self.force_track_x_flag = False
                        ma = dl * sd

                    if not self.track_x_max:
                        ma = None
                    else:
                        ma = ma + pad

                    if not self.track_x_min:
                        mi = None
                    else:
                        mi = max(1, mi)

                    self.set_x_limits(
                        max_=ma,
                        min_=mi,
                        plotid=plotid,
                        #                              force=False
                        #                              pad=10 * self.scan_delays[plotid]
                    )

            if track_y and (self.track_y_min[plotid]
                            or self.track_y_max[plotid]):
                if isinstance(track_y, tuple):
                    mi, ma = track_y
                    if ma is None:
                        ma = self.cur_max[plotid]

                    if mi is None:
                        mi = self.cur_min[plotid]

                else:
                    if not self.track_y_max[plotid]:
                        ma = None
                    else:
                        ma = self.cur_max[plotid]

                    if not self.track_y_min[plotid]:
                        mi = None
                    else:
                        mi = self.cur_min[plotid]
                self.set_y_limits(max_=ma,
                                  min_=mi,
                                  plotid=plotid,
                                  pad=track_y_pad,
                                  force=False)

            if aux:
                self.add_datum_to_aux_plot((nx, ny), plotid, series)
            else:
                plot.data.set_data(xn, new_xd)
                plot.data.set_data(yn, new_yd)
            #            self.redraw()

        if do_after:
            do_after_timer(do_after, _record_)
        else:
            _record_()

        return nx
Beispiel #12
0
 def opened(self, ui):
     self.info('opened')
     # delay 1s before starting scan
     do_after_timer(1000, self.reset_general_scan)