run("Diagnostics/sig_process_wrapper") root = "2017/05/05/20170505_123536_WireScan.h5|/" #"2017/05/04/20170504_182411_WireScan.h5|/" wire = "x" blms = ["",""] cycles = 3 stats = [] for i in range(len(blms)): path_back = root + "background/blm" + str(i+1) bg = get_attributes(path_back)["Mean"] samples = [[], [], [], []] for cycle in range (cycles): pos = load_data(root + wire+"_" + ("%04d" % (cycle+1)) + "/w_pos") path = root + wire+"_" + ("%04d" % (cycle+1)) + "/blm" + str(i+1) data = load_data(path) sp = blm_remove_spikes(data) sig = sp if bg is None else [v-bg for v in sp] rms_com, rms = profile_rms_stats(pos, sig,noise_std=0, n_sigma=3.5) #set_attribute(path, "RMS", float("nan") if (rms is None) else rms) #set_attribute(path, "RMS COM", float("nan") if (rms_com is None) else rms_com) print [rms_com, rms] off, amp, com, sigma = profile_gauss_stats(pos, sig, off=None, amp=None, com=None, sigma=None) #set_attribute(path, "Gauss COM", float("nan") if (com is None) else com) #set_attribute(path, "Gauss Sigma", float("nan") if (sigma is None) else sigma) print [off, amp, com, sigma] samples[0].append(rms_com);samples[1].append(rms);samples[2].append(com);samples[3].append(sigma) from mathutils import Gaussian g = Gaussian(amp, com, sigma) gauss = [g.value(v)+off for v in pos] plot([data, sp, sig, gauss], ["data", "sp", "signal", "gauss", ], xdata = pos, title="Fit blm" + str(i+1) + " - " + str(cycle+1)) stats.append([]) for sample in samples: sample = [v for v in sample if v is not None] stats[i].append( (mean(sample), stdev(sample)) if len(sample)>0 else (float("nan"), float("nan")) ) print stats msg = "" for i in range(len(blms)): msg += "Wire " + wire + " - BLM " + str(i) + ":\n" msg += " RMS: " + "%.4f" % stats[i][0][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][0][1] + "\n" msg += " RMS COM: " + "%.4f" % stats[i][1][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][1][1] + "\n" msg += " Gauss COM: " + "%.4f" % stats[i][2][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][2][1] + "\n" msg += " Gauss Sigma: " + "%.4f" % stats[i][3][0] + " " + unichr(0x03C3) + "=" + "%.4f" % stats[i][3][1] + "\n" print msg