1+ """
2+
3+ Adapted from the module wigglez_bao and bao.f90 of cosmomc
4+
5+ """
6+ from cosmosis .datablock import option_section
7+ import os
8+ import numpy as np
9+ from cosmosis .datablock import names as section_names
10+
11+ dist = section_names .distances
12+ likes = section_names .likelihoods
13+
14+ ROOT_dir = os .path .split (os .path .abspath (__file__ ))[0 ]
15+
16+ dirname = os .path .split (__file__ )[0 ]
17+ # Taken from DES Y6BAO likelihood
18+ # https://github.com/des-science/y6kp-bao-methods/blob/main/des-y6-bao/bao_y6_like.py
19+ REDSHIFT = 0.851
20+ # Fiducial Planck cosmology rs which was used to compute alpha
21+ RS_FIDUCIAL = 147.8
22+ # Angular diameter distance at the fiducial cosmology, d_a(zeff=0.851)
23+ DA_FIDUCIAL = 1627.70
24+ DM_FIDUCIAL = DA_FIDUCIAL * (1 + REDSHIFT )
25+
26+ def setup (options ):
27+ section = option_section
28+ CHI2_file = os .path .join (ROOT_dir ,'likelihood_mean.txt' )
29+ chi2 = np .loadtxt (CHI2_file )
30+ redshift = options .get_double (section , "redshift" , default = REDSHIFT )
31+ feedback = options .get_int (option_section , "feedback" , default = 0 )
32+
33+ #Return data for later
34+ return (chi2 ,redshift ,feedback )
35+
36+ def execute (block , config ):
37+
38+ chi2 ,redshift ,feedback = config
39+
40+ alpha = chi2 [:,0 ]
41+ if feedback :
42+ print ("alpha min = " , alpha [0 ])
43+ print ("alpha max = " , alpha [- 1 ])
44+ chi2_alpha = chi2 [:,1 ] #careful with norm. Don't care about absolute value of likelihood . -0.5*np.log(2*np.pi*sigma**2))
45+ rs_fiducial = RS_FIDUCIAL
46+ d_m_ficucial = DM_FIDUCIAL
47+
48+ #load distance relations and R_S
49+ dist_z = block [dist , "z" ]
50+ d_m = block [dist , 'd_m' ] #in Mpc
51+ h = block [dist , "h" ] #in 1/Mpc
52+ rs = block [dist , "RS_ZDRAG" ] #in Mpc
53+ if dist_z [1 ] < dist_z [0 ]:
54+ dist_z = dist_z [::- 1 ]
55+ d_m = d_m [::- 1 ]
56+ h = h [::- 1 ]
57+
58+
59+ #Compute the derived D_V distance
60+ #d_v = (dist_z*d_m*d_m/h)**(1./3.)
61+
62+ #Interpolate the theory at the
63+ #observed redshift
64+ d_m_predicted = np .interp (redshift , dist_z , d_m )
65+ alpha_predicted = (d_m_predicted / d_m_ficucial )* (rs_fiducial / rs )
66+
67+ #If required, print out some info
68+ if feedback :
69+ print ("redshift = " , redshift )
70+ print ("alpha predicted = " , alpha_predicted )
71+ print ("rs = " , rs )
72+ print ("rs_fiducial = " , rs_fiducial )
73+
74+ #interpole the chi2 at the alpha predicted
75+ if alpha_predicted < alpha [0 ]:
76+ chi2_alpha_predicted = chi2_alpha [0 ]
77+ elif alpha_predicted > alpha [- 1 ]:
78+ chi2_alpha_predicted = chi2_alpha [- 1 ]
79+ else :
80+ #simple interpolation of chi2 at the predicted alpha
81+ ii = int (np .floor ((alpha_predicted - alpha [0 ])/ 0.00404 )) #0.00404 is the step of alpha in chi2 file
82+ chi2_alpha_predicted = (chi2_alpha [ii + 1 ] - chi2_alpha [ii ])* (alpha_predicted - alpha [ii ])/ (alpha [ii + 1 ] - alpha [ii ]) + chi2_alpha [ii ]
83+
84+ #Get the log likelihood from the chi2
85+ like = - chi2_alpha_predicted / 2.
86+ block [likes , 'DESY6BAO_LIKE' ] = like
87+
88+ #Signal success
89+ return 0
90+
91+ def cleanup (config ):
92+ pass
0 commit comments