-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_yml.py
53 lines (49 loc) · 2.23 KB
/
make_yml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import yaml
import os
def make_yml(params_vary, corrs, bias_model, lmin, kmax,
mass_function, concentration, hm_correction, ns_independent,
fname_data, dirname_out,
sampler, nsamples=10000, measure_speeds=True,
debug=True):
samplers = {
'minimize': {'ignore_prior': True, 'max_evals': nsamples},
'mcmc': {'learn_proposal': True, 'burn_in': 10, 'max_samples': nsamples}}
# Open master file
with open('master.yml', "r") as f:
dflt = yaml.load(f, Loader=yaml.FullLoader)
# Update parameters
pars = {k: d['ref']['loc'] for k, d in dflt['params'].items()}
for p in params_vary:
if p not in pars:
raise ValueError(f"Unknown param {p}")
pars[p] = dflt['params'][p]
# Update two-point functions
twopts = [{'bins': [t1, t2]} for t1, t2 in corrs]
# Create dictionary
dout = dflt.copy()
dout['params'] = pars
dout['likelihood']['ygk_like.ygkLike']['twopoints'] = twopts
dout['likelihood']['ygk_like.ygkLike']['bz_model'] = bias_model
dout['likelihood']['ygk_like.ygkLike']['mf_name'] = mass_function
dout['likelihood']['ygk_like.ygkLike']['cm_name'] = concentration
dout['likelihood']['ygk_like.ygkLike']['HM_correction'] = hm_correction
dic = dout["likelihood"]["ygk_like.ygkLike"]["defaults"]
for item in dic:
if item.startswith("LOWZ"):
dic[item]["lmin"] = lmin
dout['likelihood']['ygk_like.ygkLike']['defaults']['lmin'] = lmin
dout['likelihood']['ygk_like.ygkLike']['defaults']['kmax'] = kmax
dout['likelihood']['ygk_like.ygkLike']['ns_independent'] = ns_independent
dout['likelihood']['ygk_like.ygkLike']['input_file'] = fname_data
dout['debug'] = debug
dout['output'] = f'{dirname_out}/cobaya'
dout['sampler'] = {sampler: samplers[sampler]}
if sampler == 'mcmc' and not measure_speeds:
# option to not measure speeds if likelihood
# does not depend on theory (theory is fixed)
dout['sampler']['mcmc']['measure_speeds'] = False
# Save output
os.system(f'mkdir -p {dirname_out}')
fname_out = f'{dirname_out}/params.yml'
with open(fname_out, 'w') as outfile:
yaml.dump(dout, outfile, default_flow_style=False)