Skip to content

Commit

Permalink
Merge pull request #15 from JaimeRZP/band_powers
Browse files Browse the repository at this point in the history
Band powers
  • Loading branch information
JaimeRZP authored Nov 4, 2024
2 parents e16822e + e0d3e39 commit 37fe76d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/theory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function Theory(cosmology::Cosmology,
dz = get(Nuisances, string(name, "_", "dz"), 0.0)
tracer = NumberCountsTracer(cosmology, zs .+ dz, nz;
b=b, res=res_gc,
nz_interpolation=int_gc)
nz_interpolation=int_gc,
smooth=true)
elseif t_type == "galaxy_shear"
zs_mean, nz_mean = files[string("nz_", name)]
m = get(Nuisances, string(name, "_", "m"), 0.0)
Expand Down Expand Up @@ -57,7 +58,9 @@ function Theory(cosmology::Cosmology,
ls = files[string("ls_", name1, "_", name2)]
tracer1 = tracers[name1]
tracer2 = tracers[name2]
cls[idx[i]+1:idx[i+1]] = angularCℓs(cosmology, tracer1, tracer2, ls)
lss = [[i for i in l-3:l+3] for l in ls]
clss = [mean(angularCℓs(cosmology, tracer1, tracer2, _lls)) for _lls in lss]
cls[idx[i]+1:idx[i+1]] = clss
end

return cls
Expand Down
23 changes: 22 additions & 1 deletion src/tracers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Returns:
- `NumberCountsTracer::NumberCountsTracer` : Number counts tracer structure.
"""
NumberCountsTracer(cosmo::Cosmology, z_n, nz;
b=1.0, res=1000, nz_interpolation="linear") = begin
b=1.0, res=1000, nz_interpolation="linear", smooth=false) = begin
z_w, nz_w = nz_interpolate(z_n, nz, res;
mode=nz_interpolation)
nz_norm = integrate(z_w, nz_w, SimpsonEven())
Expand All @@ -37,6 +37,9 @@ NumberCountsTracer(cosmo::Cosmology, z_n, nz;
hz = Hmpc(cosmo, z_w)

w_arr = @. (nz_w*hz/nz_norm)
if smooth
w_arr = smooth_w_neighbors(w_arr)
end
wint = linear_interpolation(chi, b .* w_arr, extrapolation_bc=Line())
F::Function =-> 1
NumberCountsTracer(wint, F)
Expand Down Expand Up @@ -175,3 +178,21 @@ function nz_interpolate(z, nz, res; mode="linear")
return z, nz
end
end

function smooth_w_neighbors(arr::Vector{T}, k::Int = 5) where T
N = length(arr)
neighbors = Vector{}(undef, N) # Create an array to hold neighbor arrays

half_k = div(k, 2) # This is 2 if k=5, so we look at two neighbors on each side

for i in 1:N
# Define the range around the current element, clamping to avoid out-of-bounds
start_idx = max(1, i - half_k)
end_idx = min(N, i + half_k)

# Collect neighbors and assign to the current position
neighbors[i] = mean(arr[start_idx:end_idx])
end

return neighbors
end
Binary file modified test/test_output.npz
Binary file not shown.

0 comments on commit 37fe76d

Please sign in to comment.