import mathutils from mathutils import * from plotutils import * #f = "2018/03/12/20180312_231754_WireScan.h5|" #f = "2018/03/12/20180312_233008_WireScan.h5|" f = "2018/03/12/20180312_234230_WireScan.h5|" #p = f + "/x_000" p = f + "/y_000" def gd(i): global p return load_data(p+str(i)+"/blm1") def gt(i): global p return load_data(p+str(i)+"/Time") def gp(i): global p return load_data(p+str(i)+"/w_pos") def bg(i): global f return load_data(f+"/background/blm" + str(i)) def bga(blm): global f return get_attributes(f+"/background/blm" + str(blm))["Mean"] def sig(i): bg = bga(1) ret = gd(i) #ret = blm_remove_spikes(ret) ret = [v-bg for v in ret] return ret epsilon = 1e-10 def make_monotonic(x): for i in range(len(x)-1): if x[i+1]<= x[i]: x[i+1] = x[i] + epsilon return x x = [x1,x2,x3,x4,x5,x6]= [gp(1), gp(2), gp(3), gp(4), gp(5), gp(6)] #plot(x, ["1", "2", "3", "4", "5", "6"], xdata = x) s = [s1, s1, s3, s4, s5, s6] = [sig(1), sig(2), sig(3), sig(4), sig(5), sig(6)] p=plot(s, ["1", "2", "3", "4", "5", "6"], xdata = x) #print call_jep(MODULE, "profile_rms_stats", [to_npa(x), to_npa(y), 0, 3.5]) run("Diagnostics/sig_process_wrapper") print "------------------ Gauss ---------------------------" sum_mean=0.0 sum_sigma=0.0 sum_norm=0.0 mathutils.MAX_EVALUATIONS = mathutils.MAX_EVALUATIONS*10 for i in range(6): [off, amp, com, sigma] = profile_gauss_stats(x[i], s[i], off=None, amp=None, com=None, sigma=None) #[amp, com, sigma] = profile_gauss_stats(x[i], s[i], off=None, amp=None, com=None, sigma=None, with_offset=False) """ if i%2 == 0: (amp, com, sigma) = fit_gaussian(s[i], make_monotonic(x[i])) else : (amp, com, sigma) = fit_gaussian(s[i][::-1], make_monotonic(x[i][::-1])) """ #print "Pass " , (i+1) ,": " , [off, amp, com, sigma] sum_mean = sum_mean + com sum_sigma = sum_sigma + sigma sum_norm = sum_norm + amp plot_function(p[i], Gaussian(amp, com, sigma), "Fit",x[i], show_points = False, show_lines = True, color = Color.BLUE) ave_mean, ave_sigma = sum_mean/6, sum_sigma/6 print "Average: mean=" , ave_mean, ave_sigma print "------------------ RMS ---------------------------" sum_com=0.0 sum_sigma=0.0 for i in range(6): #[rms_com, rms_sigma] = profile_rms_stats(x[i], s[i],noise_std=0, n_sigma=3.5) [off, amp, com, sigma] = profile_gauss_stats(x[i], s[i], off=None, amp=None, com=None, sigma=None) [rms_com, rms_sigma] = profile_rms_stats_with_estimate(x[i], s[i], com_estimate = com, window_size = sigma *3.5) print "Pass " , (i+1) ,": " , [rms_com, rms_sigma] sum_com = sum_com+ rms_com sum_sigma = sum_sigma + rms_sigma print "Average: mean=" , sum_com/6, " sigma=", sum_sigma/6