def line_figure(self, wdir, Q2, dpi): ## this block may contain something not useful load_config('%s/input.py' % wdir) istep = core.get_istep() # jar = load('%s/data/jar-%d.dat' % (wdir, istep)) labels = load('%s/data/labels-%d.dat' % (wdir, istep)) self.cluster = labels['cluster'] self.cluster_average_chi2 = labels['cluster_average_chi2'] self.best_cluster = np.argmin(self.cluster_average_chi2) nrows, ncols = 1, 1 fig = py.figure(figsize=(ncols * 5.0, nrows * 3.0)) ax = py.subplot(nrows, ncols, 1) ## polarized PDF if Q2 == None: Q2 = conf['Q20'] if Q2 == conf['Q20']: self.xf_data = load('%s/data/ppdf-%d.dat' % (wdir, istep)) else: self.xf_data = load('%s/data/ppdf-%d-%f.dat' % (wdir, istep, Q2)) print '\nplotting polarized PDF line figure from %s at Q2 = %.2f' % ( wdir, Q2) self.plot_lines(ax, 'g', 'r', all_cluster=2) ax.set_ylim(-0.11, 0.3) ax.set_yticks([-0.1, 0.0, 0.1, 0.2]) ax.set_yticklabels([r'$-0.1$', r'$0.0$', r'$0.1$', r'$0.2$']) # ax.text(0.7, 0.8, r'\boldmath$x\Delta g$', color = 'k', transform = axs[3].transAxes, size = 28) ax.title.set_text( r'\boldmath$x\Delta g~\mathrm{at}~Q^2 = %.2f~\mathrm{GeV}^2$' % Q2) legends = ax.legend(frameon=0, loc='best') for line in legends.get_lines(): line.set_linewidth(1.0) ax.semilogx() ax.set_xlim(8e-3, 9e-1) ax.set_xticks([1e-2, 1e-1]) ax.tick_params(axis='both', which='both', right=True, top=True, direction='in', labelsize=20) ax.set_xticklabels([r'', r'']) ax.axhline(0.0, color='k', linestyle='dashdot', linewidth=0.5) ax.set_xticks([0.01, 0.1, 0.5, 0.8]) ax.set_xticklabels([r'$0.01$', r'$0.1$', r'$0.5$', r'$0.8$']) # py.subplots_adjust(left = 0.12, bottom = 0.08, right = 0.99, top = 0.97, wspace = None, hspace = 0.2) py.tight_layout() if Q2 == conf['Q20']: py.savefig('%s/gallery/ppdf-lines-pjet-%d.png' % (wdir, istep), dpi=dpi) else: py.savefig('%s/gallery/ppdf-lines-pjet-%d-%f.png' % (wdir, istep, Q2), dpi=dpi)
def histogram_figure(self, wdir, Q2, dpi): ## plot histogram for parameters of all flavors load_config('%s/input.py' % wdir) istep = core.get_istep() # jar = load('%s/data/jar-%d.dat' % (wdir, istep)) labels = load('%s/data/labels-%d.dat' % (wdir, istep)) self.cluster = labels['cluster'] self.best_cluster = np.argmin(labels['cluster_average_chi2']) if Q2 == None: Q2 = conf['Q20'] if Q2 == conf['Q20']: self.ppdf_parameter_data = load('%s/data/ppdf-parameters-%d.dat' % (wdir, istep)) else: self.ppdf_parameter_data = load('%s/data/ppdf-parameters-%d-%f.dat' % (wdir, istep, Q2)) shapes = self.ppdf_parameter_data.keys() flavors = self.ppdf_parameter_data[shapes[0]].keys() for _ in sorted(self.ppdf_parameter_data[shapes[0]][flavors[0]]): print '\nplotting PPDF parameter %s histograms from %s' % (_, wdir) if len(flavors) == 8: n_rows, n_columns = 4, 2 figure = py.figure(figsize = (n_columns * 5.0, n_rows * 3.0)) axs = [py.subplot(n_rows, n_columns, count + 1) for count in range(8)] sys.exit('please make a subplot configuration for your flavors') elif len(flavors) == 7: n_rows, n_columns = 4, 2 figure = py.figure(figsize = (n_columns * 5.0, n_rows * 3.0)) axs = [py.subplot(n_rows, n_columns, count + 1) for count in range(8) if count != 7] else: sys.exit('please make a subplot configuration for your flavors') if sorted(flavors) == sorted(['g', 'up', 'ub', 'dp', 'db', 'sp', 'sb']): self.ppdf_histogram(axs[0], 'up', _, r'\boldmath$u_+$') self.ppdf_histogram(axs[1], 'ub', _, r'\boldmath$\overline{u}$') self.ppdf_histogram(axs[2], 'dp', _, r'\boldmath$d_+$') self.ppdf_histogram(axs[3], 'db', _, r'\boldmath$\overline{d}$') self.ppdf_histogram(axs[4], 'sp', _, r'\boldmath$s_+$') self.ppdf_histogram(axs[5], 'sb', _, r'\boldmath$\overline{s}$') self.ppdf_histogram(axs[6], 'g', _, r'\boldmath$g$') for ax in axs: # ax.semilogx() # ax.tick_params(axis = 'both', which = 'both', right = True, top = True, direction = 'in', labelsize = 20) # ax.set_xticklabels([r'', r'']) ax.legend(frameon = 0, loc = 'best', fontsize = 17) axs[0].title.set_text(r'$\mathrm{parameter}~%s~\mathrm{at}~Q^2 = %.2f~\mathrm{GeV^2}$' % (_, Q2)) axs[1].title.set_text(r'$\mathrm{parameter}~%s~\mathrm{at}~Q^2 = %.2f~\mathrm{GeV^2}$' % (_, Q2)) py.tight_layout() if Q2 == conf['Q20']: py.savefig('%s/gallery/ppdf-histogram-pjet-%s-%d.png' % (wdir, _, istep), dpi = dpi) else: py.savefig('%s/gallery/ppdf-histogram-pjet-%s-%d-%f.png' % (wdir, _, istep, Q2), dpi = dpi)
def make_figure(wdir, task, plot_with_factor=True, only_best_cluster=True, dpi=200): ## attribute 'plot_with_factor' is inherited from jet and not yet used ## it is kept there because someday it might be useful if task == 1: print('\nplotting PJET data from %s' % (wdir)) elif task == 2: print('\nplotting PJET data over theory from %s' % (wdir)) load_config('%s/input.py' % wdir) istep = core.get_istep() replicas = core.get_replicas(wdir) core.mod_conf(istep, replicas[0]) #--set conf as specified in istep predictions = load('%s/data/predictions-%d.dat' % (wdir, istep)) if 'pjet' not in predictions['reactions']: print('PJET is not in data file') return labels = load('%s/data/labels-%d.dat' % (wdir, istep)) cluster = labels['cluster'] cluster_average_chi2 = labels['cluster_average_chi2'] best_cluster = np.argmin(cluster_average_chi2) data = predictions['reactions']['pjet'] for idx in data: predictions = copy.copy(data[idx]['prediction-rep']) del data[idx]['prediction-rep'] del data[idx]['residuals-rep'] if only_best_cluster: best_predictions = [ predictions[i] for i in range(len(predictions)) if cluster[i] == best_cluster ] data[idx]['thy'] = np.mean(best_predictions, axis=0) data[idx]['dthy'] = np.std(best_predictions, axis=0)**0.5 else: all_predictions = [predictions[i] for i in range(len(predictions))] data[idx]['thy'] = np.mean(all_predictions, axis=0) data[idx]['dthy'] = np.std(all_predictions, axis=0)**0.5 if task == 1: plot_data(wdir, data, istep, dpi, plot_with_factor) # for idx in data: # plot_data_separate(wdir, data[idx], istep, idx, dpi, plot_with_factor) elif task == 2: ## this is copied from jet plot and not yet ready plot_data_on_theory(wdir, data, istep, dpi) return
def plot_chi2_dist_per_exp(wdir, istep): #--needs revisions NS (09/02/19) labels = load('%s/data/labels-%d.dat' % (wdir, istep)) cluster, colors, nc, order = get_clusters(wdir, istep) chi2 = labels['chi2dof'] data = load('%s/data/predictions-%d.dat' % (wdir, istep)) for reaction in data['reactions']: for idx in data['reactions'][reaction]: if reaction != 'sidis': continue if idx != 2006: continue res = np.array(data['reactions'][reaction][idx]['residuals-rep']) chi2 = np.array([np.sum(r**2) / len(r) for r in res]) #chi2=np.array([_ for _ in chi2 if _<5]) Mean = np.average(chi2) dchi = np.std(chi2) chi2min = Mean - 2 * dchi chi2max = Mean + 2 * dchi R = (chi2min, chi2max) nrows = 1 ncols = 1 #--plot labeled residuals ax = py.subplot(nrows, ncols, 1) ax.hist(chi2, bins=30, range=R, histtype='step', label='size=%d' % len(chi2)) for j in range(nc): _chi2 = [chi2[i] for i in range(len(chi2)) if cluster[i] == j] c = colors[j] print c, np.mean(_chi2), reaction, idx label = 'cluster id=%d size=%d' % (j, len(_chi2)) ax.hist(_chi2, bins=30, range=R, histtype='step', label=label, color=c) ax.set_xlabel('chi2/npts') ax.set_ylabel('yiled') ax.legend() ax.text(0.1, 0.8, 'step %d' % istep, transform=ax.transAxes) py.tight_layout() checkdir('%s/gallery' % wdir) py.savefig('%s/gallery/chi2-dist-%d-%s-%d.jpg' % (wdir, istep, reaction, idx)) py.close()
def plot_obs(wdir, only_best_cluster=True, dpi=200): print('\nplotting dy data from %s' % (wdir)) load_config('%s/input.py' % wdir) istep = core.get_istep() replicas = core.get_replicas(wdir) core.mod_conf(istep, replicas[0]) #--set conf as specified in istep predictions = load('%s/data/predictions-%d.dat' % (wdir, istep)) if 'dy' not in predictions['reactions']: print('DY is not in data file') return labels = load('%s/data/labels-%d.dat' % (wdir, istep)) cluster = labels['cluster'] cluster_average_chi2 = labels['cluster_average_chi2'] best_cluster = np.argmin(cluster_average_chi2) data = predictions['reactions']['dy'] for idx in data: predictions = copy.copy(data[idx]['prediction-rep']) del data[idx]['prediction-rep'] del data[idx]['residuals-rep'] if only_best_cluster: best_predictions = [ predictions[i] for i in range(len(predictions)) if cluster[i] == best_cluster ] data[idx]['thy'] = np.mean(best_predictions, axis=0) data[idx]['dthy'] = np.std(best_predictions, axis=0)**0.5 else: all_predictions = [predictions[i] for i in range(len(predictions))] data[idx]['thy'] = np.mean(all_predictions, axis=0) data[idx]['dthy'] = np.std(all_predictions, axis=0)**0.5 Q2_bins = [] # Q2_bins.append([30, 40]) Q2_bins.append([35, 45]) ## label pp: 37 < Q2 < 42 pd: idem Q2_bins.append([45, 52]) ## label pp: 47 < Q2 < 49 pd: idem Q2_bins.append([52, 60]) ## label pp: 54 < Q2 < 58 pd: 55 < Q2 < 57 Q2_bins.append([60, 68]) ## label pp: 63 < Q2 < 66 pd: 62 < Q2 < 65 Q2_bins.append([68, 75]) ## label pp: 70 < Q2 < 73 pd: 70 < Q2 < 72 Q2_bins.append([100, 140]) ## label pp: 118 < Q2 < 131 pd: 124 < Q2 < 129 Q2_bins.append([140, 160]) ## label pp: 148 < Q2 < 156 pd: 145 < Q2 < 154 Q2_bins.append([160, 280]) ## label pp: 173 < Q2 < 222 pd: 73 < Q2 < 280 plot_ratio(wdir, data, istep, Q2_bins, dpi) return
def get_replicas(wdir): """ load the msr files """ replicas=sorted(os.listdir('%s/msr-inspected'%wdir)) replicas=[load('%s/msr-inspected/%s'%(wdir,_)) for _ in replicas] return replicas
def update_idis_tabs(wdir, tabs, tar): load_config('%s/input.py' % wdir) istep = core.get_istep() data = load('%s/data/predictions-%d-sim.dat' % (wdir, istep)) blist = [] blist.append('thy') blist.append('shift') blist.append('residuals') blist.append('prediction') blist.append('N') blist.append('Shift') blist.append('W2') blist.append('alpha') blist.append('residuals-rep') blist.append('r-residuals') for _ in data['reactions']: for idx in data['reactions'][_]: print('update %s %d%s...' % (_, idx, tar)) tab = data['reactions'][_][idx] for k in blist: try: del tab[k] except: continue tab['value'] = np.mean(tab['prediction-rep'], axis=0) for i in range(len(tab['prediction-rep'])): tab['value%s' % (i + 1)] = tab['prediction-rep'][i] del tab['prediction-rep'] df = pd.DataFrame(tab) df.to_excel('%s/sim/%s%s.xlsx' % (wdir, idx, tar), index=False)
def get_chi2(wdir, kc): istep = core.get_istep() #replicas=core.get_replicas(wdir) #core.mod_conf(istep,replicas[0]) #--set conf as specified in istep predictions = load('%s/data/predictions-%d.dat' % (wdir, istep)) data = predictions['reactions'] tab = {} for reaction in data: for idx in data[reaction]: if reaction not in tab: tab[reaction] = {} if idx not in tab[reaction]: tab[reaction][idx] = {} value = data[reaction][idx]['value'] alpha = data[reaction][idx]['alpha'] thy = np.mean(data[reaction][idx]['prediction-rep'], axis=0) col = data[reaction][idx]['col'][0] res = (value - thy) / alpha chi2 = np.sum(res**2) npts = res.size chi2_npts = chi2 / npts tab[reaction][idx]['col'] = col tab[reaction][idx]['chi2'] = chi2 tab[reaction][idx]['npts'] = npts tab[reaction][idx]['chi2_npts'] = chi2_npts return tab
def run(self, nruns=1): if 'nruns' in conf: nruns = conf['nruns'] # set outputdir if 'args' in conf: outputdir = '%s/mcdata' % conf['args'].config.split( '/')[-1].replace('.py', '') else: outputdir = 'mcdata' checkdir(outputdir) # get exisiting runs idx = [int(x.replace('.dat', '')) for x in os.listdir(outputdir)] if len(idx) == 0: fname = ['%s/%i.dat' % (outputdir, i) for i in range(nruns)] nestout = [None for i in range(nruns)] else: fname = ['%s/%s' % (outputdir, _) for _ in os.listdir(outputdir)] nestout = [ load('%s/%s' % (outputdir, _)) for _ in os.listdir(outputdir) ] for i in range(nruns): print 'run ', i self.single_run(fname[i], nestout[i])
def get_MC_samples(self, mcpath): F = os.listdir(mcpath) data = [] for f in F: data.append(load('%s/%s' % (mcpath, f))) samples = [] likelihoods = [] n = 0 for d in data: for p in d['samples']: samples.append(p) likelihoods.extend(d['l']) n += len(d['active nll']) samples = np.array(samples) likelihoods = np.array(likelihoods) I = np.argsort(likelihoods)[::-1] x = np.array([((n - 1.) / n)**i for i in range(len(likelihoods) + 1)]) dx = (0.5 * (x[:-1] - x[1:]))[::-1] x = x[::-1] likelihoods = likelihoods[I] samples = samples[I] weights = np.array([likelihoods[i] * dx[i] for i in range(dx.size)]) weights /= np.sum(weights) weights2 = np.array( [weights[i] for i in range(weights.size) if weights[i] > 1e-4]) samples2 = np.array( [samples[i] for i in range(len(weights)) if weights[i] > 1e-4]) weights2 /= np.sum(weights2) print 'runs max likelihoods' for d in data: print d['active nll'][0] print 'sample size=', weights.size print 'sample2 size=', weights2.size out = {} out['samples'] = samples out['weights'] = weights out['samples2'] = samples2 out['weights2'] = weights2 out['order'] = conf['parman'].order out['runs'] = {} cnt = 0 for d in data: out['runs'][cnt] = { 'samples': d['samples'], 'weights': d['weights'] } cnt += 1 return out
def plot_obs(wdir, kc): print('\nplotting ln data from %s' % (wdir)) load_config('%s/input.py' % wdir) istep = core.get_istep() replicas = core.get_replicas(wdir) core.mod_conf(istep, replicas[0]) #--set conf as specified in istep predictions = load('%s/data/predictions-%d.dat' % (wdir, istep)) data = predictions['reactions']['ln'] plot_H1(wdir, istep, data[1000]) plot_ZEUS(wdir, istep, data[2000])
def _gen_labels_by_chi2(wdir, istep): print('\t by chi2 ...') #--load data where residuals are computed data = load('%s/data/predictions-%d.dat' % (wdir, istep)) res = np.array(data['res']) #--compute chi2/npts chi2dof = [] for row in res: chi2dof.append(np.sum(row**2) / len(row)) chi2dof = np.array(chi2dof) return chi2dof
def gen_exp_dict(self, wdir, istep): #--needs revision NS (09/02/19) data = load('%s/data/predictions-%d.dat' % (wdir, istep)) summary = [] for reaction in data['reactions']: for idx in data['reactions'][reaction]: tab = data['reactions'][reaction][idx] col = tab['col'][0] value = tab['value'] npts = len(value) msg = 'reaction: %8s,' msg += ' idx: %7d,' msg += ' col: %10s,' msg += ' npts: %5d,' msg = msg % (reaction, idx, col[:10], npts) if reaction == 'dy': msg += ' rea: %s,' % tab['reaction'][0] if reaction == 'sia': msg += ' had: %s,' % tab['hadron'][0] if reaction == 'idis': msg += ' tar: %s,' % tab['target'][0] msg += ' obs: %s,' % tab['obs'][0] if reaction == 'sidis': msg += ' tar: %1s,' % tab['target'][0][0] msg += ' had: %5s,' % tab['hadron'][0] msg += ' obs: %s,' % tab['obs'][0] if reaction == 'pidis': msg += ' tar: %s,' % tab['target'][0] msg += ' obs: %s,' % tab['obs'][0] if reaction == 'psidis': msg += ' tar: %1s,' % tab['target'][0][0] msg += ' had: %5s,' % tab['hadron'][0] msg += ' obs: %s,' % tab['obs'][0] if reaction == 'jet': msg += ' rea: %s' % tab['reaction'][0] msg += ' col: %s' % tab['col'][0] if reaction == 'pjet': msg += ' rea: %s' % tab['reaction'][0] msg += ' col: %s' % tab['col'][0] summary.append(msg) summary = [_ + '\n' for _ in summary] F = open('%s/data/exp-dict-%d.txt' % (wdir, istep), 'w') F.writelines(summary) F.close()
def update_tabs(wdir, tar, est, lum): istep = core.get_istep() data = load('%s/data/predictions-%d-all-%s-%s.dat' % (wdir, istep, tar, est)) blist = [] blist.append('thy') blist.append('shift') blist.append('residuals') blist.append('prediction') blist.append('N') blist.append('Shift') blist.append('W2') blist.append('alpha') blist.append('residuals-rep') blist.append('r-residuals') blist.append('L') blist.append('H') #--placeholder index idx = 80000 tab = data['reactions']['pidis'][idx] #--delete unnecessary data for k in blist: try: del tab[k] except: continue #--save mean value tab['value'] = np.mean(tab['prediction-rep'], axis=0) #--save individual values for i in range(len(tab['prediction-rep'])): tab['value%s' % (i + 1)] = tab['prediction-rep'][i] del tab['prediction-rep'] tab['stat_u'], tab['pole_u'], tab['polh_u'], tab['lum_u'], tab[ 'syst_u'] = all_errors(wdir, tar, est, tab['value'], lum) df = pd.DataFrame(tab) filename = '%s/sim/all-%s-%s.xlsx' % (wdir, tar, est) df.to_excel(filename, index=False) print('Updating xlsx file and saving to %s' % filename)
def plot_obs(wdir, kc): print('\nplotting dy-pion data from %s' % (wdir)) load_config('%s/input.py' % wdir) istep = core.get_istep() replicas = core.get_replicas(wdir) core.mod_conf(istep, replicas[0]) #--set conf as specified in istep predictions = load('%s/data/predictions-%d.dat' % (wdir, istep)) if 'dy-pion' not in predictions['reactions']: return data = predictions['reactions']['dy-pion'] plot_E615(wdir, istep, data[10001]) plot_NA10(wdir, istep, data[10002], data[10003]) return
def plot_obs(wdir, kc): print('\nplotting DY-pion (qT) from %s' % (wdir)) load_config('%s/input.py' % wdir) istep = core.get_istep() replicas = core.get_replicas(wdir) core.mod_conf(istep, replicas[0]) #--set conf as specified in istep predictions = load('%s/data/predictions-%d.dat' % (wdir, istep)) #print(predictions['reactions'].keys()) if 'pion_qT' not in predictions['reactions']: return data = predictions['reactions']['pion_qT'] plot_E615_Q(wdir, istep, data[1001]) plot_E615_xF(wdir, istep, data[1002]) return
def get_msr_inspected(wdir): print('\nget msr inspected (filtered msr files) using %s\n'%wdir) replicas=sorted(os.listdir('%s/msr'%wdir)) X=[] for i in range(len(replicas)): lprint('progress: %d/%d'%(i+1,len(replicas))) replica=load('%s/msr/%s'%(wdir,replicas[i])) istep=sorted(replica['params'].keys())[-1] #--pick last step params=replica['params'][istep] #print params #if params[2]<0.1: continue if params is None: continue data=replica['chi2']#[istep] chi2,npts=0,0 for reaction in data: #print for idx in data[reaction]: chi2+=data[reaction][idx]['chi2'] npts+=data[reaction][idx]['npts'] if chi2/npts-1<1000: X.append(chi2/npts-1) checkdir('%s/msr-inspected'%wdir) cmd=['cp'] cmd.append('%s/msr/%s'%(wdir,replicas[i])) cmd.append('%s/msr-inspected/%s'%(wdir,replicas[i])) p = subprocess.Popen(cmd, stdout=subprocess.PIPE) print() print('original num. samples :%d'%len(replicas)) print('inspected num. samples :%d'%len(X)) nrows=1 ncols=1 #--plot labeled residuals ax=py.subplot(nrows,ncols,1) ax.hist(X,bins=10) #py.tight_layout() checkdir('%s/gallery'%wdir) py.savefig('%s/gallery/chi2-dist-inspect.pdf'%(wdir)) py.close()
def gen_dist_from_fitpack(wdir,dist): print('\ngenerating %s tables for benchmark using %s'%(dist,wdir)) load_config('%s/input.py'%wdir) istep=core.get_istep() core.mod_conf(istep) #--set conf as specified in istep resman=RESMAN(nworkers=1,parallel=False,datasets=False) parman=resman.parman jar=load('%s/data/jar-%d.dat'%(wdir,istep)) replicas=jar['replicas'] X,Q2=gen_grid(dist) qpd=conf[dist] nx=len(X) nQ2=len(Q2) flavs=[-5,-4,-3,-2,-1,1,2,3,4,5,21] fmap={-5:'bb',-4:'cb',-3:'sb',-2:'ub',-1:'db'} fmap.update({5:'b',4:'c',3:'s',2:'u',1:'d'}) fmap.update({21:'g'}) #--gen qpd data per replica checkdir('%s/benchmark'%wdir) cnt=0 for par in replicas: lprint('progress: %d/%d'%(cnt+1,len(replicas))) parman.set_new_params(par) data={} for _ in Q2: data[_]={} for flav in flavs: data[_][flav]=np.array([qpd.get_xF(x,_,fmap[flav]) for x in X]) save(data,'%s/benchmark/%s-%d.dat'%(wdir,dist,cnt)) cnt+=1 print
def print_individual_parameters(working_directory, distribution, norm, index=0): load_config('%s/input.py' % working_directory) istep = core.get_istep() jar = load('%s/data/jar-%d.dat' % (working_directory, istep)) if norm: for i in range(len(jar['order'])): if jar['order'][i][0] == 2: print jar['order'][i][1].ljust(8), '%s' % str( jar['order'][i][2]).ljust( 10), ':', jar['replicas'][index][i] else: for i in range(len(jar['order'])): if (jar['order'][i][0] == 1) and (jar['order'][i][1] == distribution): print jar['order'][i][2].ljust( 13), ':', jar['replicas'][index][i]
def gen_report(self): inputfile = conf['args'].config nestfile = conf['args'].fname nestout = load(nestfile) weight = nestout['weights'][0] q = nestout['samples'][0] self.get_residuals(q) report = conf['resman'].gen_report(verb=1, level=1) save(report, 'report') L = open(inputfile).readlines() for i in range(len(L)): if L[i].startswith('#'): continue if 'params' in L[i] and '<<' in L[i]: l = L[i].split('=')[0].replace('conf', '').replace("'", '') k, kk = l.replace('][', '@').replace('[', '').replace(']', '').split('@')[1:] left = L[i].split('<<')[0] right = L[i].split('>>')[1] L[i] = left + '<<%30.20e>>' % conf['params'][k.strip()][ kk.strip()]['value'] + right if 'norm' in L[i] and '<<' in L[i]: l = L[i].split('=')[0].replace('conf', '').replace("'", '') dum1, k, dum2, kk = l.replace('][', '@').replace('[', '').replace( ']', '').split('@') left = L[i].split('<<')[0] right = L[i].split('>>')[1] value = conf['datasets'][k.strip()]['norm'][int(kk)]['value'] L[i] = left + '<<%30.20e>>' % value + right F = open(inputfile, 'w') F.writelines(L) F.close()
def plot_chi2_dist(wdir, istep): #--needs revisions NS (09/02/19) labels = load('%s/data/labels-%d.dat' % (wdir, istep)) chi2 = labels['chi2dof'] cluster, colors, nc, order = get_clusters(wdir, istep) nrows = 1 ncols = 1 #--plot labeled residuals ax = py.subplot(nrows, ncols, 1) chi2 = [_ for _ in chi2 if _ < 2] Mean = np.average(chi2) dchi = np.std(chi2) chi2min = Mean - 2 * dchi chi2max = Mean + 2 * dchi R = (chi2min, chi2max) ax.hist(chi2, bins=60, range=R, histtype='step', label='size=%d' % len(chi2)) for j in range(nc): chi2_ = [chi2[i] for i in range(len(chi2)) if cluster[i] == j] c = colors[j] print c, np.mean(chi2_), np.mean(chi2) label = 'cluster id=%d size=%d' % (j, len(chi2_)) ax.hist(chi2_, bins=30, range=R, histtype='step', label=label, color=c) mean = np.average(chi2_) ax.axvline(mean, color=c, ls=':') ax.set_xlabel('chi2/npts') ax.set_ylabel('yiled') ax.legend() ax.text(0.1, 0.8, 'step %d' % istep, transform=ax.transAxes) py.tight_layout() checkdir('%s/gallery' % wdir) py.savefig('%s/gallery/chi2-dist-%d.jpg' % (wdir, istep)) py.close()
def _gen_labels_by_echi2(wdir, istep): print('\t by echi2 ...') #--load data where residuals are computed data = load('%s/data/predictions-%d.dat' % (wdir, istep)) res = np.array(data['res']) #--compute chi2/npts echi2 = [] for row in res: echi2.append(0) #np.sum(row**2)/len(row)) echi2 = np.array(echi2) nexp = 0 for reaction in data['reactions']: for idx in data['reactions'][reaction]: nexp += 1 res = np.array(data['reactions'][reaction][idx]['residuals-rep']) for i in range(len(res)): echi2[i] += (np.sum(res[i]**2) / len(res[i])) return echi2 / nexp
def get_clusters(wdir, istep, kc): nc = kc.nc[istep] hook = kc.hooks[istep] labels = load('%s/data/labels-%d.dat' % (wdir, istep)) cluster = labels['cluster'] chi2dof = labels['chi2dof'] echi2dof = labels['echi2dof'] #--get clusters idx ordering echi2_means = [ np.mean([echi2dof[i] for i in range(len(echi2dof)) if cluster[i] == j]) for j in range(nc) ] order = np.argsort(echi2_means) clist = ['r', 'c', 'g', 'y'] colors = {order[i]: clist[i] for i in range(nc)} return cluster, colors, nc, order
def gen_tables(wdir, dist, file_name, info, info_only=False): print('\ngenerating LHAPDF tables for %s using %s' % (dist, wdir)) load_config('%s/input.py' % wdir) istep = core.get_istep() core.mod_conf(istep) #--set conf as specified in istep resman = RESMAN(nworkers=1, parallel=False, datasets=False) parman = resman.parman jar = load('%s/data/jar-%d.dat' % (wdir, istep)) replicas = jar['replicas'] #--check order consistency order = jar['order'] parman.order = order #--create output dir checkdir(wdir + '/data/') checkdir(wdir + '/data/%s/' % file_name) #--gen lhapdf_data_files if info_only == False: cnt = 0 for par in replicas: lprint('progress: %d/%d' % (cnt + 1, len(replicas))) parman.set_new_params(par) X, Q2, table = _gen_table(dist) gen_lhapdf_dat_file(X, Q2, table, wdir, file_name, cnt) cnt += 1 print #--gen_lhapdf_info_file X, Q2 = gen_grid(dist) nrep = len(replicas) gen_lhapdf_info_file(X, Q2, nrep, wdir, file_name, info)
def run(self): global conf load_config(self.inputfile) #--modify confs if 'hooks' not in conf: conf['hooks'] = {} if self.msrhook != None: conf['hooks']['msr'] = self.msrhook if self.verbose == False: conf['verbose'] = 1 else: conf['verbose'] = self.verbose #--backup conf(after mods) conf_bkp = copy.deepcopy(conf) #--decide if the input should be modified output = True if 'bootstrap' in conf and conf['bootstrap'] == True: output = False if 'steps' in conf: isteps = sorted(conf['steps']) self.order = {} self.params = {} chi2 = {} if self.prior != None: prior = load(self.prior) self.order = prior['order'] self.params = prior['params'] chi2 = prior['chi2'] prior_steps = sorted(self.order.keys()) isteps = [i for i in isteps if i not in prior_steps] for i in isteps: step = conf['steps'][i] conf.update(copy.deepcopy(conf_bkp)) conf.update(self.get_conf(conf_bkp, step)) print msg = '--step %d: ' % i msg += 'npQCD objects =' for _ in conf['params'].keys(): msg += _ + ' ' msg += 'datasets =' for _ in conf['datasets'].keys(): msg += _ + ' ' print msg par = self.get_par(i, step['dep']) self.order[i] = self.parman.order[:] self.params[i] = par[:] chi2[i] = self.resman.get_chi2() if output: self.gen_output(i) #--store the results from steps data = {'order': self.order, 'params': self.params, 'chi2': chi2} if self.prior == None: fname = '%s.msr' % id_generator(size=12) else: fname = self.prior.split('/')[-1] save(data, fname) #--run hooks if 'msr' in conf['hooks']: #--ms==multi steps cmd = conf['hooks']['msr'].replace('<<fname>>', fname) os.system(cmd) else: par = self.get_par(0) if output: self.gen_output(0) #--run remining hooks if available for _ in conf['hooks']: if _ == 'msr': continue os.system(conf['hooks'][_])
def steps_comparison_figure(self, wdirs, Q2, dpi): step_keys = sorted(wdirs.keys()) load_config('%s/input.py' % wdirs[step_keys[-1]]) istep = core.get_istep() nrows, ncols = 1, 1 fig = py.figure(figsize=(ncols * 5.0, nrows * 3.0)) ax = py.subplot(nrows, ncols, 1) colors = ['y', 'r', 'b', 'g', 'm'] ## PPDF self.xf_data = {} self.cluster = {} self.best_cluster = {} labels = {} if Q2 == None: Q2 = conf['Q20'] if Q2 == conf['Q20']: for step_key in step_keys: self.xf_data[step_key] = load('%s/data/ppdf-%d.dat' % (wdirs[step_key], step_key)) labels[step_key] = load('%s/data/labels-%d.dat' % (wdirs[step_key], step_key)) self.cluster[step_key] = labels[step_key]['cluster'] self.best_cluster[step_key] = np.argmin( labels[step_key]['cluster_average_chi2']) else: for step_key in step_keys: self.xf_data[step_key] = load('%s/data/ppdf-%d-%f.dat' % (wdirs[step_key], step_key, Q2)) labels[step_key] = load('%s/data/labels-%d.dat' % (wdirs[step_key], step_key)) self.cluster[step_key] = labels[step_key]['cluster'] self.best_cluster[step_key] = np.argmin( labels[step_key]['cluster_average_chi2']) print '\nplotting PPDF band figure with following steps at Q2 = %.2f' % Q2 print[wdirs[_] for _ in wdirs] for i in range(len(step_keys)): step = step_keys[i] # alpha = (1.0 / len(step_keys)) * (len(step_keys) - i) alpha = 0.5 color = colors[i] label = r'$\mathrm{step~%02d}$' % step self.plot_band_steps(ax, step, 'g', color, alpha, label) ax.set_ylim(-0.11, 0.3) ax.set_yticks([-0.1, 0.0, 0.1, 0.2]) ax.set_yticklabels([r'$-0.1$', r'$0.0$', r'$0.1$', r'$0.2$']) # ax.text(0.1, 0.1, r'\boldmath$x\Delta g$', color = 'k', transform = ax.transAxes, size = 28) ax.legend(frameon=0, loc='lower left', fontsize=7) ax.semilogx() ax.set_xlim(8e-3, 9e-1) ax.set_xticks([1e-2, 1e-1]) ax.tick_params(axis='both', which='both', right=True, top=True, direction='in', labelsize=20) ax.set_xticklabels([r'', r'']) ax.axhline(0.0, color='k', linestyle='dashdot', linewidth=0.5) ax.set_xticks([0.01, 0.1, 0.5]) ax.set_xticklabels([r'$0.01$', r'$0.1$', r'$0.5$']) ax.set_ylabel(r'$x \Delta g$', size=15) ax.set_xlabel(r'\boldmath$x$', size=15) ax.xaxis.set_label_coords(1.05, 0.0) py.tight_layout() # py.subplots_adjust(left=0.05, bottom=0.04, right=0.99, top=0.99, wspace=0.17, hspace=0.04) if Q2 == conf['Q20']: py.savefig('%s/gallery/ppdf-steps-pjet-%d.png' % (wdirs[step_keys[-1]], istep), dpi=dpi) else: py.savefig('%s/gallery/ppdf-steps-pjet-%d-%f.png' % (wdirs[step_keys[-1]], istep, Q2), dpi=dpi)
def line_figure1(self, wdir, had): # self.cluster, colors, nc, order = self.get_clusters(wdir, istep) print 'Generating ff plot' load_config('%s/input.py' % wdir) istep = core.get_istep() jar = load('%s/data/jar-%d.dat' % (wdir, istep)) labels = load('%s/data/labels-%d.dat' % (wdir, istep)) self.cluster = labels['cluster'] n_replicas = len(self.cluster) self.best_cluster = 0 nrows, ncols = 2, 3 fig = py.figure(figsize=(ncols * 5.0, nrows * 3.0)) # AX = [py.subplot(nrows, ncols, cnt) for cnt in range(1, 9)] AX = [py.subplot(nrows, ncols, cnt + 1) for cnt in range(6)] ## FF for i in had: self.data = load('%s/data/ff%s-%d.dat' % (wdir, i, istep)) if i == 'pion': c = 'r' lab = r'$\pi$' elif i == 'kaon': c = 'b' lab = r'$K$' elif i == 'hadron': c = 'k' lab = r'$h$' self.plot_lines(AX[0], 'u+ub', c, n_replicas, lab) self.plot_lines(AX[1], 'd+db', c, n_replicas) self.plot_lines(AX[2], 's+sb', c, n_replicas) self.plot_lines(AX[3], 'c+cb', c, n_replicas) self.plot_lines(AX[4], 'b+bb', c, n_replicas) self.plot_lines(AX[5], 'g', c, n_replicas) AX[0].text(0.9, 0.55, r'$u^+$', color='k', size=20) AX[0].set_ylabel(r'$zD(z)$', size=20) AX[0].legend(loc='upper center') AX[1].text(0.9, 0.55, r'$d^+$', color='k', size=20) AX[2].text(0.9, 0.55, r'$s^+$', color='k', size=20) AX[3].text(0.9, 0.55, r'$c^+$', color='k', size=20) AX[3].set_ylabel(r'$zD(z)$', size=20) AX[3].set_xlabel(r'$z$', size=20, x=0.9, va='baseline') AX[4].text(0.9, 0.55, r'$b^+$', color='k', size=20) AX[4].set_xlabel(r'$z$', size=20, x=0.9, va='baseline') AX[5].text(0.9, 0.55, r'$g$', color='k', size=20) AX[5].set_xlabel(r'$z$', size=20, x=0.9, va='baseline') for ax in AX: ax.set_ylim(0.0, 0.6) # ax.set_yticks([0.2,0.6,1.0,1.4]) ax.set_xlim(0.1, 1.0) ax.set_xticks([0.2, 0.4, 0.6, 0.8]) py.subplots_adjust(left=0.12, bottom=0.08, right=0.99, top=0.97, wspace=None, hspace=0.2) py.tight_layout() py.savefig('%s/gallery/ff-line-plots1-%d.png' % (wdir, istep), dpi=1000)
def steps_comparison_figure(self, wdirs, Q2, dpi): step_keys = sorted(wdirs.keys()) load_config('%s/input.py' % wdirs[step_keys[-1]]) istep = core.get_istep() nrows, ncols = 2, 2 fig = py.figure(figsize=(ncols * 5.0, nrows * 3.0)) axs = [py.subplot(nrows, ncols, cnt + 1) for cnt in range(4)] colors = ['k', 'r', 'g', 'Yellow', 'b'] ## PPDF self.xf_data = {} self.cluster = {} self.best_cluster = {} labels = {} if Q2 == None: Q2 = conf['Q20'] if Q2 == conf['Q20']: for step_key in step_keys: self.xf_data[step_key] = load('%s/data/ppdf-%d.dat' % (wdirs[step_key], step_key)) labels[step_key] = load('%s/data/labels-%d.dat' % (wdirs[step_key], step_key)) self.cluster[step_key] = labels[step_key]['cluster'] self.best_cluster[step_key] = np.argmin( labels[step_key]['cluster_average_chi2']) else: for step_key in step_keys: self.xf_data[step_key] = load('%s/data/ppdf-%d-%f.dat' % (wdirs[step_key], step_key, Q2)) labels[step_key] = load('%s/data/labels-%d.dat' % (wdirs[step_key], step_key)) self.cluster[step_key] = labels[step_key]['cluster'] self.best_cluster[step_key] = np.argmin( labels[step_key]['cluster_average_chi2']) print '\nplotting PPDF band figure with following steps at Q2 = %.2f' % Q2 print[wdirs[_] for _ in wdirs] ax = axs[0] for i in range(len(step_keys)): step = step_keys[i] # alpha = (1.0 / len(step_keys)) * (len(step_keys) - i) alpha = 0.5 color = colors[i] self.plot_band_steps(ax, step, 'uv', color, alpha) self.plot_band_steps(ax, step, 'dv', color, alpha) ax.set_ylim(0.0, 0.5) ax.set_yticks([0.0, 0.1, 0.2, 0.3, 0.4, 0.5]) ax.set_yticklabels([r'$0.1$', r'$0.2$', r'$0.3$', r'$0.4$', r'$0.5$']) ax.text(0.6, 0.3, r'\boldmath$x\Delta u^+$', color='k', transform=axs[0].transAxes, size=28) ax = axs[1] for i in range(len(step_keys)): step = step_keys[i] # alpha = (1.0 / len(step_keys)) * (len(step_keys) - i) alpha = 0.5 color = colors[i] self.plot_band_steps(ax, step, 'd/u', color, alpha) ax.set_ylim(-0.2, 0.0) ax.set_yticks([-0.05, -0.1, -0.15]) ax.set_yticklabels([r'$-0.05$', r'$-0.10$', r'$-0.15$']) ax.text(0.05, 0.15, r'\boldmath$x\Delta d^+$', color='k', transform=axs[1].transAxes, size=28) ax = axs[2] for i in range(len(step_keys)): step = step_keys[i] # alpha = (1.0 / len(step_keys)) * (len(step_keys) - i) alpha = 0.5 color = colors[i] self.plot_band_steps(ax, step, 'db+ub', color, alpha) ax.set_ylim(-0.1, 0.05) ax.set_yticks([-0.08, -0.04, 0.0, 0.04]) ax.set_yticklabels([r'$-0.08$', r'$-0.04$', r'$0.00$', r'$0.04$']) ax.text(0.1, 0.7, r'\boldmath$x\Delta s^+$', color='k', transform=axs[2].transAxes, size=28) ax = axs[3] for i in range(len(step_keys)): step = step_keys[i] # alpha = (1.0 / len(step_keys)) * (len(step_keys) - i) alpha = 0.5 color = colors[i] self.plot_band_steps(ax, step, 'db-ub', color, alpha) ax.set_ylim(-0.11, 0.3) ax.set_yticks([-0.1, 0.0, 0.1, 0.2]) ax.set_yticklabels([r'$-0.1$', r'$0.0$', r'$0.1$', r'$0.2$']) ax.text(0.7, 0.8, r'\boldmath$x\Delta g$', color='k', transform=axs[3].transAxes, size=28) ax = axs[4] for i in range(len(step_keys)): step = step_keys[i] # alpha = (1.0 / len(step_keys)) * (len(step_keys) - i) alpha = 0.5 color = colors[i] self.plot_band_steps(ax, step, 's+sb', color, alpha) ax.text(0.6, 0.8, r'\boldmath$x(s\!+\!\overline{s})$', color='k', transform=ax.transAxes, size=28) ax.set_ylim(0.0, 0.48) ax.set_yticks([0.0, 0.1, 0.2, 0.3, 0.4]) ax.set_yticklabels([r'$0$', r'', r'$0.2$', r'', r'$0.4$']) ax = axs[5] for i in range(len(step_keys)): step = step_keys[i] # alpha = (1.0 / len(step_keys)) * (len(step_keys) - i) alpha = 0.5 color = colors[i] self.plot_band_steps(ax, step, 'rs', color, alpha) ax.text(0.05, 0.78, r'\boldmath$R_s$', color='k', transform=ax.transAxes, size=30) ax.set_ylim(0.0, 1.6) ax.set_yticks([0.0, 0.5, 1.0, 1.5]) ax.set_yticklabels([r'$0$', r'$0.5$', r'$1$', r'$1.5$']) ax = axs[6] for i in range(len(step_keys)): step = step_keys[i] # alpha = (1.0 / len(step_keys)) * (len(step_keys) - i) alpha = 0.5 color = colors[i] label = r'$\mathrm{step~%02d}$' % step self.plot_band_steps(ax, step, 'g', color, alpha, label) ax.text(0.8, 0.8, r'\boldmath$xg$', color='k', transform=ax.transAxes, size=31) ax.set_ylim(0.0, 2.5) ax.set_yticks([0.0, 0.5, 1.0, 1.5, 2.0]) ax.legend(frameon=0, loc='best', bbox_to_anchor=[1.87, 0.9], fontsize=20) for ax in axs: ax.semilogx() ax.set_xlim(8e-3, 9e-1) ax.set_xticks([1e-2, 1e-1]) # ax.xaxis.set_label_coords(0.95, -0.05) ax.tick_params(axis='both', which='both', right=True, top=True, direction='in', labelsize=20) ax.set_xticklabels([r'', r'']) ax.xaxis.set_label_coords(0.7, -0.05) ax.legend(frameon=0, loc='best') axs[2].axhline(0.0, color='k', linestyle='dashdot', linewidth=0.5) axs[3].axhline(0.0, color='k', linestyle='dashdot', linewidth=0.5) for i in range(len(axs) - 1, len(axs) - 1 - ncols, -1): axs[i].set_xlabel(r'\boldmath$x$', size=30) # axs[i].text(0.84, -0.095, r'$0.5$', color = 'k', transform = ax.transAxes, size = 20) axs[i].set_xticks([0.01, 0.1, 0.5, 0.8]) axs[i].set_xticklabels([r'$0.01$', r'$0.1$', r'$0.5$', r'$0.8$']) py.tight_layout() py.subplots_adjust(left=0.05, bottom=0.04, right=0.99, top=0.99, wspace=0.17, hspace=0.04) if Q2 == conf['Q20']: py.savefig('%s/gallery/ppdf-steps-%d.png' % (wdirs[step_keys[-1]], istep), dpi=dpi) else: py.savefig('%s/gallery/ppdf-steps-%d-%f.png' % (wdirs[step_keys[-1]], istep, Q2), dpi=dpi)
def line_figure(self, wdir, Q2, dpi): ## this block may contain something not useful load_config('%s/input.py' % wdir) istep = core.get_istep() # jar = load('%s/data/jar-%d.dat' % (wdir, istep)) labels = load('%s/data/labels-%d.dat' % (wdir, istep)) self.cluster = labels['cluster'] self.cluster_average_chi2 = labels['cluster_average_chi2'] self.best_cluster = np.argmin(self.cluster_average_chi2) nrows, ncols = 2, 2 fig = py.figure(figsize=(ncols * 5.0, nrows * 3.0)) axs = [py.subplot(nrows, ncols, cnt + 1) for cnt in range(4)] ## polarized PDF if Q2 == None: Q2 = conf['Q20'] if Q2 == conf['Q20']: self.xf_data = load('%s/data/ppdf-%d.dat' % (wdir, istep)) else: self.xf_data = load('%s/data/ppdf-%d-%f.dat' % (wdir, istep, Q2)) print '\nplotting polarized PDF line figure from %s at Q2 = %.2f' % ( wdir, Q2) self.plot_lines(axs[0], 'up', 'r', all_cluster=2) self.plot_lines(axs[1], 'dp', 'r', all_cluster=2) self.plot_lines(axs[2], 'sp', 'r', all_cluster=2) self.plot_lines(axs[3], 'g', 'r', all_cluster=2) axs[0].set_ylim(0.0, 0.5) axs[0].set_yticks([0.0, 0.1, 0.2, 0.3, 0.4, 0.5]) axs[0].set_yticklabels( [r'$0.1$', r'$0.2$', r'$0.3$', r'$0.4$', r'$0.5$']) # axs[0].text(0.6, 0.3, r'\boldmath$x\Delta u^+$', color = 'k', transform = axs[0].transAxes, size = 28) axs[0].title.set_text( r'\boldmath$x\Delta u^+~\mathrm{at}~Q^2 = %.2f~\mathrm{GeV}^2$' % Q2) axs[1].set_ylim(-0.2, 0.0) axs[1].set_yticks([-0.05, -0.1, -0.15]) axs[1].set_yticklabels([r'$-0.05$', r'$-0.10$', r'$-0.15$']) # axs[1].text(0.05, 0.15, r'\boldmath$x\Delta d^+$', color = 'k', transform = axs[1].transAxes, size = 28) axs[1].title.set_text( r'\boldmath$x\Delta d^+~\mathrm{at}~Q^2 = %.2f~\mathrm{GeV}^2$' % Q2) axs[2].set_ylim(-0.1, 0.05) axs[2].set_yticks([-0.08, -0.04, 0.0, 0.04]) axs[2].set_yticklabels([r'$-0.08$', r'$-0.04$', r'$0.00$', r'$0.04$']) # axs[2].text(0.1, 0.7, r'\boldmath$x\Delta s^+$', color = 'k', transform = axs[2].transAxes, size = 28) axs[2].title.set_text(r'\boldmath$x\Delta s^+$') axs[3].set_ylim(-0.11, 0.3) axs[3].set_yticks([-0.1, 0.0, 0.1, 0.2]) axs[3].set_yticklabels([r'$-0.1$', r'$0.0$', r'$0.1$', r'$0.2$']) # axs[3].text(0.7, 0.8, r'\boldmath$x\Delta g$', color = 'k', transform = axs[3].transAxes, size = 28) axs[3].title.set_text(r'\boldmath$x\Delta g$') for ax in axs: ax.semilogx() ax.set_xlim(8e-3, 9e-1) ax.set_xticks([1e-2, 1e-1]) # ax.xaxis.set_label_coords(0.95, -0.05) ax.tick_params(axis='both', which='both', right=True, top=True, direction='in', labelsize=20) ax.set_xticklabels([r'', r'']) axs[2].axhline(0.0, color='k', linestyle='dashdot', linewidth=0.5) axs[3].axhline(0.0, color='k', linestyle='dashdot', linewidth=0.5) # for i in range(len(axs)): # if (i % ncols) == 0: axs[i].set_ylabel(r'$xf(x)$', size = 20) for i in range(len(axs) - 1, len(axs) - 1 - ncols, -1): axs[i].set_xlabel(r'\boldmath$x$', size=30) # axs[i].text(0.84, -0.095, r'$0.5$', color = 'k', transform = ax.transAxes, size = 20) axs[i].set_xticks([0.01, 0.1, 0.5, 0.8]) axs[i].set_xticklabels([r'$0.01$', r'$0.1$', r'$0.5$', r'$0.8$']) legends = axs[0].legend(frameon=0, loc='best') for line in legends.get_lines(): line.set_linewidth(1.0) py.subplots_adjust(left=0.12, bottom=0.08, right=0.99, top=0.97, wspace=None, hspace=0.2) py.tight_layout() if Q2 == conf['Q20']: py.savefig('%s/gallery/ppdf-lines-%d.png' % (wdir, istep), dpi=dpi) else: py.savefig('%s/gallery/ppdf-lines-%d-%f.png' % (wdir, istep, Q2), dpi=dpi)
def make_figure(wdir, task, only_best_cluster=True, dpi=200): if task == 1: print('\nplotting PIDIS data from %s' % (wdir)) elif task == 2: print('\nplotting PIDIS data over theory from %s' % (wdir)) load_config('%s/input.py' % wdir) istep = core.get_istep() replicas = core.get_replicas(wdir) core.mod_conf(istep, replicas[0]) #--set conf as specified in istep predictions = load('%s/data/predictions-%d.dat' % (wdir, istep)) if 'pidis' not in predictions['reactions']: print('PIDIS is not in data file') return labels = load('%s/data/labels-%d.dat' % (wdir, istep)) cluster = labels['cluster'] cluster_average_chi2 = labels['cluster_average_chi2'] best_cluster = np.argmin(cluster_average_chi2) data = predictions['reactions']['pidis'] for idx in data: predictions = copy.copy(data[idx]['prediction-rep']) del data[idx]['prediction-rep'] del data[idx]['residuals-rep'] if only_best_cluster: best_predictions = [ predictions[i] for i in range(len(predictions)) if cluster[i] == best_cluster ] data[idx]['thy'] = np.mean(best_predictions, axis=0) data[idx]['dthy'] = np.std(best_predictions, axis=0) else: all_predictions = [predictions[i] for i in range(len(predictions))] data[idx]['thy'] = np.mean(all_predictions, axis=0) data[idx]['dthy'] = np.std(all_predictions, axis=0) maps = generate_maps() subset_bins = pick_subsets(data) # log_list = [] if task == 1: indices = {} for idx in data: observable = data[idx]['obs'][0] target = data[idx]['target'][0] collaboration = data[idx]['col'][0] if (observable == 'A1') or (observable == 'Apa'): if target == 'p': if collaboration.startswith('JLab') != True: if 'Apa_proton' not in indices: indices['Apa_proton'] = [] indices['Apa_proton'].append(idx) elif collaboration.startswith('JLabHB(EG1DVCS)') == True: if 'Apa_proton_DVCS' not in indices: indices['Apa_proton_DVCS'] = [] indices['Apa_proton_DVCS'].append(idx) elif collaboration.startswith('JLabHB(EG1b)') == True: if 'Apa_proton_EG1b' not in indices: indices['Apa_proton_EG1b'] = [] indices['Apa_proton_EG1b'].append(idx) elif target == 'd': if collaboration.startswith('JLab') != True: if 'Apa_deuteron' not in indices: indices['Apa_deuteron'] = [] indices['Apa_deuteron'].append(idx) elif collaboration.startswith('JLabHB(EG1DVCS)') == True: if 'Apa_deuteron_DVCS' not in indices: indices['Apa_deuteron_DVCS'] = [] indices['Apa_deuteron_DVCS'].append(idx) elif collaboration.startswith('JLabHB(EG1b)') == True: if 'Apa_deuteron_EG1b' not in indices: indices['Apa_deuteron_EG1b'] = [] indices['Apa_deuteron_EG1b'].append(idx) elif (observable == 'A2') or (observable == 'Ape') or (observable == 'Atpe'): if target == 'p': if collaboration.startswith('JLab') != True: if 'Ape_proton' not in indices: indices['Ape_proton'] = [] indices['Ape_proton'].append(idx) elif target == 'd': if collaboration.startswith('JLab') != True: if 'Ape_deuteron' not in indices: indices['Ape_deuteron'] = [] indices['Ape_deuteron'].append(idx) if target == 'h': if 'helium' not in indices: indices['helium'] = [] indices['helium'].append(idx) for key in indices: print(key) if key == 'Apa_proton': data_Apa_proton(wdir, data, indices[key], subset_bins, maps, istep, dpi) elif key == 'Apa_proton_DVCS': data_Apa_proton_DVCS(wdir, data, indices[key], subset_bins, maps, istep, dpi) elif key == 'Apa_proton_EG1b': data_Apa_proton_EG1b(wdir, data, indices[key], subset_bins, maps, istep, dpi) elif key == 'Apa_deuteron': data_Apa_deuteron(wdir, data, indices[key], subset_bins, maps, istep, dpi) elif key == 'Apa_deuteron_DVCS': data_Apa_deuteron_DVCS(wdir, data, indices[key], subset_bins, maps, istep, dpi) elif key == 'Apa_deuteron_EG1b': data_Apa_deuteron_EG1b(wdir, data, indices[key], subset_bins, maps, istep, dpi) elif key == 'Ape_proton': data_Ape_proton(wdir, data, indices[key], subset_bins, maps, istep, dpi) elif key == 'Ape_deuteron': data_Ape_deuteron(wdir, data, indices[key], subset_bins, maps, istep, dpi) elif key == 'helium': data_helium(wdir, data, indices[key], subset_bins, maps, istep, dpi) elif task == 2: plot_data_on_theory(wdir, data, istep, dpi) return