255 def magnify_plot(ctx, name, trebin, crebin, baseline, threshold, saturate, out, filename):
257 Plot magnify histograms. 260 from root_numpy
import hist2array
as h2a
267 tfile = ROOT.TFile.Open(filename)
268 hists = [tfile.Get(
"h%s_%s"%(letter, name))
for letter
in "uvw"]
270 raise ValueError(
'Could not get hists for "%s" from: %s' % (name, filename))
274 aes = [h2a(h,return_edges=
True)
for h
in hists]
277 for h,(a,e)
in zip(hists,aes):
278 xa,ya = [getattr(h,
"Get"+l+
"axis")()
for l
in "XY"]
279 nx,ny = [getattr(h,
"GetNbins"+l)()
for l
in "XY"]
283 ext = ((ce[0],ce[-1]), (te[0],te[-1]))
285 print "%s: X:%d in [%.0f %.0f] Y:%d in [%.0f %.0f]" % \
287 nx, xa.GetBinLowEdge(1), xa.GetBinUpEdge(nx),
288 ny, ya.GetBinLowEdge(1), ya.GetBinUpEdge(ny),)
289 print "\t shape=%s ext=%s" % (a.shape, ext)
291 arrs.append(numpy.fliplr(a))
295 norm = 1.0/(crebin*trebin)
305 digi = numpy.int32(wav)
308 values, counts = numpy.unique(digi, return_counts=
True)
309 ind = numpy.argmax(counts)
314 newarr = numpy.asarray(newarr)
315 bla = numpy.asarray(bl)
316 bla =
rebin(bla, bla.size/crebin)
317 baselines.append(bla)
318 newarrs.append(newarr)
321 arrs = [
bin_ndarray(arr, (arr.shape[0]/crebin, arr.shape[1]/trebin),
"mean")
for arr
in arrs]
323 tit =
'Type "%s" (rebin: ch=x%d tick=x%d), file:%s' % (name, crebin, trebin, os.path.basename(filename))
327 tit +=
" [threshold at %d]" % threshold
328 arrs = [numpy.ma.masked_where(numpy.abs(arr)<=threshold, arr)
for arr
in arrs]
335 arr[arr > saturate] = saturate
336 arr[arr <-saturate] = -saturate
341 arrs = [a.T
for a
in arrs]
342 extents = [(e[0][0], e[0][1], e[1][0], e[1][1])
for e
in extents]
344 for a,e
in zip(arrs,extents):
def magnify_plot(ctx, name, trebin, crebin, baseline, threshold, saturate, out, filename)
static QInternalList< QTextCodec > * all
def three_horiz(arrs, extents, name, baselines)
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
def bin_ndarray(ndarray, new_shape, operation='sum')