Skip to content

Commit

Permalink
Updating old and untested examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitenti committed Sep 24, 2024
1 parent 92138af commit e446981
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
18 changes: 11 additions & 7 deletions examples/des_y1_3x2pt/des_y1_cosmic_shear_TATT.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from firecrown.modeling_tools import ModelingTools
from firecrown.likelihood.likelihood import Likelihood
from firecrown.ccl_factory import CCLFactory

from firecrown.updatable import get_default_params_map
from firecrown.metadata_types import TracerNames, TRACER_NAMES_TOTAL

SACCFILE = os.path.expanduser(
os.path.expandvars(
Expand Down Expand Up @@ -121,11 +122,14 @@ def run_likelihood() -> None:
"src3_delta_z": 0.002,
}
)
# Prepare the cosmology object
params = ParamsMap(get_default_params_map(tools) | systematics_params)

# Apply the systematics parameters
likelihood.update(systematics_params)
likelihood.update(params)

# Prepare the cosmology object
tools.update(params)
tools.prepare()
ccl_cosmo = tools.get_ccl_cosmology()

Expand Down Expand Up @@ -180,11 +184,11 @@ def make_plot(ccl_cosmo, nz, pk_ii, pk_im, two_point_0, z):
import numpy as np # pylint: disable-msg=import-outside-toplevel
import matplotlib.pyplot as plt # pylint: disable-msg=import-outside-toplevel

ells = two_point_0.ells
cells_gg = two_point_0.cells[("shear", "shear")]
cells_gi = two_point_0.cells[("shear", "intrinsic_pt")]
cells_ii = two_point_0.cells[("intrinsic_pt", "intrinsic_pt")]
cells_total = two_point_0.cells["total"]
ells = two_point_0.ells_for_xi
cells_gg = two_point_0.cells[TracerNames("shear", "shear")]
cells_gi = two_point_0.cells[TracerNames("shear", "intrinsic_pt")]
cells_ii = two_point_0.cells[TracerNames("intrinsic_pt", "intrinsic_pt")]
cells_total = two_point_0.cells[TRACER_NAMES_TOTAL]
# pylint: enable=no-member
# Code that computes effect from IA using that Pk2D object
t_lens = ccl.WeakLensingTracer(ccl_cosmo, dndz=(z, nz))
Expand Down
17 changes: 10 additions & 7 deletions examples/des_y1_3x2pt/des_y1_cosmic_shear_pk_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
import firecrown.likelihood.weak_lensing as wl
from firecrown.likelihood.two_point import TwoPoint
from firecrown.likelihood.gaussian import ConstGaussian
from firecrown.parameters import ParamsMap, create
from firecrown.parameters import ParamsMap, register_new_updatable_parameter
from firecrown.modeling_tools import ModelingTools, PowerspectrumModifier
from firecrown.likelihood.likelihood import Likelihood
from firecrown.ccl_factory import CCLFactory

from firecrown.updatable import get_default_params_map
from firecrown.metadata_types import TracerNames

SACCFILE = os.path.expanduser(
os.path.expandvars(
Expand All @@ -37,7 +38,7 @@ def __init__(self, pk_to_modify: str = "delta_matter:delta_matter"):
super().__init__()
self.pk_to_modify = pk_to_modify
self.vD19 = pyccl.baryons.BaryonsvanDaalen19()
self.f_bar = create()
self.f_bar = register_new_updatable_parameter(default_value=0.5)

def compute_p_of_k_z(self, tools: ModelingTools) -> pyccl.Pk2D:
"""Compute the 3D power spectrum P(k, z)."""
Expand Down Expand Up @@ -138,7 +139,9 @@ def run_likelihood() -> None:
}
)
# Prepare the cosmology object
tools.update(systematics_params)
params = ParamsMap(get_default_params_map(tools) | systematics_params)

tools.update(params)
tools.prepare()

ccl_cosmo = tools.get_ccl_cosmology()
Expand All @@ -150,7 +153,7 @@ def run_likelihood() -> None:
)

# Apply the systematics parameters
likelihood.update(systematics_params)
likelihood.update(params)

# Compute the log-likelihood, using the ccl.Cosmology object as the input
log_like = likelihood.compute_loglike(tools)
Expand All @@ -165,7 +168,7 @@ def run_likelihood() -> None:

# Predict CCL Cl
wl_tracer = ccl.WeakLensingTracer(ccl_cosmo, dndz=(z, nz))
ell = two_point_0.ells
ell = two_point_0.ells_for_xi
cl_dm = ccl.angular_cl(
cosmo=ccl_cosmo,
tracer1=wl_tracer,
Expand All @@ -190,7 +193,7 @@ def make_plot(ell, cl_dm, cl_baryons, two_point_0):
"""Create and show a diagnostic plot."""
import matplotlib.pyplot as plt # pylint: disable-msg=import-outside-toplevel

cl_firecrown = two_point_0.cells[("shear", "shear")]
cl_firecrown = two_point_0.cells[TracerNames("shear", "shear")]

plt.plot(ell, cl_firecrown / cl_dm, label="firecrown w/ baryons")
plt.plot(ell, cl_baryons / cl_dm, ls="--", label="CCL w/ baryons")
Expand Down

0 comments on commit e446981

Please sign in to comment.