Functions
wirecell.gen.main Namespace Reference

Functions

def cli (ctx)
 
def unitify_depos (ctx, json_path, distance_unit, time_unit, energy_unit, step_unit, input_file, output_file)
 
def move_depos (ctx, json_path, center, offset, input_file, output_file)
 
def plot_depos (ctx, json_path, plot, input_file, output_file)
 
def plot_test_boundaries (ctx, times, npz_file, pdf_file)
 
def plot_sim (ctx, input_file, output_file, ticks, plot, tag, time_range, number, channel_groups, channel_boundaries)
 
def main ()
 

Function Documentation

def wirecell.gen.main.cli (   ctx)
Wire Cell Signal Simulation Commands

Definition at line 7 of file main.py.

7 def cli(ctx):
8  '''
9  Wire Cell Signal Simulation Commands
10  '''
11 
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")
25 @click.pass_context
def cli(ctx)
Definition: main.py:7
def wirecell.gen.main.main ( void  )

Definition at line 195 of file main.py.

195 def main():
196  cli(obj=dict())
197 
def main()
Definition: main.py:195
def cli(ctx)
Definition: main.py:7
def wirecell.gen.main.move_depos (   ctx,
  json_path,
  center,
  offset,
  input_file,
  output_file 
)
Apply some transformations to a file of JSON depos and create a new file.

Definition at line 54 of file main.py.

54  input_file, output_file):
55  '''
56  Apply some transformations to a file of JSON depos and create a new file.
57  '''
58  import depos as deposmod
59  depos = deposmod.load(input_file)
60 
61  if center:
62  center = tuple([float(eval(c, units.__dict__)) for c in center])
63  depos = deposmod.center(depos, center)
64 
65  if offset:
66  offset = tuple([float(eval(c, units.__dict__)) for c in offset])
67  depos = deposmod.move(depos, offset)
68  deposmod.dump(output_file, depos)
69 
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")
77 @click.pass_context
def wirecell.gen.main.plot_depos (   ctx,
  json_path,
  plot,
  input_file,
  output_file 
)
Make a plot from a WCT JSON depo file

Definition at line 79 of file main.py.

79  input_file, output_file):
80  '''
81  Make a plot from a WCT JSON depo file
82  '''
83  import depos as deposmod
84  plotter = getattr(deposmod, "plot_"+plot)
85  depos = deposmod.load(input_file)
86  plotter(depos, output_file)
87 
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")
93 @click.pass_context
def wirecell.gen.main.plot_sim (   ctx,
  input_file,
  output_file,
  ticks,
  plot,
  tag,
  time_range,
  number,
  channel_groups,
  channel_boundaries 
)
Make plots of sim quantities saved into numpy array files.

Definition at line 148 of file main.py.

148 def plot_sim(ctx, input_file, output_file, ticks, plot, tag, time_range, number, channel_groups, channel_boundaries):
149  '''
150  Make plots of sim quantities saved into numpy array files.
151  '''
152  import wirecell.gen.sim
153  from wirecell import units
154  import numpy
155  import matplotlib.pyplot as plt
156  from matplotlib.backends.backend_pdf import PdfPages
157 
158  if not time_range:
159  if ticks:
160  time_range = "0,-1"
161  else:
162  time_range = '0,5'
163 
164  fp = numpy.load(input_file)
165 
166  if 'frame' in plot:
167  print "Frames: %s" %(', '.join([k for k in fp.keys() if k.startswith("frame")]), )
168  fr = wirecell.gen.sim.Frame(fp, tag=tag, ident=number)
169 
170  channel_boundaries = wirecell.gen.sim.parse_channel_boundaries(channel_boundaries)
171  ch = wirecell.gen.sim.group_channel_indices(fr.channels, channel_boundaries)
172  print "All channel groups: ", ch
173  if channel_groups:
174  ch = [ch[int(ci)] for ci in channel_groups.split(",")]
175  print "Using groups: ", ch
176 
177 
178  if ticks:
179  plotter = fr.plot_ticks
180  t0,tf = [int(t,10) for t in time_range.split(",")]
181  else:
182  plotter = fr.plot
183  t0,tf = [float(t)*units.ms for t in time_range.split(",")]
184 
185 
186  fig, axes = plotter(t0, tf, raw=False, chinds=ch)
187  plt.savefig(output_file)
188 
189  if 'depo' in plot:
190  print "Depos: %s" %(', '.join([k for k in fp.keys() if k.startswith("depo_data")]), )
191  deps = wirecell.gen.sim.Depos(fp, ident=number)
192  fig, axes = deps.plot()
193  plt.savefig(output_file)
194 
def parse_channel_boundaries(cb)
Definition: sim.py:24
def plot_sim(ctx, input_file, output_file, ticks, plot, tag, time_range, number, channel_groups, channel_boundaries)
Definition: main.py:148
def group_channel_indices(channels, boundaries=())
Definition: sim.py:30
def wirecell.gen.main.plot_test_boundaries (   ctx,
  times,
  npz_file,
  pdf_file 
)
Make some plots from the boundaries test.

    wire-cell -c gen/test/test_boundaries.jsonnet

this makes a test_boundaries.npz file which is input to this command.

Definition at line 94 of file main.py.

94 def plot_test_boundaries(ctx, times, npz_file, pdf_file):
95  '''
96  Make some plots from the boundaries test.
97 
98  wire-cell -c gen/test/test_boundaries.jsonnet
99 
100  this makes a test_boundaries.npz file which is input to this command.
101  '''
102  print (times)
103 
104  from wirecell.gen import sim
105  from matplotlib.backends.backend_pdf import PdfPages
106  import matplotlib.pyplot as plt
107  import numpy
108  f = numpy.load(npz_file);
109 
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")]
112 
113  with PdfPages(pdf_file) as pdf:
114 
115  for fnum in fnums:
116  fo = sim.Frame(f, fnum)
117 
118  fig, axes = fo.plot(t0=times[0]*units.ms, tf=times[1]*units.ms, raw=False)
119  fig.suptitle("Frame %d" % fnum)
120  pdf.savefig(fig)
121  plt.close()
122 
123  for dnum in dnums:
124  depo = sim.Depos(f, dnum)
125  fig, axes = depo.plot()
126  fig.suptitle("Depo group %d" % fnum)
127  pdf.savefig(fig)
128  plt.close()
129 
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.")
147 @click.pass_context
def plot_test_boundaries(ctx, times, npz_file, pdf_file)
Definition: main.py:94
def wirecell.gen.main.unitify_depos (   ctx,
  json_path,
  distance_unit,
  time_unit,
  energy_unit,
  step_unit,
  input_file,
  output_file 
)
Set units for a WCT JSON deposition file.

The units given are what the input file should be assumed to
follow.  The output file will then be in WCT's system of units.

Definition at line 28 of file main.py.

28  input_file, output_file):
29  '''
30  Set units for a WCT JSON deposition file.
31 
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.
34 
35  '''
36 
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)
41 
42 
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")
52 @click.pass_context