def display_1d_tensor(pub, name, value):
    with pub.plot(name) as pylab:
        for k in range(value.shape[0]):
            x = value[k, ...].squeeze()
            assert x.ndim == 1
            pylab.plot(x, label="%s%s" % (name, k))
            x_axis_set(pylab, -1, x.size)
            turn_off_bottom_and_top(pylab)

        y_axis_balanced(pylab, show0=True)
        pylab.legend()
def style_1d_sensel_func(pylab, n, y_max, extra_vspace=1.1):
    """ 
        Decorates approapriateyle
    """
    y_axis_set(pylab, -y_max * extra_vspace, y_max * extra_vspace)
    x_axis_set(pylab, -1, n)
    turn_off_bottom_and_top(pylab)
    turn_off_right(pylab)
    set_left_spines_outward(pylab, offset=10)
    set_thick_ticks(pylab, markersize=3, markeredgewidth=1)
    pylab.plot([0, n - 1], [0, 0], "--", color=[0.7, 0.7, 0.7])
def comparison_balanced(pylab, a, b, perc=0.95, M=1.1):
    """
        Computes 1-perc and perc percentiles, and fits only as much.
        
    """
    values = np.hstack((a, b))
    
    level = np.percentile(np.abs(values), perc * 100)
    limit = M * level
    y_axis_set(pylab, -limit, limit)
    
    n = a.size
    x_axis_set(pylab, -1, n)
Beispiel #4
0
    def plot(self, pylab):
        ts = self.get_relative_times()
        es = self.get_relative_errors()
        assert ts.size == es.size
        
        self.plot_anim.set_pylab(pylab)
        
        if ts.size > 0:
            T = self.get_T(duration=(ts[-1] - ts[0]), chunk=5, min_time=15)
            assert T >= ts[-1]
        else:
            T = 10
        
        if self.plot_line is None:            
            ax1 = pylab.gca()
            ax1.axes.get_xaxis().set_visible(False)
            ax1.axes.get_yaxis().set_visible(False)
            self.plot_line = True
        
        border = 2
        if self.config.use_first_y_goal:
            pylab.axis((-1, T + border, -0.1, 1.3))
        else:
            x_axis_set(pylab, -1, T + border)
            if es.size > 0:
                y_axis_set(pylab, -0.1, np.max(es) * 1.3)

        # s = '%s %s' % (self.servo_state, self.timestamp)
        # self.plot_anim.text('status', 0.7 * T, 1.2, s)
        # self.plot_anim.text('clock', 0.7 * T, 1.2, '%5.2f' % self.time_since_start)
        self.plot_anim.plot('error', ts, es, 'k-')
        
        if es.size > 0:
            self.plot_anim.plot('error1', ts[0], es[0], 'rs')
            self.plot_anim.plot('error2', ts[-1], es[-1], 'rs')
        else:
            self.plot_anim.plot('error1', [], [], 'ro')
            self.plot_anim.plot('error2', [], [], 'ro')
        
        self.plot_anim.plot('zero', [0, T], [0, 0], 'k--')
            
        if self.servo_state == STATE_SERVOING:
            # self.info('Servoing')
            pass
        else:
            pass
Beispiel #5
0
    def publish(self, pub):
        if not self.once:
            pub.text('info', 'never called yet')
            return
        
        N = self.last_y.size
        
        with pub.plot('last_w') as pylab:
            pylab.plot(self.last_w, 's')
            
            x_axis_set(pylab, -1, N)
            y_axis_set(pylab, -0.1, 1.1)
            turn_off_bottom_and_top(pylab)

        gy0 = self.last_gy[0, :]

        def plot_good_bad(pylab, x, valid):
            invalid = np.logical_not(valid)
            pylab.plot(np.nonzero(valid)[0], x[valid], 'ks')
            pylab.plot(np.nonzero(invalid)[0], x[invalid], 'rs')
            
        with pub.plot('last_y') as pylab: 
            plot_good_bad(pylab, self.last_y, self.last_y_valid)
            y_axis_set(pylab, -0.1, +1.1)
            x_axis_set(pylab, -1, N)
            turn_off_bottom_and_top(pylab)
            
        with pub.plot('last_y_dot') as pylab:
            pylab.plot(self.last_y_dot)            
            plot_good_bad(pylab, self.last_y_dot, self.last_y_dot_valid)
            
            upper = np.ones(N) * self.max_y_dot
            lower = -upper
            pylab.plot(upper, 'r--')
            pylab.plot(lower, 'r--')
            
            x_axis_set(pylab, -1, N)
            y_axis_balanced(pylab)
            turn_off_bottom_and_top(pylab)

        with pub.plot('last_gy') as pylab:            
            plot_good_bad(pylab, gy0, self.last_gy_valid)
            
            upper = np.ones(N) * self.max_gy
            lower = -upper
            pylab.plot(upper, 'r--')
            pylab.plot(lower, 'r--')
            
            x_axis_set(pylab, -1, N)
            y_axis_balanced(pylab)
            turn_off_bottom_and_top(pylab)
 
        self.w_stats.publish(pub.section('w_stats'))
def display_1d_field(pub, name, value):
    with pub.plot(name) as pylab:
        pylab.plot(value)
        x_axis_set(pylab, -1, value.size)
        turn_off_bottom_and_top(pylab)
Beispiel #7
0
    def publish_u_stats(self, pub):
        T = len(self.u_stats)
        print('Obtained %d obs' % T)
        K = 2  # FIXME: change this
        u_act = np.zeros((T, K))
        u_est = np.zeros((T, K))
        u_mis = np.zeros((T, K))
        u_suc = np.zeros((T, K))
        time = np.zeros(T)
        num_episode = np.zeros(T, 'int')
        id_episode2num = {}
        num2id_episode = {}
        id_episode2start = {}
        # cmd2faults = {}
        for t, stats in enumerate(self.u_stats):
            u_act[t, :] = stats['u']
            u_est[t, :] = stats['u_est']
            time[t] = stats['timestamp']
            id_ep = stats['id_episode']
            if not id_ep in id_episode2num:
                id_episode2num[id_ep] = len(id_episode2num)
                id_episode2start[id_ep] = time[t]
                num2id_episode[id_episode2num[id_ep]] = id_ep
            num_episode[t] = id_episode2num[id_ep]

        s = ""
        for k, v in id_episode2num.items():
            s += '%s: %s\n' % (k, v)
        pub.text('episodes', s)
        with pub.plot('num_episode') as pylab:
            pylab.plot(num_episode, '-')
            pylab.xlabel('index')
            pylab.ylabel('num\_episode')

        for id_episode, num in id_episode2num.items():
            print id_episode
            S = pub.section('Episode:%s' % id_episode)
            # times for this episode
            et = num_episode == num
            # normalize from 0
            e_timestamps = time[et]
            log_start = e_timestamps[0]
            e_timestamps -= log_start
            cmd2color = {0: 'g', 1: 'b'}

            episode_bounds = (18, 60)
            markersize = 2
            with S.plot('mis', figsize=(8, 2), mime=MIME_PDF) as pylab:
                for k in range(K):
#                    scale = 7
#                    u_mis_smooth = scipy.signal.convolve(u_mis[et, k], 
#                     np.ones(scale) / scale,
#                                                         mode='same')
                    pylab.plot(e_timestamps, u_mis[et, k],  # u_mis_smooth,
                               '%s-' % cmd2color[k], label='u[%d]' % k,
                               markersize=markersize)
                x_axis_set(pylab, episode_bounds[0], episode_bounds[1])

            with S.plot('success', figsize=(8, 2), mime=MIME_PDF) as pylab:
                pylab.plot(e_timestamps, e_timestamps * 0, 'k--')
                pylab.plot(e_timestamps, np.ones(len(e_timestamps)), 'k--')
                for k in range(K):
                    pylab.plot(e_timestamps, u_suc[et, k],
                               '%s-' % cmd2color[k], label='cmd #%d' % k)
                y_axis_set(pylab, -0.05, 1.05)
                x_axis_set(pylab, episode_bounds[0], episode_bounds[1])
                pylab.legend(loc='lower right')

            for k in range(K):
                with S.plot('commands_%d' % k, figsize=(8, 2),
                            mime=MIME_PDF) as pylab:
                    pylab.plot(e_timestamps, u_act[et, k], 'y.',
                               label='actual', markersize=3)
                    plot_with_colors(pylab, e_timestamps,
                                     u_est[et, k], u_act[et, k],
                                     markersize=markersize)
                    y_axis_set(pylab, -2, 2)
                    x_axis_set(pylab, episode_bounds[0], episode_bounds[1])