Skip to content

Commit

Permalink
debug makeDerivs for regular CAMB
Browse files Browse the repository at this point in the history
  • Loading branch information
honamnguyen committed May 28, 2017
1 parent a4f21da commit 5e0b426
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
38 changes: 25 additions & 13 deletions bin/makeDerivs_axionCAMB.py → bin/makeDerivs_CAMB.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from cambCall import cambInterface

def getClsAxionCamb(out_pre,spec,templateIni,params,AccuracyBoost=False,seed=0):
def getClsCamb(out_pre,spec,templateIni,params,cambRoot=os.environ['AXIONCAMB_DIR'],AccuracyBoost=False,seed=0):
option = 0 # for regular CAMB call
CAMB = cambInterface(out_pre,templateIni,cambRoot=os.environ['AXIONCAMB_DIR'],option=option,seed=seed)
CAMB = cambInterface(out_pre,templateIni,cambRoot=cambRoot,option=option,seed=seed)
for key in params:
CAMB.setParam(key,params[key])
CAMB.call(suppress=False)
Expand All @@ -24,22 +24,28 @@ def main(argv):
inv_nameMap = {v: k for k, v in nameMap.items()}

# Read Config
iniFile = "input/makeDerivs_axionCAMB.ini"
try:
iniFile = argv[0]
except:
iniFile = "input/makeDerivs_axionCAMB.ini"
Config = ConfigParser.SafeConfigParser()
Config.optionxform = str
Config.read(iniFile)

out_pre = Config.get('general','output_prefix')
spec = Config.get('general','spec')
AccuracyBoost = Config.getboolean('general','AccuracyBoost')
templateIni = os.environ['AXIONCAMB_DIR']+Config.get('general','templateIni')

templateIni = Config.get('general','templateIni')
cambRoot = Config.get('general','cambRoot')
if not os.path.isfile(templateIni):
templateIni = cambRoot+Config.get('general','templateIni')

paramList = []
fparams = {}
stepSizes = {}
fidscript = ''

for (key, val) in Config.items('axionCAMB'):
for (key, val) in Config.items('CAMB'):
fidscript += key+' = '+val+'\n'
if key in nameMap:
key = nameMap[key]
Expand All @@ -49,16 +55,22 @@ def main(argv):
fparams[key] = float(param)
stepSizes[key] = float(step)
else:
try:
fparams[key] = eval(val)
except:
fparams[key] = val
'''
if key in ['l_max_scalar','massive_neutrinos']:
fparams[key] = int(val)
else:
fparams[key] = float(val)
'''
if 'massless_neutrinos' in fparams:
fparams['massless_neutrinos'] -= fparams['massive_neutrinos']

# Save fid + stepsize
fidscript = '[camb]\n'+fidscript
filename = os.environ['FISHER_DIR']+"/output/"+out_pre+'_'+spec+"_axion_fid.csv"
filename = 'output/'+out_pre+'_'+spec+"_CAMB_fid.csv"
with open(filename,'w') as tempFile:
tempFile.write(fidscript)

Expand All @@ -69,8 +81,8 @@ def main(argv):
print "Calculating and saving fiducial cosmology..."
if not('omnuh2' in fparams) and ('mnu' in fparams):
fparams['omnuh2'] = round(fparams['mnu']/93.14,6)
fCls = getClsAxionCamb(out_pre,spec,templateIni,fparams,AccuracyBoost=AccuracyBoost)
np.savetxt("output/"+out_pre+'_'+spec+"_axion_fCls.csv",fCls,delimiter=",")
fCls = getClsCamb(out_pre,spec,templateIni,fparams,cambRoot=cambRoot,AccuracyBoost=AccuracyBoost)
np.savetxt("output/"+out_pre+'_'+spec+"_CAMB_fCls.csv",fCls,delimiter=",")

sys.exit()
# Calculate and save derivatives
Expand All @@ -82,21 +94,21 @@ def main(argv):
pparams[paramName] = fparams[paramName] + 0.5*h
if paramName =='mnu':
pparams['omnuh2'] = round(pparams['mnu']/93.14,6)
pCls = getClsAxionCamb(out_pre,spec,templateIni,pparams,AccuracyBoost=AccuracyBoost)
pCls = getClsCamb(out_pre,spec,templateIni,pparams,cambRoot=cambRoot,AccuracyBoost=AccuracyBoost)


print "Calculating backward difference for ", paramName
mparams = fparams.copy()
mparams[paramName] = fparams[paramName] - 0.5*h
if paramName =='mnu':
mparams['omnuh2'] = round(mparams['mnu']/93.14,6)
mCls = getClsAxionCamb(out_pre,spec,templateIni,mparams,AccuracyBoost=AccuracyBoost)
mCls = getClsCamb(out_pre,spec,templateIni,mparams,cambRoot=cambRoot,AccuracyBoost=AccuracyBoost)

dCls = (pCls-mCls)/h
if paramName in inv_nameMap:
np.savetxt("output/"+out_pre+'_'+spec+"_axion_dCls_"+inv_nameMap[paramName]+".csv",dCls,delimiter=",")
np.savetxt("output/"+out_pre+'_'+spec+"_CAMB_dCls_"+inv_nameMap[paramName]+".csv",dCls,delimiter=",")
else:
np.savetxt("output/"+out_pre+'_'+spec+"_axion_dCls_"+paramName+".csv",dCls,delimiter=",")
np.savetxt("output/"+out_pre+'_'+spec+"_CAMB_dCls_"+paramName+".csv",dCls,delimiter=",")
print 'End of program'
if (__name__ == "__main__"):
main(sys.argv[1:])
32 changes: 32 additions & 0 deletions input/makeDerivs_CAMB.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[CAMB]
# Fiducial, stepsize
H0 = 67.31,0.67
ombh2 = 0.0222,0.00022
#omch2 = 0.
omch2 = 0.1197,0.0012
tau = 0.06,0.0006
ns = 0.9655,0.0097
As = 2.2e-9,2.2e-11
mnu = 0.06,0.024
nnu= 3.046,0.08
w=-1.0
#,0.3
#r=0.0
omk = 0
lmax = 45000
kmax = 200000
#YHe = 0.24
TCMB = 2.7255
num_massive_neutrinos = 1
s_pivot = 0.05
t_pivot = 0.05

do_nonlinear = 0
halofit_version = 5

[general]
output_prefix = May28_highAcc_linear
spec = unlensed
AccuracyBoost = True
templateIni = params_testNN.ini
cambRoot = /home/nhnguyen/CAMB-May2016/

0 comments on commit 5e0b426

Please sign in to comment.