2 import matplotlib.pyplot
as plt
3 import matplotlib
as mpl
4 from matplotlib.collections
import LineCollection
5 from matplotlib.ticker
import AutoMinorLocator
6 from matplotlib.colors
import LogNorm
8 from collections
import defaultdict
9 from wirecell
import units
14 def __init__(self, nx, xmin, xmax, ny, ymin, ymax):
15 self.
arr = numpy.zeros((ny, nx))
23 xrel =
max(0,
min(1.0, (x - xmin) / (xmax-xmin)))
24 return int(xrel * self.
nx);
28 yrel =
max(0,
min(1.0, (y - ymin) / (ymax-ymin)))
29 return int(yrel * self.
ny);
40 return ax.imshow(self.
arr, extent=self.
extent())
48 Given a ClusterMap, return a figure showing activity 52 for snode
in cm.nodes_oftype(
's'):
53 sdat = cm.gr.nodes[snode]
54 for c
in sdat[
'activity'].
keys():
56 slices.add(sdat[
'ident'])
62 print (
"activity: c:[%d,%d], s:[%d,%d]" % (cmin, cmax, smin, smax))
64 hist =
Hist2D(smax-smin+1, smin, smax+1,
65 cmax-cmin+1, cmin, cmax+1)
66 for snode
in cm.nodes_oftype(
's'):
67 sdat = cm.gr.nodes[snode]
69 for c,v
in sdat[
'activity'].items():
71 hist.fill(si+.1, ci+.1, v)
80 for bnode
in cm.nodes_oftype(
'b'):
81 bdat = cm.gr.nodes[bnode]
82 for wnode
in cm.gr[bnode]:
83 wdat = cm.gr.nodes[wnode]
84 if wdat[
'code'] !=
'w':
87 hist.fill(bdat[
'sliceid']+0.1, wdat[
'chid']+.1, 1)
97 Plot the activity with blobs masked out 99 cmap = plt.get_cmap(
'gist_rainbow')
101 cmap.set_bad(color=
'black')
102 arr = numpy.ma.masked_where(sel(b), a)
103 fig,ax = plt.subplots(nrows=1, ncols=1)
104 fig.set_size_inches(8.5,11.0)
105 im = ax.imshow(arr, cmap=cmap, interpolation=
'none', extent=extent)
106 minorLocator = AutoMinorLocator()
107 ax.yaxis.set_minor_locator(minorLocator)
108 ax.tick_params(which=
"both", width=1)
109 ax.tick_params(which=
"major", length=7)
110 ax.tick_params(which=
"minor", length=3)
111 plt.colorbar(im, ax=ax)
116 Plot slice information as criss crossing wires and blob regions. 118 from .
import converter
120 snodes = cm.find(
's', ident=sliceid)
122 print (
"Unexpected number of slices with ID: %d, found %d" % (sliceid, len(snodes)))
125 by_face = defaultdict(list)
126 sdata = cm.gr.nodes[snode]
127 for cdat,cval
in sdata[
"activity"].items():
129 cnode = cm.channel(chid)
130 cdata = cm.gr.nodes[cnode]
131 wnodes = cm.neighbors_oftype(cnode,
'w')
133 print(
"No wires for channel %d" % chid)
135 wdat = cm.gr.nodes[wnode]
138 by_face[f].append((cval, wdat))
140 blob_xs_byface = defaultdict(list)
141 blob_ys_byface = defaultdict(list)
142 blob_cs_byface = defaultdict(list)
143 for bnode
in cm.neighbors_oftype(snode,
'b'):
144 bdata = cm.gr.nodes[bnode]
147 cpoints = converter.orderpoints(bdata[
'corners'])
148 for cp
in cpoints + [cpoints[0]]:
149 cx.append(cp[2]/units.m)
150 cy.append(cp[1]/units.m)
151 faceid = bdata[
'faceid']
152 blob_xs_byface[faceid].append(cx)
153 blob_ys_byface[faceid].append(cy)
154 blob_cs_byface[faceid].append(bdata[
'value'])
157 cmap = plt.get_cmap(
'gist_rainbow')
159 fig,axes = plt.subplots(nrows=1, ncols=len(by_face))
163 for ind, (faceid, wdats)
in enumerate(sorted(by_face.items())):
165 ax.set_title(
"face %d" % faceid)
166 ax.set_xlabel(
"Z [m]")
167 ax.set_ylabel(
"Y [m]")
172 for cval, wdat
in wdats:
176 c = [0.5*(h[i]+t[i])
for i
in range(3)]
183 toffset = (chid%5) * 0.2
187 ax.text(t[2]/units.m, t[1]/units.m + toffset,
"C%d" %chid, fontsize=0.2, rotation=90, va=
'top')
189 ax.text(c[2]/units.m, c[1]/units.m-toffset,
"P%d WID%d WIP%d" %(p,wid,wip), fontsize=0.2, rotation=90, va=
'top')
190 ax.plot([c[2]/units.m,c[2]/units.m], [c[1]/units.m, c[1]/units.m-toffset],
191 color=
'black', linewidth = 0.1, alpha=0.5)
195 ax.text(h[2]/units.m, h[1]/units.m - toffset,
"C%d" %chid, fontsize=0.2, rotation=90, va=
'bottom')
196 ax.plot([h[2]/units.m,h[2]/units.m], [h[1]/units.m - toffset, h[1]/units.m],
197 color=
'black', linewidth = 0.1, alpha=0.5)
199 ax.text(c[2]/units.m+toffset, c[1]/units.m,
"P%d WID%d WIP%d" %(p,wid,wip), fontsize=0.2, rotation=0, va=
'top')
200 ax.plot([c[2]/units.m+toffset,c[2]/units.m], [c[1]/units.m, c[1]/units.m],
201 color=
'black', linewidth = 0.1, alpha=0.5)
203 xs.append([t[2]/units.m, h[2]/units.m])
204 ys.append([t[1]/units.m, h[1]/units.m])
207 segments = [numpy.column_stack([x,y])
for x,y
in zip(xs, ys)]
208 lc = LineCollection(segments, cmap=cmap, linewidth=linewidth, alpha=0.5, norm=LogNorm())
209 lc.set_array(numpy.asarray(cs))
210 ax.add_collection(lc)
212 fig.colorbar(lc, ax=ax)
214 segments = [numpy.column_stack([x,y])
for x,y
in zip(blob_xs_byface[faceid], blob_ys_byface[faceid])]
215 lc = LineCollection(segments, linewidth=2*linewidth, alpha=0.5)
216 lc.set_array(numpy.asarray(blob_cs_byface[faceid]))
217 ax.add_collection(lc)
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
def mask_blobs(a, b, sel=lambda a:a< 1, extent=None)
def wire_blob_slice(cm, sliceid)
static int max(int a, int b)
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.
def __init__(self, nx, xmin, xmax, ny, ymin, ymax)