Example #1
0
def gravio(ctx, dotfile):
    '''
    Make a dot file using gravio of the connectivity.
    '''
    try:
        from gravio import gen, dotify
    except ImportError:
        click.echo('You need to install the "gravio" package')
        click.echo('See https://github.com/brettviren/gravio')
        sys.exit(1)
    from wirecell.util.wires import apa, graph
    desc = apa.Description()
    G, P = apa.graph(desc)

    # ['wire', 'wib', 'conductor', 'point', 'chip', 'face', 'plane', 'board', 'detector', 'apa', 'channel']
    node_colors = dict(wib='orange',
                       chip='red',
                       face='blue',
                       plane='purple',
                       board='green',
                       channel='pink')

    def skip_node(n):
        skip_types = ['point', 'wire', 'conductor']
        nt = G.nodes[n]['type']
        return nt in skip_types

    gr = gen.Graph("dune", "graph")
    gr.node(shape='point')

    for name, params in G.nodes.items():
        if skip_node(name):
            continue
        nt = G.nodes[name]['type']
        gr.node(name, shape='point', color=node_colors.get(nt, 'black'))

    #link_types = ['slot', 'submodule', 'pt', 'trace', 'wip', 'spot', 'side',
    #              'plane', 'place', 'address', 'segment', 'cable', 'channel']
    link_colors = dict(trace='pink',
                       spot='red',
                       side='blue',
                       plane='purple',
                       address='yellow',
                       cable='brown',
                       chanel='orange')
    seen_edges = set()
    for (n1, n2), params in G.edges.items():
        if skip_node(n1) or skip_node(n2):
            continue
        if (n1, n2) in seen_edges or (n2, n1) in seen_edges:
            continue
        seen_edges.add((n1, n2))
        link = params['link']
        gr.edge(n1, n2, color=link_colors.get(link, 'black'))

    d = dotify.Dotify(gr)
    dottext = str(d)
    open(dotfile, 'w').write(dottext)
Example #2
0
e = g('edge', 'a', 'b', style='dashed', weight=0.1)
assert e.tail == 'a'
assert e.head == 'b'
g.edge(style='dotted')
g.edge('a','c', color='green')
sg = g.subgraph('cluster_sg', style='solid', label="my subgraph")
assert sg.typename == 'subgraph'
sg.node('d')
g.edge('a','d')
print (g.name, g.typename, len(g.subgraphs))
print (g.nodes(color='red'))

g2 = gen.Graph("cluster_external","subgraph",label="external")
g2.edge("aa","bb")
g2.append(gen.Node("cc"))
g2.append(gen.Edge("aa","cc"))

g.append(g2)
e = g.edge("a","aa", constraint=False)
assert e.attr['constraint'] == False # not "False"

d = dotify.Dotify(g, indent='  ')
print (d)
print ('writing')
open("test_simple.dot","w").write(str(d))

print ('RED nodes:',g.nodes(color='red'))
print ('special nodes:',g.nodes(special=True))
print (g.subgraphs)
print (g.graphs(style='solid'))