-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #760 from LSSTDESC/k_NL_integral
Implemented integral at C level to compute scale k_NL for a non-linear cut.
- Loading branch information
Showing
18 changed files
with
325 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# [0] a, [1] k_NL Mpc^-1 | ||
1.000000000000000056e-01 9.589032014324436748e-01 | ||
1.291549665014883885e-01 7.428033944455602056e-01 | ||
1.668100537200058742e-01 5.757310448836822081e-01 | ||
2.154434690031883370e-01 4.467698285641908407e-01 | ||
2.782559402207124277e-01 3.475697112659149601e-01 | ||
3.593813663804627523e-01 2.718037161313307526e-01 | ||
4.641588833612778631e-01 2.147341521854057300e-01 | ||
5.994842503189409255e-01 1.727980028153486558e-01 | ||
7.742636826811269968e-01 1.431192890249111394e-01 | ||
1.000000000000000000e+00 1.230450029799866479e-01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"import pyccl as ccl\nimport numpy as np\nimport scipy.integrate\nimport math\nfrom functools import partial","execution_count":13,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"cosmoin = ccl.Cosmology(\n Omega_c=0.25,\n Omega_b=0.05,\n h=0.7,\n sigma8=0.8,\n n_s=0.96,\n Neff=0,\n m_nu=0.0,\n w0=-1.,\n wa=0.,\n T_CMB=2.7,\n m_nu_type='normal',\n Omega_g=0,\n Omega_k=0,\n transfer_function='bbks',\n matter_power_spectrum='linear')","execution_count":23,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"k_lin=np.logspace(-4., 3., 10000)\na_arr = np.logspace(-1., 0., 10)\nknl_arr = np.zeros((len(a_arr),))\nfor i in range(len(a_arr)):\n a = a_arr[i]\n #I will need linear power at z\n pk_lin_z=ccl.linear_matter_power(cosmoin, k_lin, a)\n interp_pk_lin_z=scipy.interpolate.interp1d(k_lin,pk_lin_z)\n\n\n #---kNL prediction----\n [intknl,errintknl]=scipy.integrate.quad(interp_pk_lin_z,min(k_lin),max(k_lin),epsabs=0,epsrel=1e-6)\n print(\"Check error is small:\",errintknl/intknl)\n knlemin2=1./(6*math.pi**2)*intknl\n knl=1./math.sqrt(knlemin2)\n print('knl[1/Mpc]=',knl)\n knl_arr[i] = knl","execution_count":44,"outputs":[{"name":"stdout","output_type":"stream","text":"Check error is small: 1.5286495983617028e-07\nknl[1/Mpc]= 0.12304500297998665\n"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"header_knl=\"[0] a, [1] k_NL Mpc^-1\"\n\nnp.savetxt(\"kNL.txt\", np.transpose(np.vstack((a_arr ,knl_arr))), header=header_knl)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.6.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":2} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pyccl as ccl | ||
import numpy as np | ||
import scipy.integrate | ||
import math | ||
from functools import partial | ||
|
||
cosmoin=ccl.Cosmology( | ||
Omega_c=0.25, | ||
Omega_b=0.05, | ||
h=0.7, | ||
sigma8=0.8, | ||
n_s=0.96, | ||
Neff=0, | ||
m_nu=0.0, | ||
w0=-1., | ||
wa=0., | ||
T_CMB=2.7, | ||
m_nu_type='normal', | ||
Omega_g=0, | ||
Omega_k=0, | ||
transfer_function='bbks', | ||
matter_power_spectrum='linear') | ||
|
||
k_lin=np.logspace(-4., 3., 10000) | ||
a_arr = np.logspace(-1., 0., 10) | ||
knl_arr = np.zeros((len(a_arr),)) | ||
for i in range(len(a_arr)): | ||
a = a_arr[i] | ||
#I will need linear power at z | ||
pk_lin_z=ccl.linear_matter_power(cosmoin, k_lin, a) | ||
interp_pk_lin_z=scipy.interpolate.interp1d(k_lin,pk_lin_z) | ||
|
||
|
||
#---kNL prediction---- | ||
[intknl,errintknl]=scipy.integrate.quad(interp_pk_lin_z,min(k_lin),max(k_lin),epsabs=0,epsrel=1e-6) | ||
print("Check error is small:",errintknl/intknl) | ||
knlemin2=1./(6*math.pi**2)*intknl | ||
knl=1./math.sqrt(knlemin2) | ||
print('knl[1/Mpc]=',knl) | ||
knl_arr[i] = knl | ||
|
||
header_knl="[0] a, [1] k_NL Mpc^-1" | ||
|
||
np.savetxt("kNL.txt", np.transpose(np.vstack((a_arr ,knl_arr))), header=header_knl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# [0] a, [1] k_NL Mpc^-1 | ||
1.000000000000000056e-01 9.589032014324436748e-01 | ||
1.291549665014883885e-01 7.428033944455602056e-01 | ||
1.668100537200058742e-01 5.757310448836822081e-01 | ||
2.154434690031883370e-01 4.467698285641908407e-01 | ||
2.782559402207124277e-01 3.475697112659149601e-01 | ||
3.593813663804627523e-01 2.718037161313307526e-01 | ||
4.641588833612778631e-01 2.147341521854057300e-01 | ||
5.994842503189409255e-01 1.727980028153486558e-01 | ||
7.742636826811269968e-01 1.431192890249111394e-01 | ||
1.000000000000000000e+00 1.230450029799866479e-01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import numpy as np | ||
import pyccl as ccl | ||
|
||
KNL_TOLERANCE = 1.0e-5 | ||
|
||
|
||
def test_kNL(): | ||
cosmo = ccl.Cosmology( | ||
Omega_c=0.25, | ||
Omega_b=0.05, | ||
h=0.7, | ||
sigma8=0.8, | ||
n_s=0.96, | ||
Neff=0, | ||
m_nu=0.0, | ||
w0=-1., | ||
wa=0., | ||
T_CMB=2.7, | ||
m_nu_type='normal', | ||
Omega_g=0, | ||
Omega_k=0, | ||
transfer_function='bbks', | ||
matter_power_spectrum='linear') | ||
|
||
data = np.loadtxt('./benchmarks/data/kNL.txt') | ||
a = data[:, 0] | ||
kNL = data[:, 1] | ||
kNL_ccl = ccl.kNL(cosmo, a) | ||
for i in range(len(a)): | ||
err = np.abs(kNL_ccl[i]/kNL[i] - 1) | ||
assert np.allclose(err, 0, rtol=0, atol=KNL_TOLERANCE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.