Skip to content

Test power spectra against "truth", both massless and massive nu #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: module/power_spectrum
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions skypy/power_spectrum/_camb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CAMB(TabulatedPowerSpectrum):
redshift and wavenumber using CAMB.
'''

def __init__(self, kmax, redshift, cosmology, A_s, n_s, **kwargs):
def __init__(self, kmax, redshift, cosmology, A_s, n_s, tau, **kwargs):

try:
from camb import CAMBparams, model, get_results
Expand All @@ -30,16 +30,25 @@ def __init__(self, kmax, redshift, cosmology, A_s, n_s, **kwargs):
omk=cosmology.Ok0,
TCMB=cosmology.Tcmb0.value,
mnu=np.sum(cosmology.m_nu.to_value(units.eV)),
standard_neutrino_neff=cosmology.Neff
num_massive_neutrinos=1,
standard_neutrino_neff=cosmology.Neff,
tau=tau,
YHe=0.24,
)

pars.InitPower.ns = n_s
pars.InitPower.As = A_s
pars.NonLinear = model.NonLinear_none
k_per_logint, var1, var2, hubble_units, nonlinear = None, None, None, False, False
pars.set_matter_power(redshifts=redshift, kmax=kmax, k_per_logint=k_per_logint, silent=True)
pars.set_matter_power(redshifts=redshift,
kmax=kmax,
k_per_logint=k_per_logint,
# accurate_massive_neutrino_transfers=True,
silent=True)

results = get_results(pars)
k, z, p = results.get_linear_matter_power_spectrum(var1, var2, hubble_units,
k_hunit=False,
nonlinear=nonlinear)

super().__init__(k*cosmology.h, z, p)
super().__init__(k, z, p)
19 changes: 17 additions & 2 deletions skypy/power_spectrum/_classy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from astropy import units
from ._base import TabulatedPowerSpectrum

__all__ = [
Expand All @@ -11,7 +12,7 @@ class CLASSY(TabulatedPowerSpectrum):
two dimensional grid of wavenumber and redshift.
"""

def __init__(self, kmax, redshift, cosmology, **kwargs):
def __init__(self, kmax, redshift, cosmology, A_s, n_s, tau, **kwargs):
try:
from classy import Class
except ImportError:
Expand All @@ -23,13 +24,27 @@ def __init__(self, kmax, redshift, cosmology, **kwargs):
'output': 'mPk',
'P_k_max_1/Mpc': kmax,
'z_pk': ', '.join(str(z) for z in np.atleast_1d(redshift)),
'A_s': A_s,
'n_s': n_s,
'H0': cosmology.H0.value,
'omega_b': cosmology.Ob0 * h2,
'omega_cdm': cosmology.Odm0 * h2,
'T_cmb': cosmology.Tcmb0.value,
'N_eff': cosmology.Neff,
'N_ncdm': cosmology._nmassivenu,
'N_ur': cosmology.Neff - cosmology._nmassivenu,
'tau_reio': tau,
'YHe': 0.24
}

if cosmology.has_massive_nu:

params['T_ncdm'] = 0.7133

if cosmology._nmassivenu == 1:
params['m_ncdm'] = np.sum(cosmology.m_nu.to_value(units.eV))
else:
params['m_ncdm'] = ', '.join(cosmology.m_nu.to_value(units.eV).astype(str))

params.update(kwargs)

classy_obj = Class()
Expand Down
205 changes: 205 additions & 0 deletions skypy/power_spectrum/tests/data/truth_pk_massive_nu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# k Pk(z=0.0) Pk(z=1.0)
7.0482068471392265e-06 149.9782038185607 55.53062337198318
7.782589398811979e-06 165.03150076739075 61.10421725964271
8.593490540988569e-06 181.5956679953026 67.23723248351115
9.48888250040909e-06 199.82228271068516 73.98579675384428
1.0477569843715173e-05 219.8783031442084 81.41170683920956
1.1569272033739253e-05 241.94727635546596 89.58291483251764
1.2774723236361752e-05 266.2311772381725 98.57425812030543
1.410577582391852e-05 292.9523506866617 108.4679934852785
1.5575515584350796e-05 322.3553568925519 119.35472681349943
1.7198394797014772e-05 354.7092919758921 131.334074544891
1.8990367772858008e-05 390.31025367746463 144.5156710438236
2.0969055966997985e-05 429.4840378953578 159.02016922410473
2.315390939475037e-05 472.589112138901 174.98024871447853
2.556641363844392e-05 520.0197914299015 192.542044382416
2.823028576458455e-05 572.2101229699033 211.8660955031027
3.1171719528356334e-05 629.6373530404383 233.12922577674502
3.441963181030587e-05 692.826433769211 256.5258931735537
3.8005958340363575e-05 762.3552374400161 282.2699890695871
4.196595927933231e-05 838.859130374458 310.59685815037966
4.633857408771291e-05 923.0372202118009 341.7653332482196
5.116678625199711e-05 1015.6578709496798 376.05994673003016
5.6498069335066246e-05 1117.5662010117835 413.7940128674996
6.238484041969059e-05 1229.6916755291338 455.31151045677177
6.888498255430022e-05 1353.0558554840627 500.991018881833
7.606239677115809e-05 1488.781561797604 551.2483921785711
8.398766253667419e-05 1638.1030420431962 606.5409557598083
9.273868834425229e-05 1802.3752702809402 667.3708197836536
0.00010240152988408226 1983.086003571112 734.2896529865532
0.00011307117371179629 2181.8694337137877 807.9029428724871
0.0001248525427101413 2400.5165421954134 888.8750906714337
0.00013786145226331428 2640.992968751654 977.934644500515
0.0001522258227254497 2905.450481652384 1075.8802474633146
0.00016808687217417174 3196.2436912036087 1183.5859642660123
0.00018560055560083128 3515.9486114868096 1302.00775078039
0.00020493905338807964 3867.3768064667443 1432.1903151784418
0.00022629253579652868 4253.595708822454 1575.2726988341906
0.0002498709077364765 4677.942236208305 1732.4954127339531
0.00027590601684059947 5144.043049036751 1905.206552912328
0.0003046538221067749 5655.829874314982 2094.867699089723
0.0003363969962694682 6217.553390982321 2303.0588961545686
0.00037144762674579395 6833.798502564272 2531.4830654864336
0.00041015033059520645 7509.4942763479785 2781.9703353675036
0.0004528856060584076 8249.919507911272 3056.4777407319734
0.000500073696684558 9060.709476153714 3357.090482596572
0.0005521784948883578 9947.837912710927 3686.018341802893
0.0006097123129642568 10917.61478162621 4045.590587876378
0.000673240811820142 11976.643066098106 4438.24636588256
0.0007433886000188068 13131.772166784942 4866.515866985488
0.0008208454242674633 14390.011079677945 5332.999597697991
0.0009063727542059496 15758.448438568174 5840.326600674321
0.0010008115500910208 17244.121229539494 6391.116419801656
0.0011050903853494674 18853.872746763765 6987.907285491563
0.0012202344365883618 20594.14101572235 7633.087053010613
0.001347375735361129 22470.725992979198 8328.808031765098
0.0014877645239699633 24488.57207650982 9076.910178069369
0.0016427810055669398 26651.407363843264 9878.781539392709
0.0018139493811875581 28961.46216708297 10735.259352203337
0.0020029523599427194 31419.07208746624 11646.477427310774
0.0022116485081613065 34022.30912366742 12611.728093443458
0.002442089440813288 36766.420953950736 13629.273543136256
0.0026965412713587282 39643.3652904102 14696.135423847014
0.0029775052729994057 42641.08527084177 15807.8668392092
0.0032877439023926854 45742.9625240558 16958.31934951609
0.0036303080851212144 48927.22567256212 18139.442573573695
0.004008565132040531 52166.084733837204 19340.949404247036
0.004426234383881092 55426.58189047734 20550.652249896415
0.0048874225404113535 58661.9851658501 21751.217502026997
0.005396664036624133 61822.125153151974 22924.047059823173
0.005958964888751507 64851.63127975318 24048.629727518986
0.006579854741692543 67682.47209669683 25099.770027605482
0.0072654379701241854 70236.51923917355 26048.46942368269
0.008022454242780804 72427.80573090223 26862.848127605674
0.008858347919024527 74163.82644955989 27508.595694011594
0.009781336814537644 75345.9737797725 27949.109986710046
0.010800494846329093 75875.23269223826 28147.60819743336
0.011925844771787524 75658.58451013103 28069.513840898526
0.013168448404222727 74618.60574907725 27686.03806348136
0.014540525848791003 72706.44166522472 26978.930202855045
0.016055564013496042 69917.22488899574 25946.285287851562
0.017728461711108683 66306.76566796024 24608.702608962878
0.01957566466704011 62005.56986027615 23014.501490923245
0.02161533585637808 57224.37407512566 21241.840760863208
0.023867529626190664 52244.50802864436 19395.080432651604
0.026354387267678976 47388.19437700915 17593.822891722168
0.029100364132225512 42966.71792623289 15953.66342322631
0.032010399536043406 39319.54019191567 14600.657627675695
0.03492043746337294 36644.22794463 13608.20821909483
0.03783047286719084 34595.083361792385 12848.061433112283
0.04074050827100873 32899.97733492528 12219.219626424969
0.043650543674826625 31350.403467839085 11644.292869762598
0.04656058160215616 29756.235317487724 11052.68379099353
0.049470619529485706 27984.782732061783 10395.121473239187
0.05238065745681524 26022.824982016326 9666.697833651653
0.05529069033712149 23955.028679392424 8898.872739941884
0.058200728264451024 21907.98104259511 8138.679004422714
0.06111076619178057 19993.95828378589 7427.838464557173
0.06472858352512122 17920.021555388645 6657.572459167699
0.06834639581143856 16270.648963536829 6044.975003728716
0.0719642131447792 15063.394304518893 5596.591782584755
0.07558203047811984 14225.813152745719 5285.522495614499
0.0791998478114605 13621.791392571356 5061.207635709624
0.08281766514480114 13104.33932806842 4869.040711316698
0.08643548247814178 12557.800218926726 4666.050342643998
0.09005329981148243 11918.998033106514 4428.765502211997
0.09367111714482307 11180.738875394178 4154.509984261828
0.09728893447816372 10378.148817394893 3856.338115255057
0.10090675181150437 9568.130986082231 3555.3947893141635
0.10452455905079841 8813.925033405883 3275.179584833204
0.10814237638413907 8169.868337724809 3035.8866553986595
0.11176019371747971 7662.476850798746 2847.3706355773984
0.11537801105082035 7282.779577917118 2706.2631927061043
0.11899582838416099 6996.550124060601 2599.924391358032
0.12261364571750163 6765.220405050068 2513.9830117726524
0.1262314630508423 6551.9217315517835 2434.740002601823
0.12984928038418292 6324.422814107089 2350.2171841586246
0.13346709771752358 6062.566550620322 2252.92469658749
0.13708491505086423 5765.623830015323 2142.5913173797358
0.14070273238420486 5449.097393012461 2024.9779283180785
0.14432054971754552 5134.278961223666 1907.9967431506523
0.14793836705088614 4840.618234340612 1798.8767396693106
0.1515561843842268 4582.456403755194 1702.947273157076
0.15517399162352086 4366.658043702829 1622.7598113061968
0.15879180895686149 4191.532186294422 1557.685947024672
0.16240962629020214 4048.6203675509123 1504.5827240399171
0.1660274436235428 3925.836536334679 1458.9587631055415
0.16964527105093002 3810.1898004090453 1415.9864884865176
0.17326307829022408 3690.7291454839838 1371.596724148891
0.17688088552951814 3561.6757110148724 1323.64079060979
0.18049871295690537 3423.3851894254094 1272.2520153846287
0.18411652019619942 3280.27088696846 1219.069728627318
0.18773434762358665 3138.0823382629637 1166.2307928221016
0.1913521548628807 3002.5865764912905 1115.8789761521243
0.19496998229026793 2878.8416807463827 1069.8935237485557
0.198587789529562 2769.854951930178 1029.3926718630205
0.20220561695694925 2675.48676609979 994.3241945570101
0.20582342419624328 2592.8816530440595 963.6271739706725
0.20944125162363053 2518.051030112089 935.8188799275517
0.2130590588629246 2447.18211507584 909.4829836664524
0.21667688629031182 2377.1495060178363 883.4576825719388
0.22029469352960587 2305.805977717265 856.9451205032506
0.2239125209569931 2232.4186273705022 829.672776337221
0.22753032819628716 2157.8613406081 801.9653506951364
0.23114813543558121 2084.0985818523336 774.5529573139769
0.23476596286296844 2013.226268778286 748.2147761343824
0.2383837701022625 1946.7407738828338 723.5068212354363
0.24200159752964973 1885.3731904020342 700.7006389404235
0.24561940476894378 1829.2238205847816 679.8339069679893
0.24923723219633104 1777.8323788845673 660.7352953932522
0.2528550394356251 1730.1889210080935 643.0294215835256
0.2564728668630123 1684.9556194018144 626.2192444939066
0.26009067410230635 1640.8977655289889 609.8459396493728
0.2637085015296936 1597.2430420154158 593.6223647475445
0.26732630876898766 1553.7455782755715 577.4571161480633
0.2709441361963749 1510.5581452270517 561.4069123279016
0.2745619434356689 1468.0743231817116 545.6182801448874
0.278179750674963 1426.8001848561346 530.2793392244803
0.28179757810235023 1387.2398685505307 515.5770301368224
0.2854153853416443 1349.7712542523466 501.65207666178867
0.28903321276903154 1314.5280110007266 488.55416641376513
0.2926510200083256 1281.353596598872 476.2252493484144
0.2962688474357128 1249.8975068686782 464.53475972955636
0.29988665467500686 1219.7836866677223 453.34320376447164
0.3035044821023941 1190.6966657885887 442.5332141069222
0.30712228934168817 1162.3579143100337 432.0012286661072
0.31074011676907537 1134.5396521750108 421.6627317963864
0.3143579240083694 1107.1617077360877 411.4878016629928
0.3179757514357567 1080.333528476409 401.5172389831272
0.32159355867505074 1054.2462367258313 391.82194613963384
0.3252113659143448 1029.0376281991382 382.4532197124814
0.32882919334173205 1004.7705313882904 373.43437221087436
0.33244700058102605 981.4784714968619 364.77792677788165
0.3360648280084133 959.1732916947087 356.488204721005
0.33968263524770737 937.8020955695852 348.5455617662638
0.3433004626750946 917.2358686401103 340.9021224696106
0.3469182901024818 897.3220536669313 333.5011192490445
0.35053607715368273 877.9458234061964 326.29995727311086
0.35415390458106993 859.0500835448564 319.2772932917605
0.3577717320084572 840.6093420111857 312.4238186138705
0.36138955943584444 822.60785303007 305.73347052475793
0.3650073464870453 805.0472743397642 299.20699967047665
0.3686251739144325 787.9623328336924 292.8573223574465
0.37224300134181976 771.4029400803246 286.7029864508672
0.3758607883930206 755.3938355011499 280.7530478518495
0.37947861582040787 739.9154286692914 275.00049778286444
0.3830964432477951 724.9289121223084 269.43066207492177
0.3867142706751823 710.4034513370322 264.03221144553834
0.3903320577263832 696.3155620164538 258.7963278272303
0.39394988515377044 682.6288357952247 253.70954836120737
0.3975677125811577 669.2943274235248 248.75378633705992
0.40118554000854495 656.27560292526 243.91522866552188
0.4048033270597458 643.5656825982207 239.19150776453893
0.408421154487133 631.1767440564981 234.58707437574955
0.41203898191452026 619.1125583704182 230.10333366308785
0.4156568093419075 607.3628481007793 225.73646300758688
0.4192745963931084 595.920468435362 221.48380976518138
0.42289242382049563 584.7910029597055 217.34746480982756
0.4405129549384117 534.7602248434607 198.75303270494902
0.5498958795547485 326.2469385129012 121.2564277062891
0.6874961461544037 196.0236868654745 72.8566909895803
0.859528093957901 116.52844405905755 43.31063070389224
1.0746075166225433 68.60765300066335 25.49977142641089
1.3435062154054642 40.04435525124467 14.883523399249542
1.6796913442611694 23.189176018531434 8.618869756917878
2.099999853658676 13.332915488509105 4.955533391580871
Loading