3 from wirecell
import units
9 Wire Cell Signal Simulation Commands 12 @cli.command(
"unitify-depos")
13 @click.option(
"-j",
"--json_path", default=
'depos',
14 help=
"Data structure path to the deposition array in the input file.")
15 @click.option(
"-d",
"--distance_unit", default=
'mm',
16 help=
"Set the unit of distance assumed in the input file (for x,y,z,s).")
17 @click.option(
"-t",
"--time_unit", default=
'ns',
18 help=
"Set the unit of time assumed in the input file (for t).")
19 @click.option(
"-e",
"--energy_unit", default=
'MeV',
20 help=
"Set the unit of energy assumed in the input file (for q).")
21 @click.option(
"-s",
"--step_unit", default=
None,
22 help=
"Set the unit of step, if different than distance (for s).")
23 @click.argument(
"input-file")
24 @click.argument(
"output-file")
27 distance_unit, time_unit, energy_unit, step_unit,
28 input_file, output_file):
30 Set units for a WCT JSON deposition file. 32 The units given are what the input file should be assumed to 33 follow. The output file will then be in WCT's system of units. 37 import depos
as deposmod
38 depos = deposmod.load(input_file)
39 depos = deposmod.apply_units(depos, distance_unit, time_unit, energy_unit, step_unit);
40 deposmod.dump(output_file, depos)
43 @cli.command(
"move-depos")
44 @click.option(
"-j",
"--json_path", default=
'depos',
45 help=
"Data structure path to the deposition array in the input file.")
46 @click.option(
"-c",
"--center", nargs=3,
47 help=
'Move deposition distribution to given x,y,z center. eg -c 1*m 2*cm 3*um')
48 @click.option(
"-o",
"--offset", nargs=3,
49 help=
'Move deposition by vector offset. eg -c 1*m 2*cm 3*um')
50 @click.argument(
"input-file")
51 @click.argument(
"output-file")
54 input_file, output_file):
56 Apply some transformations to a file of JSON depos and create a new file. 58 import depos
as deposmod
59 depos = deposmod.load(input_file)
62 center = tuple([
float(eval(c, units.__dict__))
for c
in center])
63 depos = deposmod.center(depos, center)
66 offset = tuple([
float(eval(c, units.__dict__))
for c
in offset])
67 depos = deposmod.move(depos, offset)
68 deposmod.dump(output_file, depos)
70 @cli.command(
"plot-depos")
71 @click.option(
"-j",
"--json_path", default=
'depos',
72 help=
"Data structure path to the deposition array in the input file.")
73 @click.option(
"-p",
"--plot", default=
'nxz',
74 help=
"The plot to make.")
75 @click.argument(
"input-file")
76 @click.argument(
"output-file")
79 input_file, output_file):
81 Make a plot from a WCT JSON depo file 83 import depos
as deposmod
84 plotter = getattr(deposmod,
"plot_"+plot)
85 depos = deposmod.load(input_file)
86 plotter(depos, output_file)
88 @cli.command(
"plot-test-boundaries")
89 @click.option(
"-t",
"--times", default=[100.0,105.0], type=float, nargs=2,
90 help=
"Two range of times over which to limit frame plots, in ms.")
91 @click.argument(
"npz-file")
92 @click.argument(
"pdf-file")
96 Make some plots from the boundaries test. 98 wire-cell -c gen/test/test_boundaries.jsonnet 100 this makes a test_boundaries.npz file which is input to this command. 105 from matplotlib.backends.backend_pdf
import PdfPages
106 import matplotlib.pyplot
as plt
108 f = numpy.load(npz_file);
110 fnums = [
int(k.split(
'_')[-1])
for k
in f.keys()
if k.startswith(
"frame")]
111 dnums = [
int(k.split(
'_')[-1])
for k
in f.keys()
if k.startswith(
"depo_data")]
113 with PdfPages(pdf_file)
as pdf:
118 fig, axes = fo.plot(t0=times[0]*units.ms, tf=times[1]*units.ms, raw=
False)
119 fig.suptitle(
"Frame %d" % fnum)
125 fig, axes = depo.plot()
126 fig.suptitle(
"Depo group %d" % fnum)
130 @cli.command(
"plot-sim")
131 @click.argument(
"input-file")
132 @click.argument(
"output-file")
133 @click.option(
"--ticks/--no-ticks", default=
False,
134 help=
"Plot ticks, not time.")
135 @click.option(
"-p",
"--plot", default=
'frame',
136 help=
"The plot to make.")
137 @click.option(
"--tag", default=
'',
138 help=
"The frame tag.")
139 @click.option(
"-t",
"--time-range", default=
'',
140 help=
"The time range in ms.")
141 @click.option(
"-n",
"--number", default=0,
142 help=
"The number of the frame or depo set to plot.")
143 @click.option(
"-c",
"--channel-groups", default=
'',
144 help=
"Indices of channel groups as comma separated list.")
145 @click.option(
"-b",
"--channel-boundaries", default=
'',
146 help=
"Channels at which there are boundaries.")
148 def plot_sim(ctx, input_file, output_file, ticks, plot, tag, time_range, number, channel_groups, channel_boundaries):
150 Make plots of sim quantities saved into numpy array files. 153 from wirecell
import units
155 import matplotlib.pyplot
as plt
156 from matplotlib.backends.backend_pdf
import PdfPages
164 fp = numpy.load(input_file)
167 print "Frames: %s" %(
', '.join([k
for k
in fp.keys()
if k.startswith(
"frame")]), )
172 print "All channel groups: ", ch
174 ch = [ch[
int(ci)]
for ci
in channel_groups.split(
",")]
175 print "Using groups: ", ch
179 plotter = fr.plot_ticks
180 t0,tf = [
int(t,10)
for t
in time_range.split(
",")]
183 t0,tf = [
float(t)*units.ms
for t
in time_range.split(
",")]
186 fig, axes = plotter(t0, tf, raw=
False, chinds=ch)
187 plt.savefig(output_file)
190 print "Depos: %s" %(
', '.join([k
for k
in fp.keys()
if k.startswith(
"depo_data")]), )
192 fig, axes = deps.plot()
193 plt.savefig(output_file)
198 if '__main__' == __name__:
def unitify_depos(ctx, json_path, distance_unit, time_unit, energy_unit, step_unit, input_file, output_file)
def parse_channel_boundaries(cb)
def plot_sim(ctx, input_file, output_file, ticks, plot, tag, time_range, number, channel_groups, channel_boundaries)
def plot_depos(ctx, json_path, plot, input_file, output_file)
def group_channel_indices(channels, boundaries=())
def plot_test_boundaries(ctx, times, npz_file, pdf_file)
def move_depos(ctx, json_path, center, offset, input_file, output_file)