def loadJobItemResults(self, paramNameFile=None, bestfit=True, bestfitonly=False, noconverge=False, silent=False): self.result_converge = None self.result_marge = None self.result_likemarge = None self.result_bestfit = self.chainBestfit(paramNameFile) if not bestfitonly: marge_root = self.distRoot if self.getDistExists(): if not noconverge: self.result_converge = ResultObjs.convergeStats(marge_root + '.converge') self.result_marge = ResultObjs.margeStats(marge_root + '.margestats', paramNameFile) self.result_likemarge = ResultObjs.likeStats(marge_root + '.likestats') if self.result_bestfit is not None and bestfit: self.result_marge.addBestFit(self.result_bestfit) elif not silent: print 'missing: ' + marge_root
def compareTable(jobItems, titles=None): for jobItem in jobItems: jobItem.loadJobItemResults(paramNameFile=args.paramNameFile, bestfit=not args.nobestfit, bestfitonly=args.bestfitonly) print jobItem.name if titles is None: titles = [jobItem.datatag for jobItem in jobItems if jobItem.result_marge is not None] else: titles = titles.split(';') return ResultObjs.resultTable(1, [jobItem.result_marge for jobItem in jobItems if jobItem.result_marge is not None], formatter=formatter, limit=args.limit, titles=titles, blockEndParams=args.blockEndParams, paramList=args.paramList).lines
def margeParamTex(rootname, params=None, limit=1, paramNameFile=None): """ Get tex snipped for constraint on parameters in params """ if not '.margestats' in rootname: rootname += '.margestats' marge = ResultObjs.margeStats(rootname , paramNameFile) if not params: params = marge.list() formatter = ResultObjs.noLineTableFormatter() texs = [] labels = [] for par in params: tex = marge.texValues(formatter, par, limit=limit) if tex is not None: texs.append(tex[0]) labels.append(marge.parWithName(par).label) else: texs.append(None) labels.append(None) return params, labels, texs
def loadFiles(pat, max_files=400, cl_ix=1, calParam=None, rescale=1): d, name = os.path.split(pat + '_?_*') pars = [] cls = [] ls = None for f in os.listdir(d): if fnmatch.fnmatch(f, name + '.theory_cl'): fname = f.replace('.theory_cl', '') params = ResultObjs.bestFit(os.path.join(d, fname + '.pars')) pars.append(params) cl = loadtxt(os.path.join(d, fname + '.theory_cl')) if calParam: cal = params.parWithName(calParam).best_fit else: cal = 1 cls.append(cl[:, cl_ix] / cal ** 2 * rescale) if ls is None: ls = cl[:, 0] if len(pars) == max_files: break if not len(pars): raise Exception('No files found: ' + pat) return ls, pars, cls
Opts = batchJobArgs.batchArgs('Compare parameter constraints over set of models') Opts.parser.add_argument('--params', nargs='+') Opts.parser.add_argument('--chain_name_params', nargs='+') Opts.parser.add_argument('--compare', nargs='+', default=None) Opts.parser.add_argument('--nobestfits', action='store_true') Opts.parser.add_argument('--single_extparam', action='store_true') Opts.parser.add_argument('--limit', type=int, default=2) Opts.parser.add_argument('--latex_filename', default=None) Opts.parser.add_argument('--mathColumns', action='store_true') Opts.parser.add_argument('--endline', default='\\cr') Opts.parser.add_argument('--paramNameFile', default='clik_latex.paramnames') (batch, args) = Opts.parseForBatch() formatter = ResultObjs.tableFormatter() names = paramNames.paramNames(args.paramNameFile) if args.chain_name_params is None: args.chain_name_params = args.params if args.compare: args.compare = [batch.normalizeDataTag(dat) for dat in args.compare] table = dict() paramtag_for_param = dict() for par in args.params: paramtag_for_param[par] = [] for jobItem in Opts.filteredBatchItems(): if (args.compare is None or jobItem.matchesDatatag(args.compare)) and (not args.single_extparam or len(jobItem.param_set) == 1 and jobItem.hasParam(args.chain_name_params)):
sys.exit() root = os.path.abspath(sys.argv[1]) pars = {'ombh2':'omegabh2', 'omch2':'omegach2', 'omnuh2':'omeganuh2', 'hubble':'H0', 'w':'w', 'helium_fraction':'yheused', 'scalar_amp(1)':'A' , 'scalar_spectral_index(1)':'ns', 'scalar_nrun(1)':'nrun', 'initial_ratio(1)':'r', 're_optical_depth':'tau', 're_delta_redshift':'deltazrei', 'massless_neutrinos':'nnu'} ini = iniFile.iniFile() ini.params['re_use_optical_depth'] = True ini.params['temp_cmb'] = 2.7255 ini.params['CMB_outputscale'] = 2.7255e6 ** 2. ini.defaults.append('params.ini') bf = ResultObjs.bestFit(root + '.minimum', setParamNameFile=root + '.paramnames', want_fixed=True) for camb, cosmomc in pars.items(): par = bf.parWithName(cosmomc) if par is not None: ini.params[camb] = par.best_fit ini.params['scalar_amp(1)'] = float(ini.params['scalar_amp(1)']) / 1e9 nmassive = 1 neffstandard = 3.046 / 3 ini.params['massless_neutrinos'] = float(ini.params['massless_neutrinos']) - neffstandard * nmassive ini.params['massive_neutrinos'] = int(round(neffstandard * nmassive)) ini.params['nu_mass_degeneracies'] = neffstandard * nmassive ini.params['share_delta_neff'] = False ini.params['tensor_spectral_index(1)'] = -float(ini.params['initial_ratio(1)']) / 8
def R(self): if self.result_converge is None: fname = self.distRoot + '.converge' if not nonEmptyFile(fname): return None self.result_converge = ResultObjs.convergeStats(fname) return float(self.result_converge.worstR())
def chainBestfit(self, paramNameFile=None): bf_file = self.chainRoot + '.minimum' if nonEmptyFile(bf_file): return ResultObjs.bestFit(bf_file, paramNameFile) return None
def getTableLines(content, referenceDataJobItem=None): if referenceDataJobItem is not None: refResults = referenceDataJobItem.result_marge else: refResults = None return ResultObjs.resultTable(args.columns, [content], blockEndParams=args.blockEndParams, formatter=formatter, paramList=args.paramList, limit=args.limit, refResults=refResults, shiftSigma_indep=args.shift_sigma_indep, shiftSigma_subset=args.shift_sigma_subset).lines
elif args.changes_replacing is not None: referenceDataJobItem = None for replace in args.changes_replacing[1:]: if replace in jobItem.data_set.names: referenceDataJobItem = baseJobItems.get( batch.normalizeDataTag(jobItem.data_set.tagReplacing(replace, args.changes_replacing[0])), None) break referenceJobItem = referenceDataJobItem if args.changes_only and not referenceDataJobItem: continue else: referenceJobItem = baseJobItems.get(dataIndex(jobItem), None) if args.changes_from_paramtag is not None: referenceDataJobItem = referenceJobItem if not args.forpaper: lines.append('\\subsection{ ' + texEscapeText(jobItem.name) + '}') try: tableLines = paramResultTable(jobItem, referenceJobItem, referenceDataJobItem) if args.separate_tex: ResultObjs.textFile(tableLines).write(jobItem.distRoot + '.tex') lines += tableLines except Exception as e: print 'ERROR: ' + jobItem.name print "Index Error:" + e.message if not args.forpaper: lines.append('\\end{document}') (outdir, outname) = os.path.split(outfile) if len(outdir) > 0 and not os.path.exists(outdir): os.makedirs(outdir) ResultObjs.textFile(lines).write(outfile) (root, _) = os.path.splitext(outfile) if not args.forpaper: print 'Now converting to PDF...' delext = ['aux', 'log', 'out', 'toc']
def formatTitle(self, title): return ResultObjs.texEscapeText(title)