Skip to content

Commit

Permalink
gg
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimerzp committed May 10, 2024
1 parent 2419042 commit 22bb96b
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/data_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,74 @@ function make_data(sacc_file, yaml_file; kwargs...)
end
end

return instructions, files
end

function make_data(s; kwargs...)

kwargs=Dict(kwargs)
kwargs_keys = [string(i) for i in collect(keys(kwargs))]

#build quantities of interest
cls = Vector{Float64}([])
ls = []
indices = Vector{Int}([])
pairs = []
for cl in s.get_tracer_combinations()
t1, t2 = cl
cl_name = _get_cl_name(s, t1, t2)
l, c_ell, ind = s.get_ell_cl(cl_name, string(t1), string(t2),
return_cov=false, return_ind=true)
append!(indices, pyconvert(Vector{Int}, ind))
append!(cls, pyconvert(Vector{Float64}, c_ell))
push!(ls, pyconvert(Vector{Float64}, l))
push!(pairs, pyconvert(Vector{String}, [t1, t2]))
end

names = unique(vcat(pairs...))
cov = pyconvert(Vector{Vector{Float64}}, s.covariance.dense)
cov = permutedims(hcat(cov...))[indices.+1, :][:, indices.+1]
w, v = eigen(cov)
cov = v * (diagm(abs.(w)) * v')
cov = tril(cov) + triu(cov', 1)
cov = Hermitian(cov)
inv_cov = inv(cov)
lengths = [length(l) for l in ls]
lengths = vcat([0], lengths)
idx = cumsum(lengths)
types = [_get_type(s, name) for name in names]

# build struct
instructions = Instructions(names, pairs, types, idx,
cls, cov, inv_cov)

# Initialize
files = Dict{String}{Vector}()
# Load in l's
for (pair, l) in zip(pairs, ls)
t1, t2 = pair
println(t1, " ", t2, " ", length(l))
merge!(files, Dict(string("ls_", t1, "_", t2)=> l))
end

# Load in nz's
for (name, tracer) in s.tracers.items()
if string(name) in names
if string("nz_", name) in kwargs_keys
println(string("using custom nz for ", string("nz_", name)))
nzs = kwargs[Symbol("nz_", name)]
z= pyconvert(Vector{Float64}, nzs["z"])
nz=pyconvert(Vector{Float64}, nzs["dndz"])
merge!(files, Dict(string("nz_", name)=>[z, nz]))
else
if string(tracer.quantity) != "cmb_convergence"
z=pyconvert(Vector{Float64}, tracer.z)
nz=pyconvert(Vector{Float64}, tracer.nz)
merge!(files, Dict(string("nz_", name)=>[z, nz]))
end
end
end
end

return instructions, files
end

0 comments on commit 22bb96b

Please sign in to comment.