Skip to content

Commit

Permalink
no control flow IA
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeRZP committed Nov 20, 2024
1 parent 2c4f3ab commit ba95c32
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 41 deletions.
8 changes: 5 additions & 3 deletions src/theory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ function Theory(cosmology::Cosmology,
elseif t_type == "galaxy_shear"
zs_mean, nz_mean = files[string("nz_", name)]
m = get(Nuisances, string(name, "_", "m"), 0.0)
IA_params = [get(Nuisances, "A_IA", 0.0),
get(Nuisances, "alpha_IA", 0.0)]
A_IA = get(Nuisances, "A_IA", 0.0)
alpha_IA = get(Nuisances, "alpha_IA", 0.0)
nz = get(Nuisances, string(name, "_", "nz"), nz_mean)
zs = get(Nuisances, string(name, "_", "zs"), zs_mean)
tracer = WeakLensingTracer(cosmology, zs, nz;
m=m, IA_params=IA_params)
m=m,
A_IA=A_IA,
alpha_IA=alpha_IA)

elseif t_type == "cmb_convergence"
tracer = CMBLensingTracer(cosmology)
Expand Down
15 changes: 7 additions & 8 deletions src/tracers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct WeakLensingTracer <: Tracer
end

WeakLensingTracer(cosmo::Cosmology, z, nz;
IA_params = [0.0, 0.0], m=0.0) = begin
A_IA=0.0, alpha_IA=0.0, m=0.0) = begin
sel = @. (z > 0.0)
z = z[sel]
nz = nz[sel]
Expand All @@ -79,15 +79,14 @@ WeakLensingTracer(cosmo::Cosmology, z, nz;
lens_prefac = 1.5*cosmo.cpar.Ωm*H0^2
chi[1] = 0.0
w_arr = @. w_arr * chi * lens_prefac * (1+z) / nz_norm
if IA_params != [0.0, 0.0]
hz = Hmpc(cosmo, z)
As = get_IA(cosmo, z, IA_params)
corr = @. As * (nz * hz / nz_norm)
w_arr = @. w_arr - corr
end
# IA correction
hz = Hmpc(cosmo, z)
As = @. A_IA*((1 + z)/1.62)^alpha_IA * (0.0134 * cosmo.cpar.Ωm / cosmo.Dz(z))
corr = @. As * (nz * hz / nz_norm)
w_arr_ia = @. w_arr - corr
# Interpolate
b = m+1.0
wint = linear_interpolation(chi, b.*w_arr, extrapolation_bc=0.0)
wint = linear_interpolation(chi, b.*w_arr_ia, extrapolation_bc=0.0)
F::Function =-> @.(sqrt((ℓ+2)*(ℓ+1)**(ℓ-1))/(ℓ+0.5)^2)
WeakLensingTracer(wint, F)
end
Expand Down
45 changes: 15 additions & 30 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ if test_main
z = Vector(range(0.01, stop=2., length=1000))
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
tg = NumberCountsTracer(cosmo_EisHu, z, nz; b=1.0)
ts = WeakLensingTracer(cosmo_EisHu, z, nz;
m=0.0,
IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo_EisHu, z, nz)
tk = CMBLensingTracer(cosmo_EisHu)
Cℓ_gg = angularCℓs(cosmo_EisHu, tg, tg, ℓs)
Cℓ_gs = angularCℓs(cosmo_EisHu, tg, ts, ℓs)
Expand Down Expand Up @@ -223,9 +221,7 @@ if test_main
z = Vector(range(0.01, stop=2., length=1000))
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
tg = NumberCountsTracer(cosmo_EisHu, z, nz; b=1.0)
ts = WeakLensingTracer(cosmo_EisHu, z, nz;
m=0.0,
IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo_EisHu, z, nz)
tk = CMBLensingTracer(cosmo_EisHu)
Cℓ_gg = angularCℓs(cosmo_EisHu_nonlin, tg, tg, ℓs)
Cℓ_gs = angularCℓs(cosmo_EisHu_nonlin, tg, ts, ℓs)
Expand Down Expand Up @@ -265,9 +261,7 @@ if test_main
z = Vector(range(0.01, stop=2., length=1000))
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
tg = NumberCountsTracer(cosmo_emul, z, nz; b=1.0)
ts = WeakLensingTracer(cosmo_emul, z, nz;
m=0.0,
IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo_emul, z, nz)
tk = CMBLensingTracer(cosmo_emul)
Cℓ_gg = angularCℓs(cosmo_emul, tg, tg, ℓs)
Cℓ_gs = angularCℓs(cosmo_emul, tg, ts, ℓs)
Expand Down Expand Up @@ -306,9 +300,7 @@ if test_main
z = Vector(range(0.01, stop=2., length=1000))
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
tg = NumberCountsTracer(cosmo_EisHu_nonlin, z, nz; b=1.0)
ts = WeakLensingTracer(cosmo_EisHu_nonlin, z, nz;
m=0.0,
IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo_EisHu_nonlin, z, nz)
tk = CMBLensingTracer(cosmo_EisHu_nonlin)
Cℓ_gg = angularCℓs(cosmo_EisHu_nonlin, tg, tg, ℓs)
Cℓ_gs = angularCℓs(cosmo_EisHu_nonlin, tg, ts, ℓs)
Expand Down Expand Up @@ -348,9 +340,7 @@ if test_main
z = Vector(range(0.01, stop=2., length=1000))
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
tg = NumberCountsTracer(cosmo_emul_nonlin, z, nz; b=1.0)
ts = WeakLensingTracer(cosmo_emul_nonlin, z, nz;
m=0.0,
IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo_emul_nonlin, z, nz)
tk = CMBLensingTracer(cosmo_emul_nonlin)
Cℓ_gg = angularCℓs(cosmo_emul_nonlin, tg, tg, ℓs)
Cℓ_gs = angularCℓs(cosmo_emul_nonlin, tg, ts, ℓs)
Expand Down Expand Up @@ -572,9 +562,7 @@ if test_main
z = Vector(range(0.01, stop=2., length=1000))
nz = Vector(@. exp(-0.5*((z-0.5)/0.05)^2))
tg = NumberCountsTracer(cosmo, z, nz; b=1.0)
ts = WeakLensingTracer(cosmo, z, nz;
m=0.0,
IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo, z, nz)
Cℓ_gs = angularCℓs(cosmo, tg, ts, ℓs)
return Cℓ_gs
end
Expand All @@ -584,9 +572,7 @@ if test_main
nz=700, nz_t=700, nz_pk=700)
z = Vector(range(0.01, stop=2., length=1000))
nz = Vector(@. exp(-0.5*((z-0.5)/0.05)^2))
ts = WeakLensingTracer(cosmo, z, nz;
m=0.0,
IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo, z, nz)
Cℓ_ss = angularCℓs(cosmo, ts, ts, ℓs)
return Cℓ_ss
end
Expand All @@ -596,9 +582,7 @@ if test_main
nz=500, nz_t=500, nz_pk=700)
z = range(0.01, stop=2., length=2000)
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
ts = WeakLensingTracer(cosmo, z, nz;
m=0.0,
IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo, z, nz)
tk = CMBLensingTracer(cosmo)
Cℓ_sk = angularCℓs(cosmo, ts, tk, ℓs)
return Cℓ_sk
Expand Down Expand Up @@ -671,8 +655,9 @@ if test_main
z = Vector(range(0.01, stop=2., length=1024))
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
tg_b = NumberCountsTracer(cosmo_EisHu_nonlin, z, nz; b=2.0)
ts_m = WeakLensingTracer(cosmo_EisHu_nonlin, z, nz; m=1.0, IA_params=[0.0, 0.0])
ts_IA = WeakLensingTracer(cosmo_EisHu_nonlin, z, nz; m=0.0, IA_params=[0.1, 0.1])
ts_m = WeakLensingTracer(cosmo_EisHu_nonlin, z, nz; m=1.0)
ts_IA = WeakLensingTracer(cosmo_EisHu_nonlin, z, nz;
m=0.0, A_IA=0.1, alpha_IA=0.1)
Cℓ_gg_b = angularCℓs(cosmo_EisHu_nonlin, tg_b, tg_b, ℓs)
Cℓ_ss_m = angularCℓs(cosmo_EisHu_nonlin, ts_m, ts_m, ℓs)
Cℓ_ss_IA = angularCℓs(cosmo_EisHu_nonlin, ts_IA, ts_IA, ℓs)
Expand Down Expand Up @@ -707,7 +692,7 @@ if test_main
cosmo.settings.cosmo_type = typeof(p)
z = Vector(range(0.01, stop=2., length=2000)) .- p
nz = Vector(@. exp(-0.5*((z-0.5)/0.05)^2))
ts = WeakLensingTracer(cosmo, z, nz; m=p, IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo, z, nz; m=p)
ℓs = [10.0, 30.0, 100.0, 300.0]
Cℓ_ss = angularCℓs(cosmo, ts, ts, ℓs)
return Cℓ_ss
Expand All @@ -718,7 +703,7 @@ if test_main
cosmo.settings.cosmo_type = typeof(p)
z = range(0.01, stop=2., length=2000)
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
ts = WeakLensingTracer(cosmo, z, nz; m=p, IA_params=[0.0, 0.0])
ts = WeakLensingTracer(cosmo, z, nz; m=p)
ℓs = [10.0, 30.0, 100.0, 300.0]
Cℓ_sk = angularCℓs(cosmo, ts, ts, ℓs)
return Cℓ_sk
Expand All @@ -729,7 +714,7 @@ if test_main
cosmo.settings.cosmo_type = typeof(p)
z = range(0.01, stop=2., length=2000)
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
ts = WeakLensingTracer(cosmo, z, nz; m=2, IA_params=[p, 0.1])
ts = WeakLensingTracer(cosmo, z, nz; m=2, A_IA=p, alpha_IA=0.1)
ℓs = [10.0, 30.0, 100.0, 300.0]
Cℓ_ss = angularCℓs(cosmo, ts, ts, ℓs)
return Cℓ_ss
Expand All @@ -740,7 +725,7 @@ if test_main
cosmo.settings.cosmo_type = typeof(p)
z = range(0.01, stop=2., length=2000)
nz = @. exp(-0.5*((z-0.5)/0.05)^2)
ts = WeakLensingTracer(cosmo, z, nz; m=2, IA_params=[0.3, p])
ts = WeakLensingTracer(cosmo, z, nz; m=2, A_IA=0.3, alpha_IA=p)
ℓs = [10.0, 30.0, 100.0, 300.0]
Cℓ_ss = angularCℓs(cosmo, ts, ts, ℓs)
return Cℓ_ss
Expand Down
Binary file modified test/test_output.npz
Binary file not shown.

0 comments on commit ba95c32

Please sign in to comment.