#!/photonics/home/gac-alvra/.conda/envs/adaq/bin/python from collections import defaultdict import numpy as np from bstrd import BS, bsstream #from zoetrope import aniplot as plt #plt.blit = False chname = "SARES11-SPEC125-M1.edge_amplitude" ch = BS(chname) pids = BS("pid") nblock = 100 def analyse(data): data = np.array(data) delta = np.diff(data) x, y = discrete_histogram(delta) return x, y def discrete_histogram(data): left_of_first_bin = data.min() - 1/2 right_of_last_bin = data.max() + 1/2 bins = np.arange(left_of_first_bin, right_of_last_bin+1) hist, edges = np.histogram(data, bins=bins) edges += 1/2 edges = edges.astype(int) return edges, hist #xs = [1] #ys = [0] #pd = plt.step([1], [0]) i = 0 seen = [] accum = defaultdict(int) #for counter, _ in zip(plt.show(), bsstream): # print(counter) for _ in bsstream: curr = pids.get() seen.append(curr) if len(seen) == nblock: res = analyse(seen) for x, y in zip(*res): accum[x] += y xs, ys = zip(*accum.items()) print(xs) print(ys) print() xs = np.array(xs) ys = np.array(ys) one = (xs == 1) other = (xs != 1) one = ys[one].sum() other = ( (xs[other] - 1) * ys[other] ).sum() print(round(other / one * 100, 1), one, other) # pd.set(xs, ys) # i += 1 # if i == 3: # break last = seen[-1] seen = [last] # use the last entry of the previous round as new first entry bsstream.stop()