Пример #1
0
def get_texture(smap, dpi):
    figure_args=dict(figsize=(2,2), facecolor='green')
    a = dtu.CreateImageFromPylab(dpi=dpi, figure_args=figure_args)
    frames = list(set(_.id_frame for _ in smap.points.values()))
    id_frame = frames[0]
#     print('frames: %s choose %s' % (frames, id_frame))
    with a as pylab:
        _plot_map_segments(smap, pylab, id_frame, plot_ref_segments=False)
        pylab.axis('equal')
        turn_all_axes_off(pylab)
        pylab.tight_layout()
    png = a.get_png()
    return png
Пример #2
0
def draw_node_graph(filename,
                    G,
                    pos_func,
                    color_func=lambda _: 0.5,
                    label_func=lambda x: str(x),
                    cmap=None):
    from reprep.plot_utils.axes import turn_all_axes_off
    import matplotlib.pyplot as plt  # XXX: use pylab argument
    import networkx as nx
    import os
    import collections

    nodes = list(G)
    pos = dict((n, pos_func(n)) for n in nodes)

    all_positions = [tuple(pos_func(n)) for n in nodes]

    if len(all_positions) != len(set(all_positions)):
        print('Warning, overlapping nodes')
        y = collections.Counter(all_positions)
        for p, num in y.items():
            if num > 1:
                print('- %d for %s' % (num, p))
                for node, node_pos in pos.items():
                    if tuple(node_pos) == p:
                        print('  - %s ' % str(node))
        pass

    node_color = map(color_func, G)
    labels = dict((n, label_func(n)) for n in G)

    fig = plt.figure()
    nx.draw_networkx(G,
                     with_labels=True,
                     pos=pos,
                     labels=labels,
                     node_color=node_color,
                     cmap=cmap)
    plt.colorbar()
    turn_all_axes_off(plt)

    dirname = os.path.dirname(filename)
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    plt.savefig(filename)
    plt.close(fig)
Пример #3
0
def report_tension(mdp, resample_res, resolution=0.33):
    tension = resample_res['tension']
    density_sf = resample_res['density_sf']

    r = Report()
    f = r.figure()

    with f.plot('tension1') as pylab:
        mdp.display_neigh_field_value(pylab, tension)
        turn_all_axes_off(pylab)

    with f.plot('density') as pylab:
        display_sf_field_cont(mdp.get_grid(),
                              pylab,
                              density_sf,
                              res=density_sf)
        turn_all_axes_off(pylab)
    return r
Пример #4
0
def report_agent(res, pomdp):
    agent = res['agent']

    r = Report()

    f = r.figure()

    p_p0 = pomdp.get_start_dist_dist()
    for i, (p0, _) in enumerate(p_p0.items()):
        with f.plot('p0-%d' % i) as pylab:
            pomdp.display_state_dist(pylab, p0)
            turn_all_axes_off(pylab)

    with r.subsection('states') as sub:
        agent.report_states(sub)

    with r.subsection('transitions') as sub:
        agent.report_transitions(sub)

    return r
Пример #5
0
def draw_node_graph(filename, G, pos_func,
                    color_func=lambda _: 0.5,
                    label_func=lambda x: str(x),
                    cmap=None):
    from reprep.plot_utils.axes import turn_all_axes_off
    import matplotlib.pyplot as plt  # XXX: use pylab argument
    import networkx as nx
    import os
    import collections
    
    nodes = list(G)
    pos = dict((n, pos_func(n)) for n in nodes)
    
    all_positions = [tuple(pos_func(n)) for n in nodes] 
    
    if len(all_positions) != len(set(all_positions)):
        print('Warning, overlapping nodes')
        y = collections.Counter(all_positions)
        for p, num in y.items():
            if num > 1:
                print('- %d for %s' % (num, p))
                for node, node_pos in pos.items():
                    if tuple(node_pos) == p:
                        print('  - %s ' % str(node))
        pass
 
    node_color = map(color_func, G) 
    labels = dict((n, label_func(n)) for n in G)
    
    fig = plt.figure() 
    nx.draw_networkx(G, with_labels=True, pos=pos, labels=labels,
                     node_color=node_color, cmap=cmap)
    plt.colorbar()
    turn_all_axes_off(plt)

    dirname = os.path.dirname(filename)
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    plt.savefig(filename)
    plt.close(fig)
Пример #6
0
def report_agent(res, pomdp):
    agent = res['agent']


    r = Report()

    f = r.figure()

    p_p0 = pomdp.get_start_dist_dist()
    for i, (p0, _) in enumerate(p_p0.items()):
        with f.plot('p0-%d' % i) as pylab:
            pomdp.display_state_dist(pylab, p0)
            turn_all_axes_off(pylab)

    with r.subsection('states') as sub:
        agent.report_states(sub)

    with r.subsection('transitions') as sub:
        agent.report_transitions(sub)


    return r