Skip to content

Commit

Permalink
trying something
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeRZP committed Oct 17, 2024
1 parent 6d6f541 commit 90c19bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
14 changes: 9 additions & 5 deletions src/theory.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function Theory(cosmology::Cosmology,
names, types, pairs,
idx, files;
Nuisances=Dict())
Nuisances=Dict(),
res_wl=350, res_gc=1000)

nui_type = eltype(valtype(Nuisances))
if !(nui_type <: Float64) & (nui_type != Any)
Expand All @@ -22,7 +23,7 @@ function Theory(cosmology::Cosmology,
zs = get(Nuisances, string(name, "_", "zs"), zs_mean)
dz = get(Nuisances, string(name, "_", "dz"), 0.0)
tracer = NumberCountsTracer(cosmology, zs .+ dz, nz;
b=b)
b=b, res_gc=res_gc)
elseif t_type == "galaxy_shear"
zs_mean, nz_mean = files[string("nz_", name)]
m = get(Nuisances, string(name, "_", "m"), 0.0)
Expand All @@ -32,7 +33,8 @@ function Theory(cosmology::Cosmology,
zs = get(Nuisances, string(name, "_", "zs"), zs_mean)
dz = get(Nuisances, string(name, "_", "dz"), 0.0)
tracer = WeakLensingTracer(cosmology, zs .+ dz, nz;
m=m, IA_params=IA_params)
m=m, IA_params=IA_params,
res=res_wl)

elseif t_type == "cmb_convergence"
tracer = CMBLensingTracer(cosmology)
Expand Down Expand Up @@ -90,7 +92,8 @@ end
"""
function Theory(cosmology::Cosmology,
instructions::Instructions, files;
Nuisances=Dict())
Nuisances=Dict(),
kwargs...)

names = instructions.names
types = instructions.types
Expand All @@ -100,5 +103,6 @@ function Theory(cosmology::Cosmology,
return Theory(cosmology::Cosmology,
names, types, pairs,
idx, files;
Nuisances=Nuisances)
Nuisances=Nuisances,
kwargs...)
end
26 changes: 19 additions & 7 deletions src/tracers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ 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)

z_w, nz_w = nz_interpolate(z_n, nz, res)
nz_norm = integrate(z_w, nz_w, SimpsonEven())

chi = cosmo.chi(z_w)
Expand Down Expand Up @@ -63,11 +62,9 @@ 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)

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)
chi = cosmo.chi(z_w)

#nz_norm = sum(0.5 .* (nz_w[1:res-1] .+ nz_w[2:res]) .* dz_w)
Expand Down Expand Up @@ -156,4 +153,19 @@ 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, res=nothing)
dz = mean(z[2:end] - z[1:end-1])
z_range = z[1]:dz:z[end]
nz_int = cubic_spline_interpolation(z_range, nz)
if res==nothing
dzz = dz/10
else
L = z[end] - z[1]
dzz = L/res
end
zz_range = z[1]:dzz:z[end]
nzz = nz_int(zz_range)
return zz_range, nzz
end

0 comments on commit 90c19bc

Please sign in to comment.