5 fixme: this module is poorly named. 8 from wirecell
import units
10 import matplotlib.pyplot
as plt
11 from mpl_toolkits.mplot3d
import Axes3D
13 matplotlib.rcParams[
'axes.formatter.useoffset'] =
False 17 Return a new frame array (chan x tick) were each channel row has 18 its baseline subtracted. 21 return (frame.T - numpy.median(frame, axis=1)).T
27 return tuple(map(int, cb.split(
',')))
32 Given a list of channels, return a list of lists where each 33 sublist is a sequential set. If a sequence of boundaries are 34 given, then force a grouping on that channel even if there's not 38 print (
"Channel boundaries: %s" %
str(boundaries))
40 channels = numpy.asarray(channels)
41 chan_list = channels.tolist()
45 i = chan_list.index(b)
50 chd = channels[1:] - channels[:-1]
51 chjumps = [-1] + list(numpy.where(chd>1)[0]) + [channels.size-1]
53 for a,b
in zip(chjumps[:-1], chjumps[1:]):
60 if a < bind
and bind < b:
71 arr = fp[
'%s_%s_%d' % (n, tag, ident)]
76 for n
in 'frame channels tickinfo'.
split():
77 setattr(self, n, thing(n))
81 def plot_ticks(self, tick0=0, tickf=-1, raw=True, chinds = ()):
83 Plot in terms of ticks. Here, the frame is assumed to be 84 dense and chinds are taken as channel ranges. 87 print (
"Frame shape: %s" %
str(frame.shape))
96 tick = self.tickinfo[1]
98 tickf += frame.shape[1]
100 ngroups = len(chinds)
101 fig, axes = plt.subplots(nrows=ngroups, ncols=1, sharex =
True)
105 for ax, chind
in zip(axes, chinds):
107 ch1 = self.channels[chind[0]]
108 ch2 = self.channels[chind[1]-1]
110 extent = (tick0, tickf, ch2, ch1)
111 print (
"exent: %s" %
str(extent))
113 im = ax.imshow(frame[chind[0]:chind[1],tick0:tickf],
114 aspect=
'auto', extent=extent, interpolation=
'none')
115 plt.colorbar(im, ax=ax)
117 ax.set_xlabel(
'ticks (%.2f us)' % (tick/units.us),)
121 def plot(self, t0=None, tf=None, raw=True, chinds = ()):
127 tstart, tick = self.tickinfo[:2]
128 nticks = frame.shape[1]
129 tend = tstart + nticks*tick
131 if t0
is None or t0 < tstart
or t0 > tend:
134 if tf
is None or tf < t0
or tf > tend:
137 tick0 =
int((t0-tstart)/tick)
138 tickf =
int((tf-tstart)/tick)
144 ngroups = len(chinds)
145 fig, axes = plt.subplots(nrows=ngroups, ncols=1, sharex =
True)
149 for ax, chind
in zip(axes, chinds):
154 ch1 = self.channels[chind0]
155 ch2 = self.channels[chind1-1]
157 extent = (t0/units.ms, tf/units.ms, ch2, ch1)
158 print (
"exent: %s, chind=(%d,%d)" % (
str(extent), chind0, chind1) )
162 im = ax.imshow(frame[chind0:chind1,tick0:tickf],
163 aspect=
'auto', extent=extent, interpolation=
'none')
164 plt.colorbar(im, ax=ax)
166 ax.set_xlabel(
'time [ms]')
183 self.
data = fp[
'depo_data_%d'%ident]
185 self.
info = fp[
'depo_info_%d'%ident]
205 ax10 = fig.add_subplot(223)
206 ax00 = fig.add_subplot(221)
207 ax11 = fig.add_subplot(224, sharey=ax10)
208 ax01 = fig.add_subplot(222, projection=
'3d')
211 ax00.hist(self.
t/units.ms, 100)
213 ax10.scatter(self.
x/units.m, self.
z/units.m)
214 ax11.scatter(self.
y/units.m, self.
z/units.m)
215 ax01.scatter(self.
x/units.m, self.
y/units.m, self.
z/units.m)
217 ax00.set_title(
'depo times [ms]');
219 ax10.set_xlabel(
'x [m]');
220 ax10.set_ylabel(
'z [m]');
221 ax11.set_xlabel(
'y [m]');
222 ax11.set_ylabel(
'z [m]');
230 return fig,(ax00,ax10,ax01,ax11)
238 f = numpy.load(filename)
def plot_ticks(self, tick0=0, tickf=-1, raw=True, chinds=())
def plot(self, t0=None, tf=None, raw=True, chinds=())
def parse_channel_boundaries(cb)
def __init__(self, fp, ident=0, tag='')
def baseline_subtract(frame)
def group_channel_indices(channels, boundaries=())
def __init__(self, filename)
def __init__(self, fp, ident=0)
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
void split(std::string const &s, char c, OutIter dest)