def read_data(filename, dpath_pion_mp, dpath_pion_pp, dpath_etas_mp, dpath_etas_pp, plot='off'): pion_mp = c51.fold(c51.open_data(filename, dpath_pion_mp)) pion_pp = c51.fold(c51.open_data(filename, dpath_pion_pp)) etas_mp = c51.fold(c51.open_data(filename, dpath_etas_mp)) etas_pp = c51.fold(c51.open_data(filename, dpath_etas_pp)) #pion_mp = c51.open_data(filename, dpath_pion_mp) #pion_pp = c51.open_data(filename, dpath_pion_pp) #etas_mp = c51.open_data(filename, dpath_etas_mp) #etas_pp = c51.open_data(filename, dpath_etas_pp) pion = pion_mp / pion_pp etas = etas_mp / etas_pp pion_gv = c51.make_gvars(pion) etas_gv = c51.make_gvars(etas) pion_gv = gv.gvar(np.array([pion_gv[i].mean for i in range(len(pion_gv))]), np.array([pion_gv[j].sdev for j in range(len(pion_gv))])) etas_gv = gv.gvar(np.array([etas_gv[i].mean for i in range(len(pion_gv))]), np.array([etas_gv[j].sdev for j in range(len(pion_gv))])) if plot == 'on': x = np.arange(len(pion_gv)) c51.scatter_plot(x, pion_gv, title='pion mres') c51.scatter_plot(x, etas_gv, title='etas mres') else: pass return pion_gv, etas_gv
def read_data(filename, dpath_pion_mp, dpath_pion_pp, dpath_etas_mp, dpath_etas_pp, plot='off'): pion_mp = c51.fold(c51.open_data(filename, dpath_pion_mp)) pion_pp = c51.fold(c51.open_data(filename, dpath_pion_pp)) etas_mp = c51.fold(c51.open_data(filename, dpath_etas_mp)) etas_pp = c51.fold(c51.open_data(filename, dpath_etas_pp)) #pion_mp = c51.open_data(filename, dpath_pion_mp) #pion_pp = c51.open_data(filename, dpath_pion_pp) #etas_mp = c51.open_data(filename, dpath_etas_mp) #etas_pp = c51.open_data(filename, dpath_etas_pp) pion = pion_mp/pion_pp etas = etas_mp/etas_pp pion_gv = c51.make_gvars(pion) etas_gv = c51.make_gvars(etas) pion_gv = gv.gvar(np.array([pion_gv[i].mean for i in range(len(pion_gv))]), np.array([pion_gv[j].sdev for j in range(len(pion_gv))])) etas_gv = gv.gvar(np.array([etas_gv[i].mean for i in range(len(pion_gv))]), np.array([etas_gv[j].sdev for j in range(len(pion_gv))])) if plot=='on': x = np.arange(len(pion_gv)) c51.scatter_plot(x, pion_gv, title='pion mres') c51.scatter_plot(x, etas_gv, title='etas mres') else: pass return pion_gv, etas_gv
def fit_proton(pr, p_avg, T): # priors priors = c51.dict_of_tuple_to_gvar(pr.priors['proton']) # trange trange = pr.trange['proton'] # make data # ss + ps p_data = np.concatenate((p_avg[:, :, 0, 0], p_avg[:, :, 3, 0]), axis=1) # ss #p_data = p_avg[:,:,0,0] # ps #p_data = p_avg[:,:,3,0] p_data = c51.make_gvars(p_data) # fit grandfit = dict() for n in range(2, 3): fitfcn = c51.fit_function(T, nstates=n) # ss + ps fit = c51.fitscript_v2(trange, T, p_data, priors, fitfcn.twopt_fitfcn_ss_ps, pr.print_fit_flag) # ss #fit = c51.fitscript_v2(trange, T, p_data, priors, fitfcn.twopt_fitfcn_ss, pr.print_fit_flag) # ps #fit = c51.fitscript_v2(trange, T, p_data, priors, fitfcn.twopt_fitfcn_ps, pr.print_fit_flag) for k in fit.keys(): try: grandfit[k] = np.concatenate((grandfit[k], fit[k]), axis=0) except: grandfit[k] = fit[k] try: grandfit['nstates'] = np.concatenate( (grandfit['nstates'], n * np.ones(len(fit[k]))), axis=0) except: grandfit['nstates'] = n * np.ones(len(fit[k])) return np.array([[0, grandfit]])
def mres_bs(params, meson, draws): #Read data mp = c51.open_data(params.data_loc['file_loc'], params.data_loc['mres_' + meson + '_mp']) pp = c51.open_data(params.data_loc['file_loc'], params.data_loc['mres_' + meson + '_pp']) T = len(pp) mres_dat = mp / pp # plot mres if params.plot_data_flag == 'on': c51.scatter_plot(np.arange(len(mres_dat[0])), c51.make_gvars(mres_dat), meson + ' folded mres') #Read priors prior = params.priors[meson] #Read trange print params.priors trange = params.trange['mres'] print trange #Fit args = ((g, trange, T, mres_dat, prior, draws) for g in range(len(draws))) pool = multi.Pool() p = pool.map_async(mres_fit, args) # sort by bootstrap number output = np.sort(np.array(p.get()), axis=0) return output
def fit_proton(pr, p_avg, T): # priors priors = c51.dict_of_tuple_to_gvar(pr.priors['proton']) # trange trange = pr.trange['proton'] # make data # ss + ps p_data = np.concatenate((p_avg[:,:,0,0], p_avg[:,:,3,0]), axis=1) # ss #p_data = p_avg[:,:,0,0] # ps #p_data = p_avg[:,:,3,0] p_data = c51.make_gvars(p_data) # fit grandfit = dict() for n in range(2,3): fitfcn = c51.fit_function(T, nstates=n) # ss + ps fit = c51.fitscript_v2(trange, T, p_data, priors, fitfcn.twopt_fitfcn_ss_ps, pr.print_fit_flag) # ss #fit = c51.fitscript_v2(trange, T, p_data, priors, fitfcn.twopt_fitfcn_ss, pr.print_fit_flag) # ps #fit = c51.fitscript_v2(trange, T, p_data, priors, fitfcn.twopt_fitfcn_ps, pr.print_fit_flag) for k in fit.keys(): try: grandfit[k] = np.concatenate((grandfit[k], fit[k]), axis=0) except: grandfit[k] = fit[k] try: grandfit['nstates'] = np.concatenate((grandfit['nstates'], n*np.ones(len(fit[k]))), axis=0) except: grandfit['nstates'] = n*np.ones(len(fit[k])) return np.array([[0, grandfit]])
def mres_bs(params, meson, draws): print 'mres', meson ens = params.ens ml = params.ml ms = params.ms loc = params.data_loc #Read data mp = c51.open_data(loc['file_loc'], loc['mres_' + meson + '_mp']) pp = c51.open_data(loc['file_loc'], loc['mres_' + meson + '_pp']) T = len(pp[0]) mres_dat = mp / pp # plot mres if params.plot_data_flag == 'on': c51.scatter_plot(np.arange(len(mres_dat[0])), c51.make_gvars(mres_dat), meson + ' mres') plt.show() #Read priors prior = params.priors[meson] #Read trange trange = params.trange['mres'] #Fit #args = ((g, trange, T, mres_dat, prior, draws) for g in range(len(draws))) #pool = multi.Pool() #p = pool.map_async(mres_fit, args) # sort by bootstrap number #output = np.sort(np.array(p.get()), axis=0) result = [] for g in range(len(draws)): mres_dat_bs = mres_dat[draws[g]] mres_dat_bs = c51.make_gvars(mres_dat_bs) #Randomize priors bsp = c51.dict_of_tuple_to_gvar( prior ) #{'mres': gv.gvar(prior[0]+prior[1]*np.random.randn(), prior[1])} #Fit fitfcn = c51.fit_function(T) fit = c51.fitscript_v2(trange, T, mres_dat_bs, bsp, fitfcn.mres_fitfcn, result_flag='off') result.append([g, fit]) output = np.sort(np.array(result), axis=0) return output
def decay_bs(params, meson, draws): print 'decay ', meson ens = params.ens ml = params.ml ms = params.ms loc = params.data_loc # read data decay_dat = c51.fold(c51.open_data(loc['file_loc'], loc['spec_'+meson])) decay_ss = np.squeeze(decay_dat[:,:,0,:]) decay_ps = np.squeeze(decay_dat[:,:,1,:]) T = 2*len(decay_ss[0]) if params.plot_data_flag == 'on': # unfolded correlator data c51.scatter_plot(np.arange(len(decay_ss[0])), c51.make_gvars(decay_ss), meson+' ss folded') c51.scatter_plot(np.arange(len(decay_ps[0])), c51.make_gvars(decay_ps), meson+' ps folded') # effective mass eff = c51.effective_plots(T) meff_ss = eff.effective_mass(c51.make_gvars(decay_ss), 1, 'cosh') meff_ps = eff.effective_mass(c51.make_gvars(decay_ps), 1, 'cosh') xlim = [3, len(meff_ss)-2] ylim = c51.find_yrange(meff_ss, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_ss)), meff_ss, meson+' ss effective mass', xlim = xlim, ylim = ylim) ylim = c51.find_yrange(meff_ps, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_ps)), meff_ps, meson+' ps effective mass', xlim = xlim, ylim = ylim) # scaled correlator E0 = params.priors[meson]['E0'][0] scaled_ss = eff.scaled_correlator(c51.make_gvars(decay_ss), E0, phase=1.0) scaled_ps = eff.scaled_correlator(c51.make_gvars(decay_ps), E0, phase=1.0) ylim = c51.find_yrange(scaled_ss, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(scaled_ss)), scaled_ss, meson+' ss scaled correlator (take sqrt to get Z0_s)', xlim = xlim, ylim = ylim) ylim = c51.find_yrange(scaled_ps, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(scaled_ps)), scaled_ps, meson+' ps scaled correlator (divide by Z0_s to get Z0_p)', xlim = xlim, ylim = ylim) plt.show() # concatenate data decay_ss_ps = np.concatenate((decay_ss, decay_ps), axis=1) # priors priors = params.priors[meson] # read trange trange = params.trange['twopt'] #Fit #args = ((g, trange, T, decay_ss_ps, priors, draws) for g in range(len(draws))) #pool = multi.Pool() #p = pool.map_async(decay_fit, args) ## sort via bootstrap number #output = np.sort(np.array(p.get()), axis=0) result = [] for g in range(len(draws)): # resample decay data decay_bs = decay_ss_ps[draws[g]] decay_bs = c51.make_gvars(decay_bs) # priors bsp = c51.dict_of_tuple_to_gvar(priors) #Fit fitfcn = c51.fit_function(T, nstates=2) fit = c51.fitscript_v2(trange, T, decay_bs, bsp, fitfcn.twopt_fitfcn_ss_ps, result_flag='off') fit = [g, fit] result.append(fit) output = np.sort(np.array(result), axis=0) return output
def read_data(params): # read data twopt_dat = c51.fold(c51.open_data(params.data_loc['file_loc'], params.data_loc['phiqq_'+params.hadron])) T = 2*len(twopt_dat[0]) if params.plot_data_flag == 'on': # unfolded correlator data c51.scatter_plot(np.arange(len(twopt_dat[0])), c51.make_gvars(twopt_dat), params.hadron+' folded') # effective mass eff = c51.effective_plots(T) meff = eff.effective_mass(c51.make_gvars(twopt_dat), 1, 'cosh') xlim = [2, len(meff)] ylim = c51.find_yrange(meff, xlim[0], xlim[1]) ylim = [0.0, 0.7] c51.scatter_plot(np.arange(len(meff)), meff, params.hadron+' effective mass', xlim = xlim, ylim = ylim) # scaled correlator E0 = params.priors[params.hadron]['E0'][0] scaled = eff.scaled_correlator(c51.make_gvars(twopt_dat), E0, phase=1.0) c51.scatter_plot(np.arange(len(scaled)), scaled, params.hadron+' scaled correlator (A0 = Z0_s*Z0_p)') return twopt_dat, T
def decay_axial(pr, meson, draws): if meson == 'pion': shortname = 'll' elif meson == 'kaon': shortname = 'ls' # read data twopt_dat = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['spec_'+meson]) twopt_ss = np.squeeze(twopt_dat[:,:,0,:]) twopt_ps = np.squeeze(twopt_dat[:,:,1,:]) axial_dat = np.squeeze(c51.open_data(pr.data_loc['file_loc'], pr.data_loc['axial_'+shortname])) T = len(twopt_ss[0]) if pr.plot_data_flag == 'on': # unfolded correlator data c51.scatter_plot(np.arange(len(twopt_ss[0])), c51.make_gvars(twopt_ss), 'two point no fold') c51.scatter_plot(np.arange(len(axial_dat[0])), c51.make_gvars(axial_dat), 'axial_'+shortname+' no fold') # fold data axial_dat = c51.fold(axial_dat, phase=-1.0) twopt_ss = c51.fold(twopt_ss, phase=1.0) twopt_ps = c51.fold(twopt_ps, phase=1.0) if pr.plot_data_flag == 'on': # folded correlator data c51.scatter_plot(np.arange(len(twopt_ss[0])), c51.make_gvars(twopt_ss), 'two point folded') c51.scatter_plot(np.arange(len(axial_dat[0])), c51.make_gvars(axial_dat), 'axial_'+shortname+' folded') # effective mass eff = c51.effective_plots(T) meff = eff.effective_mass(c51.make_gvars(twopt_ss), 1, 'cosh') meff_axial = eff.effective_mass(c51.make_gvars(axial_dat)[1:], 1, 'cosh') xlim = [3, len(meff)] ylim = c51.find_yrange(meff, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff)), meff, 'two pt effective mass', xlim = xlim, ylim = ylim) ylim = c51.find_yrange(meff, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_axial))+1, meff_axial, 'axial_'+shortname+' effective mass', xlim = xlim, ylim = ylim) # scaled correlator E0 = pr.priors[meson]['E0'][0] scaled = eff.scaled_correlator(c51.make_gvars(twopt_ss), E0, phase=1.0) scaled_axial = eff.scaled_correlator(c51.make_gvars(axial_dat)[1:], E0, phase=-1.0) c51.scatter_plot(np.arange(len(scaled)), scaled, 'two pt scaled correlator (take sqrt to get Z0)') c51.scatter_plot(np.arange(len(scaled_axial))+1, scaled_axial, 'axial_'+shortname+' scaled correlator (divide by Z0 to get F0)') # concatenate decay_axial_ss = np.concatenate((axial_dat, twopt_ss), axis=1) # read priors priors = pr.priors[meson] # read trange trange = pr.trange['decay_axial'] # fit args = ((g, trange, T, decay_axial_ss, priors, draws) for g in range(len(draws))) pool = multi.Pool() p = pool.map_async(decay_axial_fit, args) # sort via bootstrap number output = np.sort(np.array(p.get()), axis=0) return output
def fittwo_pt(params, twopt_dat, T): # make data twopt_gv = c51.make_gvars(twopt_dat) # priors priors = params.priors[params.hadron] priors_gv = c51.dict_of_tuple_to_gvar(priors) # read trange trange = params.trange['twopt'] # fit fitfcn = c51.fit_function(T, nstates=1) fit = c51.fitscript_v2(trange, T, twopt_gv, priors_gv, fitfcn.twopt_fitfcn_phiqq, params.print_fit_flag) return np.array([[0, fit]])
def decay_fit(args): g, trange, T, decay_ss_sp_dat, priors, draws = args # resample decay data decay_bs = decay_ss_sp_dat[draws[g]] decay_bs = c51.make_gvars(decay_bs) # priors bsp = c51.dict_of_tuple_to_gvar(priors) #Fit fitfcn = c51.fit_function(T, nstates=2) fit = c51.fitscript_v2(trange, T, decay_bs, bsp, fitfcn.twopt_fitfcn_ss_ps, result_flag='off') fit = [g, fit] return fit
def decay_axial_fit(args): g, trange, T, decay_axial_ss, priors, draws = args # resample decay_axial_ss = c51.make_gvars(decay_axial_ss[draws[g]]) # make priors bsp = c51.dict_of_tuple_to_gvar(priors) # fit fitfcn = c51.fit_function(T, nstates=2) fit = c51.fitscript_v2(trange, T, decay_axial_ss, bsp, fitfcn.axial_twoptss_fitfcn, result_flag='off') # record nbs fit = [g, fit] return fit
def fit_proton(pr, p_avg, T): # priors priors = c51.dict_of_tuple_to_gvar(pr.priors['proton']) # trange trange = pr.trange['proton'] # make data p_data = np.concatenate((p_avg[:,:,0,0], p_avg[:,:,3,0]), axis=1) p_data = c51.make_gvars(p_data) # fit fitfcn = c51.fit_function(T, nstates=6) fit = c51.fitscript_v2(trange, T, p_data, priors, fitfcn.twopt_fitfcn_ss_ps, pr.print_fit_flag) return np.array([[0, fit]])
def read_data(filename, dpath_pion, dpath_kaon, plot='off'): pion = c51.open_data(filename, dpath_pion) kaon = c51.open_data(filename, dpath_kaon) #Fold meson data pion = c51.fold(pion) kaon = c51.fold(kaon) pion_ss = c51.make_gvars(pion[:, :, 0, 0]) pion_ps = c51.make_gvars(pion[:, :, 1, 0]) kaon_ss = c51.make_gvars(kaon[:, :, 0, 0]) kaon_ps = c51.make_gvars(kaon[:, :, 1, 0]) if plot == 'on': dat = pion_ps E0 = 0.237 meff = c51.effective_mass(dat, 1, 'cosh') x = np.arange(len(meff)) xlim = [4, 15] ylim = c51.find_yrange(meff, xlim[0], xlim[1]) c51.scatter_plot(x, meff, 'meff', xlim=xlim, ylim=ylim) scaled2pt = c51.scaled_correlator(dat, E0) ylim = c51.find_yrange(scaled2pt, xlim[0], xlim[1]) c51.scatter_plot(x, scaled2pt, 'scaled 2pt', xlim=xlim, ylim=ylim) ylim = c51.find_yrange(dat, xlim[0], xlim[1]) c51.scatter_plot(x, dat, 'data', xlim=xlim, ylim=ylim) else: pass pion_ss_ps = np.concatenate((pion[:, :, 0, 0], pion[:, :, 1, 0]), axis=1) kaon_ss_ps = np.concatenate((kaon[:, :, 0, 0], kaon[:, :, 1, 0]), axis=1) pion_ss_ps_gv = c51.make_gvars(pion_ss_ps) kaon_ss_ps_gv = c51.make_gvars(kaon_ss_ps) return pion_ss_ps_gv, kaon_ss_ps_gv
def read_data(filename, dpath_pion, dpath_kaon, plot='off'): pion = c51.open_data(filename, dpath_pion) kaon = c51.open_data(filename, dpath_kaon) #Fold meson data pion = c51.fold(pion) kaon = c51.fold(kaon) pion_ss = c51.make_gvars(pion[:,:,0,0]) pion_ps = c51.make_gvars(pion[:,:,1,0]) kaon_ss = c51.make_gvars(kaon[:,:,0,0]) kaon_ps = c51.make_gvars(kaon[:,:,1,0]) if plot=='on': dat = pion_ps E0 = 0.237 meff = c51.effective_mass(dat,1,'cosh') x = np.arange(len(meff)) xlim = [4,15] ylim = c51.find_yrange(meff, xlim[0], xlim[1]) c51.scatter_plot(x, meff, 'meff', xlim = xlim, ylim = ylim) scaled2pt = c51.scaled_correlator(dat, E0) ylim = c51.find_yrange(scaled2pt, xlim[0], xlim[1]) c51.scatter_plot(x, scaled2pt, 'scaled 2pt', xlim=xlim, ylim=ylim) ylim = c51.find_yrange(dat, xlim[0], xlim[1]) c51.scatter_plot(x, dat, 'data', xlim=xlim, ylim=ylim) else: pass pion_ss_ps = np.concatenate((pion[:,:,0,0],pion[:,:,1,0]), axis=1) kaon_ss_ps = np.concatenate((kaon[:,:,0,0],kaon[:,:,1,0]), axis=1) pion_ss_ps_gv = c51.make_gvars(pion_ss_ps) kaon_ss_ps_gv = c51.make_gvars(kaon_ss_ps) return pion_ss_ps_gv, kaon_ss_ps_gv
def mres_fit(args): g, trange, T, mres_dat, prior, draws = args print g #Resample mres data mres_dat_bs = mres_dat[draws[g]] mres_dat_bs = c51.make_gvars(mres_dat_bs) print 'bs' #Randomize priors bsp = c51.dict_of_tuple_to_gvar(prior) #{'mres': gv.gvar(prior[0]+prior[1]*np.random.randn(), prior[1])} #Fit fitfcn = c51.fit_function(T) fit = c51.fitscript_v2(trange, T, mres_dat_bs, bsp, fitfcn.mres_fitfcn, result_flag='off') result = [g, fit] return result
def mres_bs(params, meson, draws): print 'mres', meson ens = params.ens ml = params.ml ms = params.ms loc = params.data_loc #Read data mp = c51.open_data(loc['file_loc'], loc['mres_'+meson+'_mp']) pp = c51.open_data(loc['file_loc'], loc['mres_'+meson+'_pp']) T = len(pp[0]) mres_dat = mp/pp # plot mres if params.plot_data_flag == 'on': c51.scatter_plot(np.arange(len(mres_dat[0])), c51.make_gvars(mres_dat), meson+' mres') plt.show() #Read priors prior = params.priors[meson] #Read trange trange = params.trange['mres'] #Fit #args = ((g, trange, T, mres_dat, prior, draws) for g in range(len(draws))) #pool = multi.Pool() #p = pool.map_async(mres_fit, args) # sort by bootstrap number #output = np.sort(np.array(p.get()), axis=0) result = [] for g in range(len(draws)): mres_dat_bs = mres_dat[draws[g]] mres_dat_bs = c51.make_gvars(mres_dat_bs) #Randomize priors bsp = c51.dict_of_tuple_to_gvar(prior) #{'mres': gv.gvar(prior[0]+prior[1]*np.random.randn(), prior[1])} #Fit fitfcn = c51.fit_function(T) fit = c51.fitscript_v2(trange, T, mres_dat_bs, bsp, fitfcn.mres_fitfcn, result_flag='off') result.append([g, fit]) output = np.sort(np.array(result), axis=0) return output
def mres_fit(args): g, trange, T, mres_dat, prior, draws = args print g #Resample mres data mres_dat_bs = mres_dat[draws[g]] mres_dat_bs = c51.make_gvars(mres_dat_bs) print 'bs' #Randomize priors bsp = c51.dict_of_tuple_to_gvar( prior ) #{'mres': gv.gvar(prior[0]+prior[1]*np.random.randn(), prior[1])} #Fit fitfcn = c51.fit_function(T) fit = c51.fitscript_v2(trange, T, mres_dat_bs, bsp, fitfcn.mres_fitfcn, result_flag='off') result = [g, fit] return result
def mres_bs(params, meson, draws): #Read data mp = c51.open_data(params.data_loc['file_loc'], params.data_loc['mres_'+meson+'_mp']) pp = c51.open_data(params.data_loc['file_loc'], params.data_loc['mres_'+meson+'_pp']) T = len(pp) mres_dat = mp/pp # plot mres if params.plot_data_flag == 'on': c51.scatter_plot(np.arange(len(mres_dat[0])), c51.make_gvars(mres_dat), meson+' folded mres') #Read priors prior = params.priors[meson] #Read trange print params.priors trange = params.trange['mres'] print trange #Fit args = ((g, trange, T, mres_dat, prior, draws) for g in range(len(draws))) pool = multi.Pool() p = pool.map_async(mres_fit, args) # sort by bootstrap number output = np.sort(np.array(p.get()), axis=0) return output
def read_proton(pr): # read data p_up = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['proton_spin_up']) p_dn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['proton_spin_dn']) pnp_up = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['proton_np_spin_up']) pnp_dn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['proton_np_spin_dn']) p_savg = c51.ispin_avg(p_up, p_dn) pnp_savg = c51.ispin_avg(pnp_up, pnp_dn) p_avg = c51.parity_avg(p_savg, pnp_savg, phase=-1.0) T = len(p_avg[0]) p_avg = p_avg[:, :T/2] # keep only first half of data ('folded' length) if pr.plot_data_flag == 'on': # folded correlator data p_ss = p_avg[:,:,0,0] p_ps = p_avg[:,:,3,0] c51.scatter_plot(np.arange(len(p_ss[0])), c51.make_gvars(p_ss), 'proton ss folded') c51.scatter_plot(np.arange(len(p_ps[0])), c51.make_gvars(p_ps), 'proton ps folded') # effective mass eff = c51.effective_plots(T) meff_ss = eff.effective_mass(c51.make_gvars(p_ss)[1:], 1, 'cosh') meff_ps = eff.effective_mass(c51.make_gvars(p_ps)[1:], 1, 'cosh') xlim = [1, len(meff_ss)] #*2/5] #ylim = [0.7, 1.1] ylim = [0.3, 0.9] #ylim = c51.find_yrange(meff_ss, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_ss))+1, meff_ss, 'proton ss effective mass', xlim = xlim, ylim = ylim) #ylim = c51.find_yrange(meff_ps, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_ps))+1, meff_ps, 'proton ps effective mass', xlim = xlim, ylim = ylim) # scaled correlator E0 = pr.priors['proton']['E0'][0] scaled_ss = eff.scaled_correlator(c51.make_gvars(p_ss), E0, phase=1.0) scaled_ps = eff.scaled_correlator(c51.make_gvars(p_ps), E0, phase=1.0) ylim = c51.find_yrange(scaled_ss, xlim[0], xlim[1]/2) c51.scatter_plot(np.arange(len(scaled_ss)), scaled_ss, 'proton ss scaled correlator (take sqrt to get Z0_s)', xlim = xlim, ylim = ylim) ylim = c51.find_yrange(scaled_ps, xlim[0], xlim[1]/2) c51.scatter_plot(np.arange(len(scaled_ps)), scaled_ps, 'proton ps scaled correlator (divide by Z0_s to get Z0_p)', xlim = xlim, ylim = ylim) plt.show() return p_avg, T
def read_proton(pr): # read data p_up = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['proton_spin_up']) p_dn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['proton_spin_dn']) pnp_up = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['proton_np_spin_up']) pnp_dn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['proton_np_spin_dn']) p_savg = c51.ispin_avg(p_up, p_dn) pnp_savg = c51.ispin_avg(pnp_up, pnp_dn) p_avg = c51.parity_avg(p_savg, pnp_savg, phase=-1.0) T = len(p_avg[0]) p_avg = p_avg[:, :T/2] # keep only first half of data ('folded' length) if pr.plot_data_flag == 'on': # folded correlator data p_ss = p_avg[:,:,0,0] p_ps = p_avg[:,:,3,0] c51.scatter_plot(np.arange(len(p_ss[0])), c51.make_gvars(p_ss), 'proton ss folded') c51.scatter_plot(np.arange(len(p_ps[0])), c51.make_gvars(p_ps), 'proton ps folded') # effective mass eff = c51.effective_plots(T) meff_ss = eff.effective_mass(c51.make_gvars(p_ss)[1:], 1, 'cosh') meff_ps = eff.effective_mass(c51.make_gvars(p_ps)[1:], 1, 'cosh') xlim = [1, len(meff_ss)] #*2/5] ylim = [0.6, 1.2] #ylim = c51.find_yrange(meff_ss, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_ss))+1, meff_ss, 'proton ss effective mass', xlim = xlim, ylim = ylim) #ylim = c51.find_yrange(meff_ps, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_ps))+1, meff_ps, 'proton ps effective mass', xlim = xlim, ylim = ylim) # scaled correlator E0 = pr.priors['proton']['E0'][0] scaled_ss = eff.scaled_correlator(c51.make_gvars(p_ss), E0, phase=1.0) scaled_ps = eff.scaled_correlator(c51.make_gvars(p_ps), E0, phase=1.0) ylim = c51.find_yrange(scaled_ss, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(scaled_ss)), scaled_ss, 'proton ss scaled correlator (take sqrt to get Z0_s)', xlim = xlim, ylim = ylim) ylim = c51.find_yrange(scaled_ps, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(scaled_ps)), scaled_ps, 'proton ps scaled correlator (divide by Z0_s to get Z0_p)', xlim = xlim, ylim = ylim) return p_avg, T
import h5py as h5 import numpy as np import c51lib as c51 import matplotlib.pyplot as plt #Read meson data filename = 'l2464f211b600m0102m0509m635a_avg.h5' datapath = 'l2464f211b600m0102m0509m635/wf1p0_m51p2_l58_a51p5_smrw5p0_n75/spectrum/ml0p0126_ms0p0693/pion/corr' data_ss = c51.read_data(filename, datapath, 0, 0) data_ps = c51.read_data(filename, datapath, 1, 0) data = np.concatenate((data_ss, data_ps), axis=1) data = c51.make_gvars(data) #data = data_ps #Plot effective mass T = len(data) * 0.5 meff = c51.effective_mass(data, 1) x = np.arange(len(meff)) ylim = c51.find_yrange(meff, 1, 10) #ylim = [0.47, 0.57] xr = [1, 15] c51.scatter_plot(x, meff, 'effective mass', xlim=[xr[0], xr[1]], ylim=ylim) #ylim = c51.find_yrange(meff, 65, 79) c51.scatter_plot(x, meff, 'effective mass ps', xlim=[T + xr[0], T + xr[1]], ylim=ylim) #Fit
def decay_axial(pr, meson, draws): if meson == 'pion': shortname = 'll' elif meson == 'kaon': shortname = 'ls' # read data twopt_dat = c51.open_data(pr.data_loc['file_loc'], pr.data_loc['spec_' + meson]) twopt_ss = np.squeeze(twopt_dat[:, :, 0, :]) twopt_ps = np.squeeze(twopt_dat[:, :, 1, :]) axial_dat = np.squeeze( c51.open_data(pr.data_loc['file_loc'], pr.data_loc['axial_' + shortname])) T = len(twopt_ss[0]) if pr.plot_data_flag == 'on': # unfolded correlator data c51.scatter_plot(np.arange(len(twopt_ss[0])), c51.make_gvars(twopt_ss), 'two point no fold') c51.scatter_plot(np.arange(len(axial_dat[0])), c51.make_gvars(axial_dat), 'axial_' + shortname + ' no fold') # fold data axial_dat = c51.fold(axial_dat, phase=-1.0) twopt_ss = c51.fold(twopt_ss, phase=1.0) twopt_ps = c51.fold(twopt_ps, phase=1.0) if pr.plot_data_flag == 'on': # folded correlator data c51.scatter_plot(np.arange(len(twopt_ss[0])), c51.make_gvars(twopt_ss), 'two point folded') c51.scatter_plot(np.arange(len(axial_dat[0])), c51.make_gvars(axial_dat), 'axial_' + shortname + ' folded') # effective mass eff = c51.effective_plots(T) meff = eff.effective_mass(c51.make_gvars(twopt_ss), 1, 'cosh') meff_axial = eff.effective_mass( c51.make_gvars(axial_dat)[1:], 1, 'cosh') xlim = [3, len(meff)] ylim = c51.find_yrange(meff, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff)), meff, 'two pt effective mass', xlim=xlim, ylim=ylim) ylim = c51.find_yrange(meff, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_axial)) + 1, meff_axial, 'axial_' + shortname + ' effective mass', xlim=xlim, ylim=ylim) # scaled correlator E0 = pr.priors[meson]['E0'][0] scaled = eff.scaled_correlator(c51.make_gvars(twopt_ss), E0, phase=1.0) scaled_axial = eff.scaled_correlator(c51.make_gvars(axial_dat)[1:], E0, phase=-1.0) c51.scatter_plot(np.arange(len(scaled)), scaled, 'two pt scaled correlator (take sqrt to get Z0)') c51.scatter_plot( np.arange(len(scaled_axial)) + 1, scaled_axial, 'axial_' + shortname + ' scaled correlator (divide by Z0 to get F0)') # concatenate decay_axial_ss = np.concatenate((axial_dat, twopt_ss), axis=1) # read priors priors = pr.priors[meson] # read trange trange = pr.trange['decay_axial'] # fit args = ((g, trange, T, decay_axial_ss, priors, draws) for g in range(len(draws))) pool = multi.Pool() p = pool.map_async(decay_axial_fit, args) # sort via bootstrap number output = np.sort(np.array(p.get()), axis=0) return output
def read_baryon(pr): # read data baryon = pr.baryon2pt if baryon in ['proton', 'sigma', 'xi', 'lambda']: corr_up = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_spin_up']) corr_dn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_spin_dn']) corrnp_up = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_np_spin_up']) corrnp_dn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_np_spin_dn']) # spin avg corr = 0.5 * (corr_up + corr_dn) corrnp = 0.5 * (corrnp_up + corrnp_dn) elif baryon in ['delta', 'sigma_st', 'xi_st', 'omega']: corr_upup = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_spin_upup']) corr_up = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_spin_up']) corr_dn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_spin_dn']) corr_dndn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_spin_dndn']) corrnp_upup = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_np_spin_upup']) corrnp_up = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_np_spin_up']) corrnp_dn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_np_spin_dn']) corrnp_dndn = c51.open_data(pr.data_loc['file_loc'], pr.data_loc[baryon + '_np_spin_dndn']) # spin avg corr = 0.25 * (corr_upup + corr_up + corr_dn + corr_dndn) corrnp = 0.25 * (corrnp_upup + corrnp_up + corrnp_dn + corrnp_dndn) # parity avg corr_avg = c51.parity_avg(corr, corrnp, phase=-1.0) T = len(corr_avg[0]) corr_avg = corr_avg[:, :T / 2] # keep only first half of data ('folded' length) if pr.plot_data_flag == 'on': for src in range(len(corr_avg[0, 0, 0])): for snk in range(len(corr_avg[0, 0])): # folded correlator data corr_i = corr_avg[:, :, snk, src] #c51.scatter_plot(np.arange(len(corr_i[0])), c51.make_gvars(corr_i), '%s snk_%s src_%s folded' %(baryon,str(snk),str(src))) # effective mass eff = c51.effective_plots(T) meff = eff.effective_mass( c51.make_gvars(corr_i)[1:], 1, 'cosh') xlim = [1, len(meff)] ylim = c51.find_yrange(meff, xlim[0], xlim[1] * 2 / 5) c51.scatter_plot(np.arange(len(meff)) + 1, meff, '%s snk_%s src_%s effective mass' % (baryon, str(snk), str(src)), xlim=xlim, ylim=ylim) # scaled correlator E0 = pr.priors[baryon]['E0'][0] scaled = eff.scaled_correlator(c51.make_gvars(corr_i), E0, phase=1.0) ylim = c51.find_yrange(scaled, xlim[0], xlim[1] * 2 / 5) c51.scatter_plot( np.arange(len(scaled)), scaled, '%s snk_%s src_%s scaled correlator (take sqrt to get Z0_s)' % (baryon, str(snk), str(src)), xlim=xlim, ylim=ylim) plt.show() return corr_avg, T
data_dn = c51.read_data(filename, datapath, 3, 0) data_neg = c51.ispin_avg(data_up, data_dn) #Parity average data_ps = c51.parity_avg(data_pos, data_neg, -1) ##READ SPIN AND PARITY AVG'D DATA #filename = 'l2464f211b600m0102m0509m635_tune_avg.h5' #datapath = 'prot_w6p1_n94' #datapath = 'prot_w5p6_n94' filename = 'l2464f211b600m0102m0509m635a_avg.h5' datapath = 'l2464f211b600m0102m0509m635/wf1p0_m51p2_l58_a51p5_smrw5p0_n75/spectrum/ml0p0126_ms0p0693/pion/corr' data_ss = c51.read_data(filename, datapath, 0, 0) data_ps = c51.read_data(filename, datapath, 3, 0) data = np.concatenate((data_ss, data_ps), axis=1) data = c51.make_gvars(data) #data = data_ps #Plot effective mass T = len(data)*0.5 meff = c51.effective_mass(data, 1) x = np.arange(len(meff)) ylim = c51.find_yrange(meff, 1, 10) #ylim = [0.47, 0.57] xr = [1,15] c51.scatter_plot(x, meff, 'effective mass', xlim=[xr[0],xr[1]], ylim=ylim) #ylim = c51.find_yrange(meff, 65, 79) c51.scatter_plot(x, meff, 'effective mass ps', xlim=[T+xr[0],T+xr[1]], ylim=ylim) #Fit inputs = c51.read_yaml('temp.yml')
def decay_bs(params, meson, draws): print 'decay ', meson ens = params.ens ml = params.ml ms = params.ms loc = params.data_loc # read data decay_dat = c51.fold(c51.open_data(loc['file_loc'], loc['spec_' + meson])) decay_ss = np.squeeze(decay_dat[:, :, 0, :]) decay_ps = np.squeeze(decay_dat[:, :, 1, :]) T = 2 * len(decay_ss[0]) if params.plot_data_flag == 'on': # unfolded correlator data c51.scatter_plot(np.arange(len(decay_ss[0])), c51.make_gvars(decay_ss), meson + ' ss folded') c51.scatter_plot(np.arange(len(decay_ps[0])), c51.make_gvars(decay_ps), meson + ' ps folded') # effective mass eff = c51.effective_plots(T) meff_ss = eff.effective_mass(c51.make_gvars(decay_ss), 1, 'cosh') meff_ps = eff.effective_mass(c51.make_gvars(decay_ps), 1, 'cosh') xlim = [3, len(meff_ss) - 2] ylim = c51.find_yrange(meff_ss, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_ss)), meff_ss, meson + ' ss effective mass', xlim=xlim, ylim=ylim) ylim = c51.find_yrange(meff_ps, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(meff_ps)), meff_ps, meson + ' ps effective mass', xlim=xlim, ylim=ylim) # scaled correlator E0 = params.priors[meson]['E0'][0] scaled_ss = eff.scaled_correlator(c51.make_gvars(decay_ss), E0, phase=1.0) scaled_ps = eff.scaled_correlator(c51.make_gvars(decay_ps), E0, phase=1.0) ylim = c51.find_yrange(scaled_ss, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(scaled_ss)), scaled_ss, meson + ' ss scaled correlator (take sqrt to get Z0_s)', xlim=xlim, ylim=ylim) ylim = c51.find_yrange(scaled_ps, xlim[0], xlim[1]) c51.scatter_plot(np.arange(len(scaled_ps)), scaled_ps, meson + ' ps scaled correlator (divide by Z0_s to get Z0_p)', xlim=xlim, ylim=ylim) plt.show() # concatenate data decay_ss_ps = np.concatenate((decay_ss, decay_ps), axis=1) # priors priors = params.priors[meson] # read trange trange = params.trange['twopt'] #Fit #args = ((g, trange, T, decay_ss_ps, priors, draws) for g in range(len(draws))) #pool = multi.Pool() #p = pool.map_async(decay_fit, args) ## sort via bootstrap number #output = np.sort(np.array(p.get()), axis=0) result = [] for g in range(len(draws)): # resample decay data decay_bs = decay_ss_ps[draws[g]] decay_bs = c51.make_gvars(decay_bs) # priors bsp = c51.dict_of_tuple_to_gvar(priors) #Fit fitfcn = c51.fit_function(T, nstates=2) fit = c51.fitscript_v2(trange, T, decay_bs, bsp, fitfcn.twopt_fitfcn_ss_ps, result_flag='off') fit = [g, fit] result.append(fit) output = np.sort(np.array(result), axis=0) return output