def testcw(fname, t_initial, t_final, two_pulse_fit, one_pulse, sigma0, sum_mu, sum_tau, sum_a, sum_b, diff_tau, diff_a, diff_b, sampling, burn, thin, height_th, Plot=True, debug=False): result, mcmc_flag, unequal_edges = fit_two_cw(*hpa.trace_extr(fname, height_th, t_initial=t_initial, t_final=t_final), sigma0=sigma0, # signal noise sum_mu=sum_mu, sum_tau=sum_tau, sum_a=sum_a, sum_b=sum_b, diff_tau=diff_tau, diff_a=diff_a, diff_b=diff_b, two_pulse_fit=two_pulse_fit, one_pulse=one_pulse, height_th=height_th, sampling=sampling, burn=burn, thin=thin, Plot=Plot, debug=debug) # pymc.gelman_rubin() #https://pymc-devs.github.io/pymc/modelchecking.html # print 'test' if Plot: plt.figure(figsize=(10,5)) plt.plot(*hpa.trace_extr(fname,height_th,t_initial,t_final), label='unwindowed', color='grey') result.plot_fit(data_kws={'alpha':0.5, 'marker':'.'}) # plt.savefig(results_directory+'testmcmccw.pdf') print result.fit_report() print ('arrival time difference = {:.2f}ns'.\ format((result.best_values['one_x_offset']-result.best_values['two_x_offset'])*1e9)) return result, mcmc_flag, unequal_edges # def testcw(i, sampling, burn, thin, height_th, Plot=True): # result, mcmc_flag, unequal_edges = fit_two_cw(*hpa.trace_extr(filelist_cont[:10000][mask_2ph_cont][i], # t_initial, t_final), # height_th=height_th, # sampling=sampling, # burn=burn, # thin=thin, # debug=True) # # pymc.gelman_rubin() #https://pymc-devs.github.io/pymc/modelchecking.html # if Plot: # plt.figure() # plt.plot(*hpa.trace_extr(filelist_cont[mask_2ph_cont][i]), label='unwindowed', color='grey', alpha=0.5) # result.plot_fit(data_kws={'alpha':0.5, 'marker':'.'}) # plt.savefig(results_directory+'testmcmccw.pdf') # print result.fit_report() # print ('arrival time difference = {:.2f}ns'.\ # format((result.init_values['one_x_offset']-result.init_values['two_x_offset'])*1e9)) # return result, mcmc_flag, unequal_edges
def trace_simple_ave(filelist, height_th, t_initial=None, t_final=None): time, _ = hpa.trace_extr(filelist[0], t_initial, t_final) a = [hpa.trace_extr(file, t_initial, t_final)[1] for file in filelist] # reduce to trace length to avoid edge effects idx_0 = int(len(time) / 30) v_len = len(time) - 2 * idx_0 time = time[idx_0:idx_0 + v_len] a = [line[idx_0:idx_0 + v_len] for line in a] amean = np.nanmean(a, 0) bg = np.median(amean[amean < height_th]) return time, amean - bg, np.std(amean - bg)
def fit_corrected_pulse(filelist, fit_model, t_initial=None, t_final=None): time, _ = hps.trace_extr(filelist[0], t_initial, t_final) a = [ fit_shift(*hps.trace_extr(file, t_initial, t_final), fit_model=fit_model) for file in filelist ] # reduce to trace length to avoid edge effects idx_0 = int(len(time) / 30) v_len = len(time) - 2 * idx_0 time = time[idx_0:idx_0 + v_len] a = [line[idx_0:idx_0 + v_len] for line in a] return time, np.nanmean(a, 0)
def trace_ave(filelist, height_th, t_initial=None, t_final=None, smooth=201): time, _ = hps.trace_extr(filelist[0], height_th, t_initial, t_final) a = [ time_offset(*hps.trace_extr(file, height_th, t_initial, t_final), height_th=height_th) for file in filelist ] # reduce to trace length to avoid edge effects idx_0 = int(len(time) / 30) v_len = len(time) - 2 * idx_0 time = time[idx_0:idx_0 + v_len] a = [line[idx_0:idx_0 + v_len] for line in a] return time, savgol_filter(np.nanmean(a, 0), smooth, 3)
def fit_corrected_pulse(filelist, height_th, fit_model, t_initial=None, t_final=None): time, _ = hps.trace_extr(filelist[0], height_th, t_initial, t_final) a = [ fit_shift(*hps.trace_extr(file, height_th, t_initial, t_final), fit_model=fit_model, height_th=height_th) for file in filelist ] # reduce to trace length to avoid edge effects idx_0 = int(len(time) / 30) v_len = len(time) - 2 * idx_0 time = time[idx_0:idx_0 + v_len] a = [line[idx_0:idx_0 + v_len] for line in a] a_avg = np.nanmean(a, 0) a_std = np.nanstd(a, 0) # bg = np.median(a[a<0.5*np.max(a)]) # a_fs = savgol_filter(a_avg, 101, 5) hist_fs = np.histogram(a_avg[a_avg < np.max(a_avg / 2)], 500) a_avg = a_avg - hist_fs[1][np.argmax(hist_fs[0])] return time, a_avg, a_std # def fit_corrected_pulse(filelist, height_th, fit_model, t_initial=None, t_final=None): # time, _ = hps.trace_extr(filelist[0], height_th, t_initial, t_final) # a = [fit_shift(*hps.trace_extr(file, height_th, t_initial, t_final), # fit_model=fit_model) # for file # in filelist] # # reduce to trace length to avoid edge effects # idx_0 = int(len(time) / 30) # v_len = len(time) - 2 * idx_0 # time = time[idx_0:idx_0 + v_len] # a = [line[idx_0:idx_0 + v_len] for line in a] # a_avg = np.nanmean(a, 0) # a_std = np.nanstd(a, 0) # # bg = np.median(a[a<0.5*np.max(a)]) # # a_fs = savgol_filter(a_avg, 101, 5) # hist_fs = np.histogram(a_avg[a_avg<np.max(a_avg/2)], 500) # a_avg = a_avg - hist_fs[1][np.argmax(hist_fs[0])] # return time, a_avg, a_std
def g2(filelist, t_initial=None, t_final=None): return [time_diff(*hps.trace_extr(file, t_initial, t_final)) for file in filelist]
params=p, # weights=1 / yerr, # method=method ) return result, result_mcmc """Import source traces""" directory_name_source = '/workspace/projects/TES/data/20170126_TES5_n012_distinguishibility_20MHz_tau_vs_offset/200ns/' filelist_200ns = np.array(glob.glob(directory_name_source + '*.trc')) data_200ns = np.array([ hpa.param_extr(f, t_initial=None, t_final=None, h_th=height_th) for f in tqdm.tqdm(filelist_200ns[:10000]) ]) """Testing mcmc on one trace""" mdl = fit_two_mcmc(*hpa.trace_extr(filelist_200ns[mask_2ph_200ns][0], t_initial, t_final), sampling=1.5e4) def testmcmc(i, iters, height_th, Plot=True): result, result_mcmc = fit_two(*trace_extr( filelist_200ns[mask_2ph_200ns][i], t_initial, t_final, height_th=height_th), sampling=iters) # pymc.gelman_rubin() #https://pymc-devs.github.io/pymc/modelchecking.html if Plot: plt.figure() plt.plot(*trace_extr(filelist_200ns[mask_2ph_200ns][i]), label='unwindowed')