Skip to content

Commit

Permalink
Merge pull request #9 from JaimeRZP/make_data
Browse files Browse the repository at this point in the history
Make data bug
  • Loading branch information
JaimeRZP authored Feb 27, 2024
2 parents b1a8e73 + db4b519 commit 7ee8338
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LimberJack"
uuid = "6b86205d-155a-4b14-b82d-b6a149ea78f2"
authors = ["Jaime Ruiz-Zapatero <[email protected]>", "David Alonso", "Andrina Nicola", "Arrykrishna Mootoovaloo", "James Sullivan", "Marco Bonic"]
version = "0.1.3"
version = "0.1.31"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand Down
1 change: 1 addition & 0 deletions Tutorial/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
LimberJack = "6b86205d-155a-4b14-b82d-b6a149ea78f2"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
60 changes: 24 additions & 36 deletions src/data_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ function _get_spin(sacc_file, tracer_name)
return spin
end

function _get_cl_name(s, t1, t2)
spin1 = _get_spin(s, t1)
spin2 = _get_spin(s, t2)
cl_name = string("cl_", spin1 , spin2)
if cl_name == "cl_e0"
cl_name = "cl_0e"
end
return cl_name
end

function _apply_scale_cuts(s, yaml_file)
indices = Vector{Int}([])
for cl in yaml_file["order"]
t1, t2 = cl["tracers"]
lmin, lmax = cl["ell_cuts"]
cl_name = cl["cl_name"]
cl_name = _get_cl_name(s, t1, t2)
ind = s.indices(cl_name, (t1, t2),
ell__gt=lmin, ell__lt=lmax)
append!(indices, pyconvert(Vector{Int}, ind))
Expand All @@ -39,34 +49,11 @@ function _apply_scale_cuts(s, yaml_file)
return s
end

function make_data(sacc_file, yaml_file; kwargs...)

"""
make_data(sacc_file, yaml_file)
Process `sacc` and `yaml` files into a `Meta` structure \
containing the instructions of how to compose the theory \
vector and a `npz` file with the neccesary redshift distributions \
of the tracers involved.
Arguments:
- `sacc_file` : sacc file
- `yaml_file` : yaml_file
kwargs=Dict(kwargs)
kwargs_keys = [string(i) for i in collect(keys(kwargs))]

Returns:
```
struct Instructions
names : names of tracers.
pairs : pairs of tracers to compute angular spectra for.
types : types of the tracers.
idx : positions of cls in theory vector.
data : data vector.
cov : covariance of the data.
inv_cov : inverse covariance of the data.
end
```
-files: npz file
"""
function make_data(sacc_file, yaml_file; nzs_path="")
#cut
s = _apply_scale_cuts(sacc_file, yaml_file)

Expand All @@ -77,7 +64,7 @@ function make_data(sacc_file, yaml_file; nzs_path="")
pairs = []
for cl in yaml_file["order"]
t1, t2 = cl["tracers"]
cl_name = cl["cl_name"]
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))
Expand All @@ -101,7 +88,7 @@ function make_data(sacc_file, yaml_file; nzs_path="")

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

# Initialize
files = Dict{String}{Vector}()
Expand All @@ -115,20 +102,21 @@ function make_data(sacc_file, yaml_file; nzs_path="")
# Load in nz's
for (name, tracer) in s.tracers.items()
if string(name) in names
if nzs_path == ""
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
else
nzs = npzread(string(nzs_path, "nz_", name, ".npz"))
z = nzs["z"]
dndz = nzs["dndz"]
merge!(files, Dict(string("nz_", name)=>[z, dndz]))
end
end
end

return instructions, files
end
end

0 comments on commit 7ee8338

Please sign in to comment.