Skip to content
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

better res treatment #13

Closed
wants to merge 4 commits into from
Closed
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
26 changes: 15 additions & 11 deletions src/tracers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ Kwargs:
Returns:
- `NumberCountsTracer::NumberCountsTracer` : Number counts tracer structure.
"""
NumberCountsTracer(cosmo::Cosmology, z_n, nz; b=1.0, res=1000) = begin
nz_int = linear_interpolation(z_n, nz, extrapolation_bc=0)
z_w = range(0.00001, stop=z_n[end], length=res)
nz_w = nz_int(z_w)
NumberCountsTracer(cosmo::Cosmology, z_n, nz; b=1.0) = begin
z_w, nz_w = nz_interpolate(z_n, nz)
nz_norm = integrate(z_w, nz_w, SimpsonEven())

chi = cosmo.chi(z_w)
Expand Down Expand Up @@ -62,15 +60,11 @@ struct WeakLensingTracer <: Tracer
end

WeakLensingTracer(cosmo::Cosmology, z_n, nz;
IA_params = [0.0, 0.0], m=0.0, res=350, kwargs...) = begin
nz_int = linear_interpolation(z_n, nz, extrapolation_bc=0)
IA_params = [0.0, 0.0], m=0.0, kwargs...) = begin
cosmo_type = cosmo.settings.cosmo_type
z_w = range(0.00001, stop=z_n[end], length=res)
dz_w = (z_w[end]-z_w[1])/res
nz_w = nz_int(z_w)
z_w, nz_w = nz_interpolate(z_n, nz)
res = length(z_w)
chi = cosmo.chi(z_w)

#nz_norm = sum(0.5 .* (nz_w[1:res-1] .+ nz_w[2:res]) .* dz_w)
nz_norm = integrate(z_w, nz_w, SimpsonEven())

# Calculate chis at which to precalculate the lensing kernel
Expand Down Expand Up @@ -156,4 +150,14 @@ function get_IA(cosmo::Cosmology, zs, IA_params)
A_IA = IA_params[1]
alpha_IA = IA_params[2]
return @. A_IA*((1 + zs)/1.62)^alpha_IA * (0.0134 * cosmo.cpar.Ωm / cosmo.Dz(zs))
end

function nz_interpolate(z, nz)
dz = mean(z[2:end] - z[1:end-1])
z_range = z[1]:dz:z[end]
nz_int = cubic_spline_interpolation(z_range, nz)
dzz = dz/10
zz_range = z[1]:dzz:z[end]
nzz = nz_int(zz_range)
return zz_range, nzz
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ if test_main
cosmo.settings.cosmo_type = typeof(p)
z = Vector(range(0., stop=2., length=1000)) .- p
nz = Vector(@. exp(-0.5*((z-0.5)/0.05)^2))
tg = NumberCountsTracer(cosmo, z, nz; b=1, res=350)
tg = NumberCountsTracer(cosmo, z, nz; b=1)
ℓs = [10.0, 30.0, 100.0, 300.0]
Cℓ_gg = angularCℓs(cosmo, tg, tg, ℓs)
return Cℓ_gg
Expand Down
Binary file modified test/test_output.npz
Binary file not shown.
Loading