From 72002e6a6e86b1715d020a1d6c560674f2167a13 Mon Sep 17 00:00:00 2001 From: Sandro Dias Pinto Vitenti Date: Tue, 29 Oct 2024 17:35:54 -0300 Subject: [PATCH] Testing cosmosis connector with pure ccl. --- .../cosmosis/test_cosmosis_module.py | 19 ++++-- .../lkscript_two_point_pure_ccl.py | 59 +++++++++++++++++++ 2 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 tests/likelihood/gauss_family/lkscript_two_point_pure_ccl.py diff --git a/tests/connector/cosmosis/test_cosmosis_module.py b/tests/connector/cosmosis/test_cosmosis_module.py index dc4394b0..6a286db8 100644 --- a/tests/connector/cosmosis/test_cosmosis_module.py +++ b/tests/connector/cosmosis/test_cosmosis_module.py @@ -105,15 +105,24 @@ def fixture_config_with_two_point_real() -> DataBlock: return result -@pytest.fixture(name="config_with_two_point_harmonic") -def fixture_config_with_two_point_harmonic() -> DataBlock: +@pytest.fixture(name="config_with_two_point_harmonic", params=["default", "pure_ccl"]) +def fixture_config_with_two_point_harmonic(request) -> DataBlock: result = DataBlock() + likelihood_file = "" + if request.param == "default": + likelihood_file = ( + "${FIRECROWN_DIR}/tests/likelihood/gauss_family/lkscript_two_point.py" + ) + elif request.param == "pure_ccl": + likelihood_file = ( + "${FIRECROWN_DIR}/tests/likelihood/" + "gauss_family/lkscript_two_point_pure_ccl.py" + ) + result.put_string( option_section, "Likelihood_source", - expandvars( - "${FIRECROWN_DIR}/tests/likelihood/gauss_family/lkscript_two_point.py" - ), + expandvars(likelihood_file), ) result.put_string( option_section, diff --git a/tests/likelihood/gauss_family/lkscript_two_point_pure_ccl.py b/tests/likelihood/gauss_family/lkscript_two_point_pure_ccl.py new file mode 100644 index 00000000..64e64a7a --- /dev/null +++ b/tests/likelihood/gauss_family/lkscript_two_point_pure_ccl.py @@ -0,0 +1,59 @@ +""" +Provides a trivial likelihood factory function for a ConstGaussian +for testing purposes. +""" + +import numpy as np +import sacc + +from firecrown.likelihood.likelihood import NamedParameters +from firecrown.likelihood.gaussian import ConstGaussian +from firecrown.likelihood.two_point import TwoPoint +from firecrown.likelihood.number_counts import ( + NumberCounts, +) +from firecrown.modeling_tools import ModelingTools +from firecrown.ccl_factory import ( + CCLFactory, + PoweSpecAmplitudeParameter, + CCLCreationMode, +) + + +def build_likelihood(params: NamedParameters): + """Return a ConstGaussian (likelihood) object.""" + sacc_data = sacc.Sacc() + + src0 = NumberCounts(sacc_tracer="lens0") + z = np.linspace(0, 0.8, 50) + 0.05 + dndz = np.exp(-0.5 * (z - 0.4) ** 2 / 0.02 / 0.02) + sacc_data.add_tracer("NZ", "lens0", z, dndz) + + if params.get_string("projection") == "harmonic": + two_point = TwoPoint("galaxy_density_cl", source0=src0, source1=src0) + ells = np.unique(np.logspace(1, 3, 10).astype(np.int64)) + Cells = np.random.normal(size=ells.shape[0]) + sacc_data.add_ell_cl("galaxy_density_cl", "lens0", "lens0", ells, Cells) + cov = np.diag(np.ones_like(Cells) * 0.01) + sacc_data.add_covariance(cov) + elif params.get_string("projection") == "real": + two_point = TwoPoint("galaxy_density_xi", source0=src0, source1=src0) + thetas = np.linspace(0.0, np.pi, 10) + xis = np.random.normal(size=thetas.shape[0]) + sacc_data.add_theta_xi("galaxy_density_xi", "lens0", "lens0", thetas, xis) + cov = np.diag(np.ones_like(xis) * 0.01) + sacc_data.add_covariance(cov) + else: + raise ValueError("Invalid projection") + + likelihood = ConstGaussian(statistics=[two_point]) + likelihood.read(sacc_data) + + tools = ModelingTools( + ccl_factory=CCLFactory( + amplitude_parameter=PoweSpecAmplitudeParameter.SIGMA8, + creation_mode=CCLCreationMode.PURE_CCL_MODE, + ) + ) + + return likelihood, tools