7 import matplotlib.pyplot
as plt
9 from wirecell
import units
15 Wire Cell Toolkit Imaging Commands 18 @cli.command(
"paraview-blobs")
19 @click.argument(
"cluster-tap-file")
20 @click.argument(
"paraview-file")
24 Convert a JsonClusterTap JSON file to a ParaView .vtu file of blobs 26 from .
import converter, tap
27 from tvtk.api
import write_data
29 gr = tap.load(cluster_tap_file)
30 if 0 == gr.number_of_nodes():
31 click.echo(
"no verticies in %s" % cluster_tap_file)
33 dat = converter.clusters2blobs(gr)
34 write_data(dat, paraview_file)
35 click.echo(paraview_file)
38 @cli.command(
"paraview-activity")
39 @click.argument(
"cluster-tap-file")
40 @click.argument(
"paraview-file")
44 Convert a JsonClusterTap JSON file to a ParaView .vti file of activity 46 from .
import converter, tap
47 from tvtk.api
import write_data
49 gr = tap.load(cluster_tap_file)
50 if 0 == gr.number_of_nodes():
51 click.echo(
"no verticies in %s" % cluster_tap_file)
53 alldat = converter.clusters2views(gr)
54 for wpid,dat
in alldat.items():
55 fname = paraview_file%wpid
56 write_data(dat, fname)
61 @cli.command(
"paraview-depos")
62 @click.argument(
"depo-npz-file")
63 @click.argument(
"paraview-file")
67 Convert an NPZ file to a ParaView .vtu file of depos 69 from .
import converter
70 from tvtk.api
import write_data
73 fp = numpy.load(
open(depo_npz_file))
74 dat = fp[
'depo_data_0']
75 ugrid = converter.depos2pts(dat);
76 write_data(ugrid, paraview_file)
77 click.echo(paraview_file)
84 @cli.command(
"bee-blobs")
85 @click.option(
'-o',
'--output', help=
"The output Bee JSON file name")
86 @click.option(
'-g',
'--geom', default=
"protodune",
87 help=
"The name of the detector geometry")
88 @click.option(
'--rse', nargs=3, type=int, default=[0, 0, 0],
89 help=
"The '<run> <subrun> <event>' numbers as a triple of integers")
90 @click.option(
'-s',
'--sampling', type=click.Choice([
"center",
"uniform"]), default=
"uniform",
91 help=
"The sampling technique to turn blob volumes into points")
92 @click.option(
'-d',
'--density', type=float, default=9.0,
93 help=
"For samplings which care, specify target points per cc")
94 @click.argument(
"cluster-tap-files", nargs=-1)
95 def bee_blobs(output, geom, rse, sampling, density, cluster_tap_files):
97 Make one Bee JSON file from the blobs in a set of 'cluster tap' 98 JSON files which are presumed to originate from one trigger. 100 from .
import tap, converter
102 dat = dict(runNo=rse[0], subRunNo=rse[1], eventNo=rse[2], geom=geom, type=
"wire-cell",
103 x=list(), y=list(), z=list(), q=list())
107 return [round(a, 3)
for a
in arr]
110 density *= 1.0/(units.cm**3)
111 sampling_func = dict(
112 center = converter.blob_center,
113 uniform =
lambda b : converter.blob_uniform_sample(b, density),
116 for ctf
in cluster_tap_files:
118 print (
"got %d" % gr.number_of_nodes())
119 if 0 == gr.number_of_nodes():
120 print(
"skipping empty graph %s" % ctf)
122 arr = converter.blobpoints(gr, sampling_func)
123 print (
"%s: %d points" % (ctf, arr.shape[0]))
124 dat[
'x'] += fclean(arr[:,0]/units.cm)
125 dat[
'y'] += fclean(arr[:,1]/units.cm)
126 dat[
'z'] += fclean(arr[:,2]/units.cm)
127 dat[
'q'] += fclean(arr[:,3])
131 from json
import encoder
132 encoder.FLOAT_REPR =
lambda o:
format(o,
'.3f')
133 json.dump(dat,
open(output,
'w', encoding=
"utf8"))
137 @cli.command(
"activity")
138 @click.option(
'-o',
'--output', help=
"The output plot file name")
139 @click.option(
'-s',
'--slices', nargs=2, type=int,
140 help=
"Range of slice IDs")
141 @click.option(
'-S',
'--slice-line', type=int, default=-1,
142 help=
"Draw a line down a slice")
143 @click.argument(
"cluster-tap-file")
144 def activity(output, slices, slice_line, cluster_tap_file):
148 from matplotlib.colors
import LogNorm
149 from .
import tap, clusters, plots
150 gr = tap.load(cluster_tap_file)
152 ahist = plots.activity(cm)
156 arr = arr[:,slices[0]:slices[1]]
157 extent = [slices[0], slices[1]]
159 extent = [0, arr.shape[1]]
160 extent += [ahist.rangey[1], ahist.rangey[0]]
162 fig,ax = plt.subplots(nrows=1, ncols=1)
163 fig.set_size_inches(8.5,11.0)
165 cmap = plt.get_cmap(
'gist_rainbow')
166 im = ax.imshow(arr, cmap=cmap, interpolation=
'none', norm=LogNorm(), extent=extent)
168 ax.plot([slice_line, slice_line], [ahist.rangey[0], ahist.rangey[1]],
169 linewidth=0.1, color=
'black')
173 for chunk
in [400, 400, 400, 400, 480, 480]:
175 y = boundary + ahist.rangey[0]
176 ax.plot(extent[:2], [y,y], color=
'gray', linewidth=0.1);
178 from matplotlib.ticker
import AutoMinorLocator
179 minorLocator = AutoMinorLocator()
180 ax.yaxis.set_minor_locator(minorLocator)
181 ax.tick_params(which=
"both", width=1)
182 ax.tick_params(which=
"major", length=7)
183 ax.tick_params(which=
"minor", length=3)
185 plt.colorbar(im, ax=ax)
186 ax.set_title(cluster_tap_file)
187 ax.set_xlabel(
"slice ID")
188 ax.set_ylabel(
"channel IDs")
192 @cli.command(
"blob-activity-mask")
193 @click.option(
'-o',
'--output', help=
"The output plot file name")
194 @click.option(
'-s',
'--slices', nargs=2, type=int,
195 help=
"The output plot file name")
196 @click.option(
'-S',
'--slice-line', type=int, default=-1,
197 help=
"Draw a line down a slice")
198 @click.option(
'--found/--missed', default=
True,
199 help=
"Mask what blobs found or missed")
200 @click.argument(
"cluster-tap-file")
203 Plot blobs as maskes on channel activity. 205 from .
import tap, clusters, plots
206 gr = tap.load(cluster_tap_file)
208 ahist = plots.activity(cm)
210 plots.blobs(cm, bhist)
212 sel =
lambda a: a>= 1
215 sel =
lambda a: a < 1
219 a = ahist.arr[:,slices[0]:slices[1]]
220 b = bhist.arr[:,slices[0]:slices[1]]
221 extent = [slices[0], slices[1]]
225 extent = [0, a.shape[1]]
226 extent += [ahist.rangey[1], ahist.rangey[0]]
228 fig,ax = plots.mask_blobs(a, b, sel, extent)
230 ax.plot([slice_line, slice_line], [ahist.rangey[0], ahist.rangey[1]],
231 linewidth=0.1, color=
'black')
232 ax.set_title(
"%s %s" % (title, cluster_tap_file))
233 ax.set_xlabel(
"slice ID")
234 ax.set_ylabel(
"channel IDs")
238 @cli.command(
"wire-slice-activity")
239 @click.option(
'-o',
'--output', help=
"The output plot file name")
240 @click.option(
'-s',
'--sliceid', type=int, help=
"The slice ID to plot")
241 @click.argument(
"cluster-tap-file")
244 Plot the activity in one slice as wires and blobs 246 from .
import tap, clusters, plots
247 gr = tap.load(cluster_tap_file)
249 fig, axes = plots.wire_blob_slice(cm, sliceid)
256 if '__main__' == __name__:
def paraview_blobs(ctx, cluster_tap_file, paraview_file)
def blob_activity_mask(output, slices, slice_line, found, cluster_tap_file)
int open(const char *, int)
Opens a file descriptor.
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
def wire_slice_activity(output, sliceid, cluster_tap_file)
def activity(output, slices, slice_line, cluster_tap_file)
def paraview_activity(ctx, cluster_tap_file, paraview_file)
def bee_blobs(output, geom, rse, sampling, density, cluster_tap_files)