3 Do fun stuff to a connectivity graph 7 from wirecell
import units
11 Return a list of all nodes in G of the given type. 13 return [n
for n
in G.nodes
if G.node[n][
'type'] == typename]
18 Return a set of all neighbor nodes withing given radius of seed 19 which are of the given typename. 22 return set([n
for n
in networkx.neighbors(G, seed)
if G.node[n][
'type'] == typename])
24 return set([n
for n
in networkx.ego_graph(G, seed, radius)
if G.node[n][
'type'] == typename])
28 Return all neighbor nodes by following a path of type names from 41 Return a child by walking an "edgepath" from a seed node. 43 The edgepath is a list of triples: 45 >>> [(typename, attrname, attrval), ...] 47 Where `typename` is the node type for the step in the path and 48 `attrname` and `attrval` give a name/value for an edge attribute 49 which must join current node with next node. 54 tn, an, av = edgepath.pop(0)
69 Return parent node of given type 71 for n
in networkx.neighbors(G, child):
72 if G.node[n][
'type'] == parent_type:
96 Flatten the graph to the conductor level. 98 The channel_hash is a callable like apa.channel_hash(). 103 spots_in_layer = [40,40,48]
107 ind_slot = G[apa][wib][
'slot']
110 face =
parent(G, board,
'face')
111 ind_connector = G[wib][board][
'connector']
112 ind_box = G[face][board][
'spot']
113 ind_side = G[apa][face][
'side']
116 ind_chip = G[board][chip][
'spot']
119 conductor =
parent(G, channel,
"conductor")
121 ind_address = G[chip][channel][
'address']
122 ind_layer = G[board][conductor][
'layer']
123 ind_spot = G[board][conductor][
'spot']
126 wires.sort(key =
lambda w: G[conductor][w][
'segment'])
129 plane =
parent(G, wire0,
'plane')
130 ind_wip = G[plane][wire0][
'wip']
131 ind_plane = G[face][plane][
'plane']
132 if ind_plane != ind_layer:
133 raise ValueError(
'Inconsistent graph, layer and plane differ')
136 ind_wan = ind_box * spots_in_layer[ind_layer] + ind_spot
137 ind_wanglobal = ind_wan + spots_in_layer[ind_layer]*boxes_in_face*ind_side
139 one = dict(channel =
channel_hash(ind_connector, ind_slot, ind_chip, ind_address))
140 for k,v
in locals().items():
141 if k.startswith(
'ind_'):
150 Return list of tuples: (ch, plane, wip, sx, sy, sz, ex, ey, ez) 152 corresponding to rows in the "ChannelWireGeometry" file used by 154 https://github.com/bnlif/wire-cell-celltree 156 for the wires in the given face. 158 Note: this only returns the one face of wires but channel numbers 159 are calculated with full knowledge of wrapped wires. 164 planes.sort(key =
lambda p : G[face][p][
'plane'])
167 wires.sort(key =
lambda w : G[plane][w][
'wip'])
168 iplane = G[face][plane][
'plane']
170 iwire = G[plane][wire][
'wip']
173 head, tail = pts[0:2]
174 if G[wire][head][
'endpoint'] == 1:
175 head, tail = pts[1], pts[0]
176 ecm = [r/units.cm
for r
in G.node[head][
'pos']]
177 scm = [r/units.cm
for r
in G.node[tail][
'pos']]
180 one = [chident, iplane, iwire] + scm + ecm
182 ret.append(tuple(one))
188 Return a wirecell.util.wires.schema store filled with information 189 from connection graph G starting from given face. 200 face_indices = list()
202 iface = G[apa][face][
'side']
209 planes.sort(key =
lambda p : G[face][p][
'plane'])
210 plane_wires = [list()
for _
in planes]
213 wires.sort(key =
lambda w : G[plane][w][
'wip'])
214 iplane = G[face][plane][
'plane']
216 wip = G[plane][wire][
'wip']
219 head, tail = pts[0:2]
220 if G[wire][head][
'endpoint'] == 1:
221 head, tail = pts[1], pts[0]
222 hpos = G.node[head][
'pos']
223 tpos = G.node[tail][
'pos']
224 h_id = m.make(
'point', sign*hpos.x, hpos.y, sign*hpos.z)
225 t_id = m.make(
'point', sign*tpos.x, tpos.y, sign*tpos.z)
227 conductor =
parent(G, wire,
'conductor')
228 segment = G[wire][conductor][
'segment']
230 wire_id = m.make(
'wire', wip, chident, segment, t_id, h_id)
231 plane_wires[iplane].append(wire_id)
233 wire_plane_indices = list()
234 for iplane, wire_list
in enumerate(plane_wires):
237 wire_list.sort(key =
lambda w: -1*m.wire_ypos(w))
239 wire_list.sort(key = m.wire_ypos)
241 wire_list.sort(key =
lambda w: sign*m.wire_zpos(w))
242 wpid = schema.wire_plane_id(iplane, iface, iapa)
243 index = m.make(
"plane", iplane, wire_list)
244 wire_plane_indices.append(index)
245 fi = m.make(
"face", iface, wire_plane_indices)
246 face_indices.append(fi)
247 m.make(
"anode", iapa, face_indices)
253 Return set of wire nodes connected to the given plane node. 259 Return set of wire nodes connected to a chip node. If 260 intermediates is true, return the conductor and channel nodes that 261 form the connection to the wires. 267 conductors.update(cs)
270 for cond
in conductors:
275 return channels | conductors | wires
280 Return a new graph with wire endpoints as nodes and a dictionary of 2D points 282 newG = networkx.DiGraph()
286 if G[wire][pt1][
'endpoint'] == 2:
288 pos1 = G.node[pt1][
'pos']
289 pos2 = G.node[pt2][
'pos']
290 pos[pt1] = (pos1.z, pos1.y)
291 pos[pt2] = (pos2.z, pos2.y)
292 newG.add_edge(pt1, pt2)
297 Like wires graph but swap sign of the 2D "X" (3D "Z") coordinates 298 so a conductor zig-zags across a transparent frame. 300 newG = networkx.DiGraph()
302 for icond, cond
in enumerate(conductors):
305 seg = G[cond][wire][
'segment']
312 if G[wire][pt1][
'endpoint'] == 2:
314 pos1 = G.node[pt1][
'pos']
315 pos2 = G.node[pt2][
'pos']
316 pos[pt1] = (sign*pos1.z, pos1.y)
317 pos[pt2] = (sign*pos2.z, pos2.y)
318 newG.add_edge(pt1, pt2, style=style, icolor=icond)
def nodes_by_type(G, typename)
def wires_graph(G, wires)
def neighbors_by_type(G, seed, typename, radius=1)
def conductors_graph(G, conductors)
def to_schema(G, P, channel_ident)
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
def wires_in_plane(G, plane)
def flatten_to_conductor(G, channel_hash)
this assumes a particular hashing scheme.
def child_by_path(G, seed, edgepath)
def neighbors_by_path(G, seed, typenamepath)
def wires_in_chip(G, chip, intermediates=False)
def to_celltree_wires(G, channel_ident, face='face0')
def parent(G, child, parent_type)
def channel_ident(G, wire)
def channel_hash(iconn, islot, ichip, iaddr)