2 from wirecell
import units
3 import matplotlib.pyplot
as plt
4 import matplotlib.patches
as mpatches
6 from collections
import defaultdict
10 cmap = plt.get_cmap(
'seismic')
12 colors = [
cmap(i)
for i
in numpy.linspace(0, 1, npts)]
14 x = numpy.asarray((p1.x, p2.x))
15 y = numpy.asarray((p1.y, p2.y))
16 plt.plot(x, y, linewidth=ind+1)
22 Plot one plane of wires. 24 This plot is in protodune-numbers document. 26 fig,axes = plt.subplots(nrows=1, ncols=3)
34 face = store.faces[iface]
36 cmap = plt.get_cmap(
'rainbow')
38 for iplane
in range(3):
41 planeid = face.planes[iplane]
42 plane = store.planes[planeid]
44 wires = [w
for w
in plane.wires[::wire_stride]]
47 colors = [
cmap(i)
for i
in numpy.linspace(0, 1, nwires)]
51 wire = store.wires[wind]
52 if segments
and not wire.segment
in segments:
55 color = colors[wcount]
57 color = colors[nwires-wcount-1]
59 p1 = store.points[wire.tail]
60 p2 = store.points[wire.head]
61 width = widths[wire.segment]
62 ax.plot((p1.z/units.meter, p2.z/units.meter), (p1.y/units.meter, p2.y/units.meter),
63 linewidth = width, color=color)
65 ax.locator_params(axis=
'x', nbins=5)
66 ax.set_aspect(
'equal',
'box')
67 ax.set_xlabel(
"Z [meter]")
69 ax.set_ylabel(
"Y [meter]")
70 ax.set_title(
"plane %d/%s" % (iplane,uvw[iplane]))
76 Plot wires for select channels. 78 channels = set(channels)
79 bychan = defaultdict(list)
83 for anode
in store.anodes:
84 for iface
in anode.faces:
85 face = store.faces[iface]
86 for iplane
in face.planes:
87 plane = store.planes[iplane]
89 wire = store.wires[wind]
90 if wire.channel
in channels:
91 bychan[wire.channel].append((wire, wip))
93 fig, ax = plt.subplots(nrows=1, ncols=1)
95 for ch,wws
in sorted(bychan.items()):
96 wws.sort(key=
lambda ww: ww[0].segment)
98 p1 = store.points[wire.tail]
99 p2 = store.points[wire.head]
100 width = wire.segment + 1
101 ax.plot((p1.z/units.meter, p2.z/units.meter),
102 (p1.y/units.meter, p2.y/units.meter), linewidth = width)
110 t=
'w:%d ch:%d\nident:%d seg:%d' % \
111 (wip, wire.channel, wire.ident, wire.segment)
113 horizontalalignment=hal,
114 bbox=dict(facecolor=
'yellow', alpha=0.5, pad=10))
115 ax.set_xlabel(
"Z [meter]")
116 ax.set_ylabel(
"Y [meter]")
123 Plot each plane of wires on a page of a PDF file. 127 from matplotlib.backends.backend_pdf
import PdfPages
134 all_wire_anode = list()
136 plane_colors=[
"blue",
"red",
"black"]
138 with PdfPages(pdffile)
as pdf:
140 for anode
in store.anodes:
146 for iface
in anode.faces:
147 face = store.faces[iface]
149 for iplane
in face.planes:
150 plane = store.planes[iplane]
151 wires_in_plane = [store.wires[wind]
for wind
in plane.wires]
152 wires = [w
for w
in wires_in_plane
if w.segment == 0]
153 def pt(w):
return store.points[w.head]
154 wires.sort(key=
lambda a: pt(a).z)
158 edge_z.append(p.z/units.m)
159 edge_x.append(p.x/units.m)
160 edge_n.append(w.channel)
161 edge_s.append(
'f%d p%d c%d wid%d' % (face.ident, plane.ident, w.channel, w.ident))
165 fig, ax = plt.subplots(nrows=1, ncols=1)
166 ax.scatter(edge_z, edge_x, s=1, c=
'red', marker=
'.')
167 for i,(z,x,s)
in enumerate(
zip(edge_z, edge_x, edge_s)):
168 hal = [
"left",
"right"][i%2]
169 ax.text(z, x, s, horizontalalignment=hal,
170 bbox=dict(facecolor=
'yellow', alpha=0.5, pad=1))
171 for i
in range(len(edge_n)//2):
172 z = 0.5*(edge_z[2*i]+edge_z[2*i+1])
173 n = 1+
abs(edge_n[2*i] - edge_n[2*i+1])
175 ax.text(z, x,
str(n), horizontalalignment=
'center',
176 bbox=dict(facecolor=
'yellow', alpha=0.5, pad=1))
179 ax.set_title(
"Edge Channels AnodeID: %d" % (anode.ident))
180 ax.set_xlabel(
"Z [meter]")
181 ax.set_ylabel(
"X [meter]")
185 for anode
in store.anodes:
186 seg_x1 = [list(),list(),list()]
187 seg_x2 = [list(),list(),list()]
188 seg_z1 = [list(),list(),list()]
189 seg_z2 = [list(),list(),list()]
190 seg_col = [list(),list(),list()]
191 for iface
in anode.faces:
192 face = store.faces[iface]
193 for iplane
in face.planes:
194 plane = store.planes[iplane]
195 for wind
in plane.wires:
196 wire = store.wires[wind]
197 p1 = store.points[wire.tail]
198 p2 = store.points[wire.head]
200 seg_x1[seg].append(p1.x/units.meter)
201 seg_x2[seg].append(p2.x/units.meter)
202 seg_z1[seg].append(p1.z/units.meter)
203 seg_z2[seg].append(p2.z/units.meter)
204 seg_col[seg].append(plane_colors[iplane%(len(plane_colors))])
209 fig, axes = plt.subplots(nrows=3, ncols=1)
212 ax.scatter(seg_z2[seg], seg_x2[seg], c=seg_col[seg], s=1, marker=
'.')
213 ax.set_title(
"AnodeID %d wires, seg %d, head (%d wires)" %
214 (anode.ident, seg, len(seg_col[seg])))
219 fig, axes = plt.subplots(nrows=3, ncols=1)
222 ax.scatter(seg_z1[seg], seg_x1[seg], c=seg_col[seg], s=1, marker=
'.')
223 ax.set_title(
"AnodeID %d wires, seg %d, tail (%d wires)" %
224 (anode.ident, seg, len(seg_col[seg])))
230 for anode
in store.anodes:
238 for iface
in anode.faces:
239 face = store.faces[iface]
243 for iplane
in face.planes:
244 plane = store.planes[iplane]
246 print (
"anodeID:%d faceID:%d planeID:%d" %
247 (anode.ident, face.ident, plane.ident))
249 first_wires.append(plane.wires[:2])
251 fig, ax = plt.subplots(nrows=1, ncols=1)
252 ax.set_aspect(
'equal',
'box')
253 for wind
in plane.wires[::wire_step]:
254 wire = store.wires[wind]
255 p1 = store.points[wire.tail]
256 p2 = store.points[wire.head]
257 width = wire.segment + .1
258 ax.plot((p1.z/units.meter, p2.z/units.meter),
259 (p1.y/units.meter, p2.y/units.meter), linewidth = width)
260 wire_x1.append(p1.x/units.meter)
261 wire_z1.append(p1.z/units.meter)
262 wire_x2.append(p2.x/units.meter)
263 wire_z2.append(p2.z/units.meter)
264 wire_anode.append(anode.ident)
267 for wcount, wind
in enumerate([plane.wires[0], plane.wires[-1]]):
268 wire = store.wires[wind]
269 print (
"\twcount:%d wind:%d wident:%d chan:%d" % (wcount,wind,wire.ident,wire.channel))
270 p1 = store.points[wire.tail]
271 p2 = store.points[wire.head]
274 wirex = p2.x/units.meter
279 t=
'%s wid:%d ch:%d' %([
"beg",
"end"][wcount], wire.ident, wire.channel)
281 horizontalalignment=hal,
282 bbox=dict(facecolor=
'yellow', alpha=0.5, pad=10))
297 ax.set_xlabel(
"Z [meter]")
298 ax.set_ylabel(
"Y [meter]")
299 ax.set_title(
"AnodeID %d, FaceID %d, PlaneID %d every %dth wire, x=%.3fm" % \
300 (anode.ident, face.ident, plane.ident, wire_step, wirex))
306 fig, axes = plt.subplots(nrows=2, ncols=2)
307 for iplane,winds
in enumerate(first_wires):
308 plane_color =
"red green blue".
split()[iplane]
309 w0 = store.wires[winds[0]]
310 h0 = numpy.asarray(store.points[w0.head])
311 t0 = numpy.asarray(store.points[w0.tail])
312 w1 = store.wires[winds[1]]
313 h1 = numpy.asarray(store.points[w1.head])
314 t1 = numpy.asarray(store.points[w1.tail])
325 w = w/math.sqrt(numpy.sum(w*w))
328 r = r/math.sqrt(numpy.sum(r*r))
331 x = x/math.sqrt(numpy.sum(x*x))
335 axes[0,0].arrow(0,0, pt[2], pt[1], color=plane_color, linewidth=ipt+1)
336 axes[0,1].arrow(0,0, pt[2], pt[0], color=plane_color, linewidth=ipt+1)
337 axes[1,0].arrow(0,0, pt[0], pt[1], color=plane_color, linewidth=ipt+1)
339 for a,t
in zip(axes.flatten(),[
"Z vs Y",
"X vs Y",
"Z vs X",
"none"]):
340 a.set_aspect(
'equal')
341 a.set_title(
"%s anode: %d, face: %d" % (t, anode.ident, face.ident))
353 fig, ax = plt.subplots(nrows=1, ncols=1)
354 ax.scatter(wire_z1, wire_x1,s=1, c=wire_anode, marker=
'.')
355 ax.set_title(
"AnodeID %d wires, tail" % anode.ident)
358 fig, ax = plt.subplots(nrows=1, ncols=1)
359 ax.scatter(wire_z2, wire_x2,s=1, c=wire_anode, marker=
'.')
360 ax.set_title(
"AnodeID %d wires, head" % anode.ident)
363 all_wire_x1 += wire_x1
364 all_wire_z1 += wire_z1
365 all_wire_x2 += wire_x2
366 all_wire_z2 += wire_z2
367 all_wire_anode += wire_anode
370 fig, ax = plt.subplots(nrows=1, ncols=1)
371 ax.scatter(all_wire_z1, all_wire_x1,s=1, c=all_wire_anode,marker=
'.')
372 ax.set_title(
"All wires, tail")
375 fig, ax = plt.subplots(nrows=1, ncols=1)
376 ax.scatter(all_wire_z2, all_wire_x2,s=1, c=all_wire_anode,marker=
'.')
377 ax.set_title(
"All wires, head")
384 ax = fig.add_subplot(111)
386 face = store.faces[iface]
387 for planeid
in face.planes:
388 plane = store.planes[planeid]
389 for wind
in plane.wires[::20]:
390 wire = store.wires[wind]
391 if segments
and not wire.segment
in segments:
394 p1 = store.points[wire.tail]
395 p2 = store.points[wire.head]
397 width = wire.segment + 1
398 ax.plot((p1.z, p2.z), (p1.y, p2.y), linewidth = width)
404 ax = fig.add_subplot(111)
407 plane = store.planes[store.faces[0].planes[iplane]]
408 wires = [store.wires[w]
for w
in plane.wires]
411 cmap = plt.get_cmap(
'seismic')
412 colors = [
cmap(i)
for i
in numpy.linspace(0, 1, nwires)]
415 p1 = store.points[wire.tail]
416 p2 = store.points[wire.head]
418 color = colors[iwire]
419 ax.plot((p1.z, p2.z), (p1.y, p2.y), color=color)
445 ax.add_patch(mpatches.Rectangle(rect.ll, rect.width, rect.height,
446 color=color, fill=
False))
447 ax.set_xlabel(
"APA-local Z")
448 ax.set_ylabel(
"APA-local Y")
449 ax.set_title(
"Looking in anti-drift direction")
453 cmap = plt.get_cmap(
'seismic')
455 colors = [
cmap(i)
for i
in numpy.linspace(0, 1, npts)]
457 x = numpy.asarray((p1.x, p2.x))
458 y = numpy.asarray((p1.y, p2.y))
459 plt.plot(x, y, linewidth=ind+1)
463 cmap = plt.get_cmap(
'seismic')
466 chans = [w[2]
for w
in wires]
469 nchans = maxchan - minchan + 1
471 colors = [
cmap(i)
for i
in numpy.linspace(0, 1, nchans)]
473 pitch, side, ch, seg, p1, p2 = one
477 color = colors[ch-minchan]
479 x = numpy.asarray((p1.x, p2.x))
480 y = numpy.asarray((p1.y, p2.y))
481 plt.plot(x, y, color=color, linewidth = seg+1, linestyle = linestyle)
485 plotwires([w
for w
in wires
if w[2]%group_size == ind])
489 rect = Rectangle(6.0, 10.0)
492 for offset
in numpy.linspace(.1, 6, 60):
493 start =
Point(-3.0 + offset, 5.0)
494 ray = Ray(start, start+direc)
502 bbmin, bbmax = wobj.bounding_box
503 xmin, xmax = bbmin[2],bbmax[2]
504 ymin, ymax = bbmin[1],bbmax[1]
512 wirenums = [w.wire
for w
in wires]
513 minwire =
min(wirenums)
514 maxwire =
max(wirenums)
515 nwires = maxwire-minwire+1
518 wires = [w
for w
in wires
if wire_filter(w)]
519 print (
"filter leaves %d wires" % len(wires))
521 ax.set_aspect(
'equal',
'box')
522 ax.add_patch(mpatches.Rectangle((xmin, ymin), dx, dy,
523 color=
"black", fill=
False))
525 cmap = plt.get_cmap(
'rainbow')
527 colors = [
cmap(i)
for i
in numpy.linspace(0, 1, nwires)]
529 color = colors[one.wire-minwire]
530 x = numpy.asarray((one.beg[2], one.end[2]))
531 y = numpy.asarray((one.beg[1], one.end[1]))
532 plt.plot(x, y, color=color)
534 plt.plot([ xmin + 0.5*dx ], [ ymin + 0.5*dy ],
"o")
536 plt.axis([xmin,xmax,ymin,ymax])
def plot_wires(wobj, wire_filter=None)
def select_channels(store, pdffile, channels, labels=True)
def plot_wires_sparse(wires, indices, group_size=40)
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
def face_in_allplanes(store, iface=0, segments=None)
def wrap_one(start_ray, rect)
def oneplane(store, iplane, segments=None)
def plot_rect(rect, color="black")
static int max(int a, int b)
def allplanes(store, pdffile)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
void split(std::string const &s, char c, OutIter dest)