depo2tvtk.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 '''
3 Convert a Numpy file produced by NumpyDepoSaver into a vtk file which
4 can be visualized with paraview.
5 '''
6 import os
7 import math
8 import numpy
9 from wirecell import units
10 from collections import defaultdict
11 from tvtk.api import tvtk, write_data
12 from tvtk.common import configure_input
13 
14 import rendertvtk;
15 
16 
17 def main(infile, outname=None, toffset=1*units.us, speed=1.6*units.mm/units.us):
18  if outname is None or outname == "-":
19  outname = os.path.splitext(infile)[0]
20 
21  if type(speed) == type(""):
22  speed = eval(speed)
23  if type(toffset) == type(""):
24  toffset = eval(toffset)
25 
26 
27  print("toffset=%f us, speed=%f mm/us" %
28  (toffset/units.us, speed/(units.mm/units.us)))
29 
30  arrs = numpy.load(infile)
31  depos = arrs['depo_data_0']
32 
33 
34  # depos is a 7xN array
35  # (t,q,x,y,z,dl,dt)
36 
37  #
38  # pack into array of : dict(
39  # point= [x,y,z],
40  # values=dict(name1=val1, name2=val2, ...)
41  # )
42 
43  points = list()
44  for one in depos.T:
45  t,q,x,y,z,dl,dt = one
46  rx = x + (t-toffset)*speed
47  # size=(dl,dt,dt)
48  p = dict(point=[-rx,y,z], values=dict(time=t,charge=q))
49  points.append(p)
50 
51  pointdata = rendertvtk.points(points)
52  ofile = outname + "-depos.vtp"
53  print(ofile)
54  write_data(pointdata, ofile)
55 
56 
57 if '__main__' == __name__:
58  import sys
59  main(*sys.argv[1:])
60 
61 
std::enable_if< internal::is_string< String >::value >::type print(std::FILE *f, const text_style &ts, const String &format_str, const Args &...args)
Definition: color.h:549
def main(infile, outname=None, toffset=1 *units.us, speed=1.6 *units.mm/units.us)
Definition: depo2tvtk.py:17
def points(jdat)
Definition: rendertvtk.py:105