2 from wirecell
import units
4 from itertools
import chain
5 from collections
import defaultdict
7 import matplotlib.pyplot
as plt
8 from matplotlib.backends.backend_pdf
import PdfPages
10 desc = apa.Description();
13 xkcd_color = [
'xkcd:red',
'xkcd:tangerine',
'xkcd:goldenrod',
14 'xkcd:green',
'xkcd:blue',
'xkcd:purple',
29 inp = graph.wires_in_plane(G, P.plane[0])
30 inc = graph.wires_in_chip(G, P.chip[8])
31 wires = inp.intersection(inc)
32 wg,wpos = graph.wires_graph(G, wires)
33 networkx.draw(wg, pos=wpos, with_labels=
True,width=0.1)
34 plt.savefig(
'test_plot_plane_chip.pdf')
37 wg, wpos = graph.conductors_graph(G, [P.conductor[0]])
38 networkx.draw(wg, pos=wpos, with_labels=
True)
39 plt.savefig(
'test_plot_conductor.pdf')
42 with PdfPages(
'test_plot_chip.pdf')
as pdf:
45 channels = graph.neighbors_by_type(G, chip,
'channel')
46 conductors = list(chain.from_iterable([graph.neighbors_by_type(G, ch,
'conductor')
for ch
in channels]))
47 wg, wpos = graph.conductors_graph(G, conductors)
49 edges = wg.edges(data=
True)
52 for n1,n2,dat
in edges:
53 styles.append(dat[
'style'])
54 icolor = dat[
'icolor']
55 colors.append(xkcd_color[icolor%len(xkcd_color)])
56 networkx.draw_networkx_edges(wg, pos=wpos, style=styles,
57 width=0.1, arrows=
False,
59 print chip,len(channels),len(conductors)
68 with PdfPages(
'test_plot_board.pdf')
as pdf:
71 plt.title(
"Board %d" % (iboard+1,))
73 bg = networkx.DiGraph()
75 chips = graph.neighbors_by_type(G, board,
'chip')
79 print 'board:',board, len(chips), chips
81 channels = graph.neighbors_by_type(G, chip,
'channel')
82 conductors = chain.from_iterable([graph.neighbors_by_type(G, ch,
'conductor')
for ch
in channels])
83 cg, cpos = graph.conductors_graph(G, conductors)
85 cstyles = [e[2][
'style']
for e
in cg.edges(data=
True)]
86 cedges = list(cg.edges())
88 colors += [xkcd_color[ichip]]*n_edges
92 bg = networkx.compose(bg, cg)
95 networkx.draw_networkx_edges(bg, edgelist=edges,
96 pos=bpos, style=styles,
98 width=penwidth, arrows=
False)
99 assert(len(edges) == len(colors))
104 plt.axes().set_aspect(
'equal',
'box')
105 plt.xlabel(
'$z_c$ (mm)')
106 plt.ylabel(
'$y_c$ (mm)')
112 with PdfPages(
'test_plot_wib_wires.pdf')
as pdf:
114 boards_by_connector = defaultdict(list)
116 boards_on_wib = graph.neighbors_by_type(G, wib,
'board')
117 for b
in boards_on_wib:
118 iconnector = G[wib][b][
'connector']
119 boards_by_connector[iconnector].append((wib,b))
120 print boards_by_connector
121 for iconnector, wib_boards
in sorted(boards_by_connector.items()):
122 for wib,board
in wib_boards:
123 plt.title(
"%s connector %s %s" % (wib, iconnector, board))
124 bg = networkx.DiGraph()
126 chips = graph.neighbors_by_type(G, board,
'chip')
128 channels = graph.neighbors_by_type(G, chip,
'channel')
129 print chip, len(channels)
130 conductors = chain.from_iterable([graph.neighbors_by_type(G, ch,
'conductor')
for ch
in channels])
131 cg, cpos = graph.conductors_graph(G, conductors)
132 bg = networkx.compose(bg, cg)
134 networkx.draw(bg, pos=bpos, arrows=
False, width=0.1)
139 'Plot all wib connections' 141 newG = networkx.Graph()
144 conn_colors = [
'xkcd:sky blue',
'xkcd:deep pink',
145 'xkcd:sky blue',
'xkcd:deep pink']
148 return (-2 + slot - 0.5, 0)
149 def conn_pos(slot, conn):
151 square_pts = [(-1,-1), (1,-1), (1,1), (-1,1)]
152 line_pts = [(0,-2),(0,-1),(0,1),(0,2)]
157 return (wp[0]+scale*pt[0], wp[1]+scale*pt[1])
158 def board_pos(side, spot):
160 return (-5 + spot, -3)
161 return (4 - spot, +3)
166 nwib =
"w%d"%(
int(wib[3:])+1,)
167 newG.add_node(nwib, color=
"xkcd:white", shape=
'o')
170 islot = G[apa][wib][
'slot']
171 newP[nwib] = wib_pos(islot)
172 boards_on_wib = graph.neighbors_by_type(G, wib,
'board')
173 for board
in boards_on_wib:
174 face = list(graph.neighbors_by_type(G, board,
'face'))[0]
175 ispot = G[face][board][
'spot']
177 iside = G[face][apa][
'side']
178 nboard =
"b%d"%(
int(board[5:])+1,)
180 iconn = G[wib][board][
'connector']
181 nconn =
"%d%d" % (islot+1, iconn+1)
182 newG.add_node(nconn, color=conn_colors[iconn], shape=
'd')
183 newP[nconn] = conn_pos(islot, iconn)
185 newG.add_node(nboard, color=conn_colors[iconn], shape=
's')
186 newP[nboard] = board_pos(iside, ispot)
188 newG.add_edge(nwib,nconn)
189 newG.add_edge(nconn,nboard)
192 colors = [n[1][
'color']
for n
in newG.nodes(data=
True)]
193 shapes = [n[1][
'shape']
for n
in newG.nodes(data=
True)]
195 networkx.draw(newG, pos=newP,
200 plt.savefig(
'test_plot_wib.pdf')
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
def test_plot_board(debug=False)
def test_plot_conductor()
def test_plot_wib_wires()
def test_plot_plane_chip()