Skip to content

Commit

Permalink
v3 preparation (#1087)
Browse files Browse the repository at this point in the history
* Removed v2 vestiges. Now in v3 mode.
  • Loading branch information
damonge committed Jun 7, 2023
1 parent 17a0e5a commit d421ca0
Show file tree
Hide file tree
Showing 109 changed files with 363 additions and 3,696 deletions.
4 changes: 2 additions & 2 deletions benchmarks/test_cib.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def test_cibcl():
h=0.7,
n_s=0.9645,
A_s=2.02E-9,
Neff=3.046)
mdef = ccl.halos.MassDef200m()
Neff=3.046, T_CMB=2.725)
mdef = ccl.halos.MassDef200m
cM = ccl.halos.ConcentrationDuffy08(mass_def=mdef)
nM = ccl.halos.MassFuncTinker10(mass_def=mdef, norm_all_z=True)
bM = ccl.halos.HaloBiasTinker10(mass_def=mdef)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/test_correlation_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_correlation_3d(model):
h=0.7,
sigma8=0.8,
n_s=0.96,
Neff=3.046,
Neff=3.046, T_CMB=2.725,
mass_split='normal',
Omega_g=0,
Omega_k=1.0 - 0.25 - 0.05 - Omega_v[model],
Expand Down
16 changes: 7 additions & 9 deletions benchmarks/test_covariances.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import numpy as np
import pytest
import pyccl as ccl


Expand All @@ -13,11 +12,12 @@ def test_ssc_WL():
cosmo = ccl.Cosmology(Omega_c=0.25, Omega_b=0.05, h=h, n_s=0.97,
sigma8=0.8, m_nu=0.0)

mass_def = ccl.halos.MassDef200m()
mass_def = ccl.halos.MassDef200m
hmf = ccl.halos.MassFuncTinker10(mass_def=mass_def)
hbf = ccl.halos.HaloBiasTinker10(mass_def=mass_def)
con = ccl.halos.ConcentrationDuffy08(mass_def=mass_def)
nfw = ccl.halos.HaloProfileNFW(concentration=con, fourier_analytic=True)
nfw = ccl.halos.HaloProfileNFW(mass_def=mass_def, concentration=con,
fourier_analytic=True)
hmc = ccl.halos.HMCalculator(mass_function=hmf, halo_bias=hbf,
mass_def=mass_def)

Expand All @@ -30,12 +30,10 @@ def test_ssc_WL():
a = np.linspace(1/(1+6), 1, n_z)
k = np.geomspace(k_min, k_max, n_k)

with pytest.warns(ccl.CCLDeprecationWarning): # TODO: remove normprof v3
tk3D = ccl.halos.halomod_Tk3D_SSC(cosmo=cosmo, hmc=hmc,
prof=nfw, prof2=nfw, prof12_2pt=None,
lk_arr=np.log(k), a_arr=a,
use_log=True,
normprof1=True, normprof2=True)
tk3D = ccl.halos.halomod_Tk3D_SSC(cosmo=cosmo, hmc=hmc,
prof=nfw, prof2=nfw, prof12_2pt=None,
lk_arr=np.log(k), a_arr=a,
use_log=True)

z, nofz = np.loadtxt(os.path.join(data_dir, "ssc_WL_nofz.txt"),
unpack=True)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/test_eh.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_eh(transfer, fname):
h=0.7,
sigma8=0.8,
n_s=0.96,
Neff=0,
Neff=0, T_CMB=2.725,
m_nu=0.0,
w0=-1.0,
wa=0.0,
Expand Down
43 changes: 0 additions & 43 deletions benchmarks/test_growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def read_growth_allz_benchmark_file():

# Split into redshift column and growth(z) columns
z = dat[0]
# gfac = np.column_stack((dat[1:], dat_MG[1:]))
gfac = dat[1:]

return z, gfac
Expand Down Expand Up @@ -120,45 +119,3 @@ def test_growth_highz_model(i):
def test_growth_allz_model(i):
compare_growth(z_allz, gfac_allz[i], Omega_v_vals[i], w0_vals[i],
wa_vals[i], mu0_vals[i], Sig0_vals[i])


def test_growth_mg():
"""
Compare the modified growth function computed by CCL against the exact
result for a particular modification of the growth rate.
"""
# Define differential growth rate arrays
nz_mg = 128
z_mg = np.zeros(nz_mg)
df_mg = np.zeros(nz_mg)
for i in range(0, nz_mg):
z_mg[i] = 4. * (i + 0.0) / (nz_mg - 1.)
df_mg[i] = 0.1 / (1. + z_mg[i])

# Define two test cosmologies, without and with modified growth
# respectively
cosmo1 = ccl.Cosmology(
Omega_c=0.25, Omega_b=0.05, Omega_k=0., Neff=0., m_nu=0.,
w0=-1., wa=0., h=0.7, A_s=2.1e-9, n_s=0.96)
cosmo2 = ccl.Cosmology(
Omega_c=0.25, Omega_b=0.05, Omega_k=0., Neff=0., m_nu=0.,
w0=-1., wa=0., h=0.7, A_s=2.1e-9, n_s=0.96,
z_mg=z_mg, df_mg=df_mg)

# We have included a growth modification \delta f = K*a, with K==0.1
# (arbitrarily). This case has an analytic solution, given by
# D(a) = D_0(a)*exp(K*(a-1)). Here we compare the growth computed by CCL
# with the analytic solution.
a = 1. / (1. + z_mg)

d1 = ccl.growth_factor(cosmo1, a)
d2 = ccl.growth_factor(cosmo2, a)
f1 = ccl.growth_rate(cosmo1, a)
f2 = ccl.growth_rate(cosmo2, a)

f2r = f1 + 0.1*a
d2r = d1 * np.exp(0.1*(a-1.))

# Check that ratio of calculated and analytic results is within tolerance
assert np.allclose(d2r, d2, atol=0, rtol=GROWTH_TOLERANCE)
assert np.allclose(f2r, f2, atol=0, rtol=GROWTH_TOLERANCE)
10 changes: 3 additions & 7 deletions benchmarks/test_halomod.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,22 @@ def test_halomod(model):
hbf = ccl.halos.HaloBiasSheth99(mass_def=mass_def,
mass_def_strict=False)
cM = ccl.halos.ConcentrationDuffy08(mass_def=mass_def)
prf = ccl.halos.HaloProfileNFW(concentration=cM)
prf = ccl.halos.HaloProfileNFW(mass_def=mass_def, concentration=cM)
hmc = ccl.halos.HMCalculator(mass_function=hmf, halo_bias=hbf,
mass_def=mass_def)

z = 0.
k = data_z0[:, 0] * cosmo['h']
pk = data_z0[:, -1] / (cosmo['h']**3)
with pytest.warns(ccl.CCLDeprecationWarning): # TODO: remove normprof v3
pk_ccl = ccl.halos.halomod_power_spectrum(cosmo, hmc, k, 1./(1+z), prf,
normprof1=True)
pk_ccl = ccl.halos.halomod_power_spectrum(cosmo, hmc, k, 1./(1+z), prf)
tol = pk * HALOMOD_TOLERANCE
err = np.abs(pk_ccl - pk)
assert np.all(err <= tol)

z = 1.
k = data_z1[:, 0] * cosmo['h']
pk = data_z1[:, -1] / (cosmo['h']**3)
with pytest.warns(ccl.CCLDeprecationWarning): # TODO: remove normprof v3
pk_ccl = ccl.halos.halomod_power_spectrum(cosmo, hmc, k, 1./(1+z), prf,
normprof1=True)
pk_ccl = ccl.halos.halomod_power_spectrum(cosmo, hmc, k, 1./(1+z), prf)
tol = pk * HALOMOD_TOLERANCE
err = np.abs(pk_ccl - pk)
assert np.all(err <= tol)
34 changes: 19 additions & 15 deletions benchmarks/test_haloprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
wa=0,
m_nu=0,
mass_split='normal',
Neff=3.046,
Neff=3.046, T_CMB=2.725,
Omega_k=0,
transfer_function='eisenstein_hu',
mass_function='shethtormen')
transfer_function='eisenstein_hu')


def test_profile_Hernquist():
Expand All @@ -34,7 +33,8 @@ def test_profile_Hernquist():

mdef = ccl.halos.MassDef(mDelta, 'matter')
c = ccl.halos.ConcentrationConstant(c=concentration, mass_def=mdef)
p = ccl.halos.HaloProfileHernquist(concentration=c, truncated=False)
p = ccl.halos.HaloProfileHernquist(mass_def=mdef, concentration=c,
truncated=False)

prof = p.real(COSMO, r, halomass, a)

Expand All @@ -57,7 +57,8 @@ def test_profile_Einasto():

mdef = ccl.halos.MassDef(mDelta, 'matter')
c = ccl.halos.ConcentrationConstant(c=concentration, mass_def=mdef)
p = ccl.halos.HaloProfileEinasto(concentration=c, truncated=False)
p = ccl.halos.HaloProfileEinasto(mass_def=mdef, concentration=c,
truncated=False)

prof = p.real(COSMO, r, halomass, a)

Expand All @@ -80,7 +81,8 @@ def test_profile_NFW():

mdef = ccl.halos.MassDef(mDelta, 'matter')
c = ccl.halos.ConcentrationConstant(c=concentration, mass_def=mdef)
p = ccl.halos.HaloProfileNFW(concentration=c, truncated=False)
p = ccl.halos.HaloProfileNFW(mass_def=mdef, concentration=c,
truncated=False)

prof = p.real(COSMO, r, halomass, a)

Expand Down Expand Up @@ -108,18 +110,21 @@ def test_haloprofile(model):
c = ccl.halos.ConcentrationConstant(c=concentration, mass_def=mdef)

if model == 'nfw':
p = ccl.halos.HaloProfileNFW(concentration=c, truncated=False)
p = ccl.halos.HaloProfileNFW(mass_def=mdef, concentration=c,
truncated=False)
prof = p.real(COSMO, r, halomass, a)
elif model == 'projected_nfw':
p = ccl.halos.HaloProfileNFW(concentration=c, truncated=False,
projected_analytic=True)
p = ccl.halos.HaloProfileNFW(mass_def=mdef, concentration=c,
truncated=False, projected_analytic=True)
prof = p.projected(COSMO, r, halomass, a)
elif model == 'einasto':
mdef = ccl.halos.MassDef(halomassdef, 'matter')
p = ccl.halos.HaloProfileEinasto(concentration=c, truncated=False)
p = ccl.halos.HaloProfileEinasto(mass_def=mdef, concentration=c,
truncated=False)
prof = p.real(COSMO, r, halomass, a)
elif model == 'hernquist':
p = ccl.halos.HaloProfileHernquist(concentration=c, truncated=False)
p = ccl.halos.HaloProfileHernquist(mass_def=mdef, concentration=c,
truncated=False)
prof = p.real(COSMO, r, halomass, a)

tol = np.clip(np.abs(HALOPROFILE_TOLERANCE * data[:, 1]), 1e-12, np.inf)
Expand Down Expand Up @@ -148,10 +153,9 @@ def test_weak_lensing_functions():

mdef = ccl.halos.MassDef(mDelta, 'matter')
c = ccl.halos.ConcentrationConstant(c=concentration, mass_def=mdef)
p = ccl.halos.HaloProfileNFW(
concentration=c,
truncated=False, projected_analytic=True, cumul2d_analytic=True
)
p = ccl.halos.HaloProfileNFW(mass_def=mdef, concentration=c,
truncated=False, projected_analytic=True,
cumul2d_analytic=True)

kappa = p.convergence(COSMO, r_al, halomass,
a_lens=a_lens, a_source=a_source)
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/test_hmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def test_hmf_despali16():


def test_hmf_bocquet16():
hmd = ccl.halos.MassDef200c()
mf = ccl.halos.MassFuncBocquet16(mass_def=hmd)
mf = ccl.halos.MassFuncBocquet16(mass_def="200c")
d_hmf = np.loadtxt(os.path.join(dirdat, 'hmf_bocquet16.txt'),
unpack=True)
m = d_hmf[0]
Expand Down
8 changes: 3 additions & 5 deletions benchmarks/test_hod.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest
import pyccl as ccl


Expand Down Expand Up @@ -56,6 +55,7 @@ def _nz_2mrs(z):
hmc = ccl.halos.HMCalculator(mass_function=hmf, halo_bias=hbf,
mass_def=mass_def)
prf = ccl.halos.HaloProfileHOD(
mass_def=mass_def,
concentration=cm,
log10Mmin_0=np.log10(10.**log10Mcut/cosmo['h']),
siglnM_0=sigma_Ncen,
Expand All @@ -67,10 +67,8 @@ def _nz_2mrs(z):
prf2pt = ccl.halos.Profile2ptHOD()
# P(k)
a_arr, lk_arr, _ = cosmo.get_linear_power().get_spline_arrays()
with pytest.warns(ccl.CCLDeprecationWarning): # TODO: remove normprof v3
pk_hod = ccl.halos.halomod_Pk2D(cosmo, hmc, prf, prof_2pt=prf2pt,
lk_arr=lk_arr, a_arr=a_arr,
normprof1=True)
pk_hod = ccl.halos.halomod_Pk2D(cosmo, hmc, prf, prof_2pt=prf2pt,
lk_arr=lk_arr, a_arr=a_arr)
# C_ell
tr = ccl.NumberCountsTracer(cosmo, has_rsd=False, dndz=(z_arr, dndz),
bias=(z_arr, np.ones(len(dndz))))
Expand Down
27 changes: 10 additions & 17 deletions benchmarks/test_ia_profile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest
import pyccl as ccl


Expand Down Expand Up @@ -48,21 +47,15 @@ def test_satellite_shear_profile():
NFW = ccl.halos.HaloProfileNFW(concentration=cM, truncated=True,
fourier_analytic=True, mass_def='200m')

with pytest.warns(ccl.CCLDeprecationWarning):
pk_GI_1h = ccl.halos.halomod_Pk2D(cosmo, hmc, NFW,
normprof1=True,
normprof2=True,
prof2=sat_gamma_HOD,
get_2h=False,
lk_arr=np.log(k_arr),
a_arr=a_arr)
with pytest.warns(ccl.CCLDeprecationWarning):
pk_II_1h = ccl.halos.halomod_Pk2D(cosmo, hmc, sat_gamma_HOD,
normprof1=True,
normprof2=True,
get_2h=False,
lk_arr=np.log(k_arr),
a_arr=a_arr)
pk_GI_1h = ccl.halos.halomod_Pk2D(cosmo, hmc, NFW,
prof2=sat_gamma_HOD,
get_2h=False,
lk_arr=np.log(k_arr),
a_arr=a_arr)
pk_II_1h = ccl.halos.halomod_Pk2D(cosmo, hmc, sat_gamma_HOD,
get_2h=False,
lk_arr=np.log(k_arr),
a_arr=a_arr)

z_arr = np.linspace(0., 3., 256)
z0 = 0.1
Expand Down Expand Up @@ -90,5 +83,5 @@ def test_satellite_shear_profile():
sigma8=0.81, n_s=0.96, h=1.)
cosmo.compute_sigma()
Ns_M_mean = sat_gamma_HOD._Ns(mass_benchmark, 1.)
norm = Ns_M_mean / sat_gamma_HOD.get_normalization(cosmo, 1, hmc)
norm = Ns_M_mean / sat_gamma_HOD.get_normalization(cosmo, 1, hmc=hmc)
assert np.all(np.fabs(norm / norm_benchmark - 1) < 0.005)
8 changes: 4 additions & 4 deletions benchmarks/test_massdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
cs_200c_p = dc[7]
cs_200c_di = dc[8]

hmd_vir = ccl.halos.MassDefVir()
hmd_200m = ccl.halos.MassDef200m()
hmd_200c = ccl.halos.MassDef200c()
hmd_500c = ccl.halos.MassDef500c()
hmd_vir = ccl.halos.MassDefVir
hmd_200m = ccl.halos.MassDef200m
hmd_200c = ccl.halos.MassDef200c
hmd_500c = ccl.halos.MassDef500c


def test_mdef_get_radius():
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/test_power_nu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_power_nu(model):
h=0.7,
A_s=2.1e-9,
n_s=0.96,
Neff=3.046,
Neff=3.046, T_CMB=2.725,
Omega_k=0,
w0=w_0[model],
wa=w_a[model],
Expand Down
1 change: 1 addition & 0 deletions benchmarks/test_ptpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Set cosmology
COSMO = ccl.Cosmology(Omega_c=0.25, Omega_b=0.05,
h=0.7, sigma8=0.8, n_s=0.96,
T_CMB=2.725,
transfer_function='bbks')

# Redshifts
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/test_sz.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_szcl():
h=0.7,
n_s=0.9645,
A_s=2.02E-9,
Neff=3.046,
Neff=3.046, T_CMB=2.725,
transfer_function='boltzmann_class')
bm = np.loadtxt("benchmarks/data/sz_cl_P13_szpowerspectrum.txt",
unpack=True)
Expand Down
17 changes: 0 additions & 17 deletions pyccl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,4 @@
from . import halos
from . import nl_pt

from .bcm import * # deprecated
from .halomodel import * # deprecated
from .massfunction import * # deprecated
from .haloprofile import * # deprecated

from .cosmology import *


def __getattr__(name):
rename = {"core": "cosmology", "cls": "cells"}
if name in rename:
from .errors import CCLDeprecationWarning
import warnings
warnings.warn(f"Module {name} has been renamed to {rename[name]}.",
CCLDeprecationWarning)
name = rename[name]
return eval(name)
raise AttributeError(f"No module named {name}.")

0 comments on commit d421ca0

Please sign in to comment.