print '1..3' di = np.arange(1001, dtype='u8') do = bin_data(di, 10) good = len(do) == 100 and all(do['counts'][0:100] == 10) result(good, 'basic binning') # Check that partial bins are thrown away di = np.arange(1000, 1555, dtype='u8') do = bin_data(di, 100) good = len(do) == 5 \ and all(do['counts'] == 100) \ and all(do['time'] == np.arange(1000,1500,100)) result(good, 'partial bins') di = np.array([0, 100, 110], dtype='u8') do = bin_data(di, 10) good = len(do) == 11 \ and do['counts'][0] == 1 \ and all(do['counts'][1:9] == 0) \ and do['counts'][10] == 1 result(good, 'bin_photons zero bins test') di = np.array([200, 300, 400, 500], dtype='u8') do = bin_photons(di, 100, 0, 1000) good = np.all(do['count'] == [0, 0, 1, 1, 1, 1, 0, 0, 0, 0]) \ and np.all(do['start_t'] == [0, 100, 200, 300, 400, 500, 600, 700, 800, 900]) result(good, 'bin_photons start_t/end_t')
print('1..3') di = np.arange(1001, dtype='u8') do = bin_data(di, 10) good = len(do) == 100 and all(do['counts'][0:100] == 10) result(good, 'basic binning') # Check that partial bins are thrown away di = np.arange(1000, 1555, dtype='u8') do = bin_data(di, 100) good = len(do) == 5 \ and all(do['counts'] == 100) \ and all(do['time'] == np.arange(1000,1500,100)) result(good, 'partial bins') di = np.array([0, 100, 110], dtype='u8') do = bin_data(di, 10) good = len(do) == 11 \ and do['counts'][0] == 1 \ and all(do['counts'][1:9] == 0) \ and do['counts'][10] == 1 result(good, 'bin_photons zero bins test') di = np.array([200, 300, 400, 500], dtype='u8') do = bin_photons(di, 100, 0, 1000) good = np.all(do['count'] == [0, 0, 1, 1, 1, 1, 0, 0, 0, 0]) \ and np.all(do['start_t'] == [0, 100, 200, 300, 400, 500, 600, 700, 800, 900]) result(good, 'bin_photons start_t/end_t')
#!/usr/bin/python import matplotlib.pyplot as pl import numpy as np from photon_tools.bin_photons import bin_photons jiffy = 1/128e6 # seconds width = 1e-3 # seconds spans = np.genfromtxt('spans') points = np.genfromtxt('points') ts = np.fromfile('2011-07-04-run_001.strobe1.times', dtype='u8') dts = ts[1:] - ts[:-1] bins = bin_photons(ts, width / jiffy) pl.subplot(211) pl.xlabel(r'Time (s)') pl.ylabel(r'Rate') pl.plot(jiffy*bins['start_t'], bins['count']/width, '+') for (a,b) in spans: pl.axvspan(jiffy*ts[a], jiffy*ts[b], color='g', alpha=0.3) pl.xlim(jiffy*ts[0], jiffy*ts[0] + 2) pl.subplot(212) pl.semilogy(jiffy*ts[:len(points)], points[:,2], '+') pl.axhline(2, color='g') pl.ylabel(r'$\beta$') pl.xlim(jiffy*ts[0], jiffy*ts[0] + 2) pl.show()
return runs.reshape(-1, 2) - [0,1] import argparse parser = argparse.ArgumentParser() parser.add_argument('file', nargs='+', help='Timestamp files') parser.add_argument('-w', '--bin-width', type=float, default=0.1, help='Bin width in seconds') parser.add_argument('-b', '--buffer', type=float, default=0.2, help='Amount of time before and after burst to drop') parser.add_argument('-t', '--threshold', type=float, default=10, help='Threshold (multiple of the median count') args = parser.parse_args() for fname in args.file: f = read_photons.open(fname) bins = bin_photons(f.channel(0), bin_width=args.bin_width / f.jiffy, include_zeros=False) counts = bins['count'] t = bins['start_t'] thresh = args.threshold * np.median(counts) bursts = np.array(find_runs(counts > thresh)) starts = t[bursts[:,0]] - args.buffer / f.jiffy ends = t[bursts[:,1]] + args.buffer / f.jiffy print('%s: Found %d bursts above threshold of %f / bin' % (fname, len(bursts), thresh)) pl.clf() pl.plot(t * f.jiffy, counts, '+') for start,end in zip(starts, ends): pl.axvspan(start * f.jiffy, end * f.jiffy, alpha=0.3, color='k') pl.savefig(fname+'-bursts.png')