Skip to content

Commit

Permalink
Clean test
Browse files Browse the repository at this point in the history
  • Loading branch information
ggalloni committed Aug 8, 2024
1 parent 266a25d commit ec27371
Showing 1 changed file with 42 additions and 31 deletions.
73 changes: 42 additions & 31 deletions mflike/tests/test_mflike.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@
"tau": 0.0544,
}

nuis_params = {
common_nuis_params = {
"T_effd": 19.6,
"beta_d": 1.5,
"beta_s": -2.5,
"alpha_s": 1,
"bandint_shift_LAT_93": 0,
"bandint_shift_LAT_145": 0,
"bandint_shift_LAT_225": 0,
"cal_LAT_93": 1,
"cal_LAT_145": 1,
"cal_LAT_225": 1,
"calG_all": 1,
"alpha_LAT_93": 0,
"alpha_LAT_145": 0,
"alpha_LAT_225": 0,
}

TT_nuis_params = {
"a_tSZ": 3.30,
"a_kSZ": 1.60,
"a_p": 6.90,
Expand All @@ -28,35 +45,28 @@
"a_s": 3.10,
"T_d": 9.60,
"a_gtt": 2.80,
"a_gte": 0.10,
"a_gee": 0.10,
"a_psee": 0,
"a_pste": 0,
"xi": 0.10,
"beta_s": -2.5,
"alpha_s": 1,
"T_effd": 19.6,
"beta_d": 1.5,
"alpha_dT": -0.6,
"alpha_dE": -0.4,
"alpha_p": 1,
"alpha_tSZ": 0.,
"bandint_shift_LAT_93": 0,
"bandint_shift_LAT_145": 0,
"bandint_shift_LAT_225": 0,
"calT_LAT_93": 1,
"calE_LAT_93": 1,
"calT_LAT_145": 1,
"calE_LAT_145": 1,
"calT_LAT_225": 1,
}

TE_nuis_params = {
"a_gte": 0.10,
"a_pste": 0,
"alpha_dE": -0.4,
}

EE_nuis_params = {
"a_gee": 0.10,
"a_psee": 0,
"alpha_dE": -0.4,
"calE_LAT_93": 1,
"calE_LAT_145": 1,
"calE_LAT_225": 1,
"cal_LAT_93": 1,
"cal_LAT_145": 1,
"cal_LAT_225": 1,
"calG_all": 1,
"alpha_LAT_93": 0,
"alpha_LAT_145": 0,
"alpha_LAT_225": 0,
}

chi2s = {
Expand All @@ -80,6 +90,7 @@ def test_mflike(self):
# using camb low accuracy parameters for the test
camb_cosmo = cosmo_params | {"lmax": 9001, "lens_potential_accuracy": 1}
pars = camb.set_params(**camb_cosmo)
nuis_params = common_nuis_params | TT_nuis_params | TE_nuis_params | EE_nuis_params
results = camb.get_results(pars)
powers = results.get_cmb_power_spectra(pars, CMB_unit="muK")
cl_dict = {k: powers["total"][:, v] for k, v in {"tt": 0, "ee": 1, "te": 3}.items()}
Expand Down Expand Up @@ -108,7 +119,7 @@ def test_mflike(self):
self.assertAlmostEqual(-2 * (loglike - my_mflike.logp_const), chi2, 2)

def test_cobaya_TT(self):
TT_nuis_params = {k: v for k, v in nuis_params.items() if "calE" not in k}
nuis_params = common_nuis_params | TT_nuis_params | TE_nuis_params | EE_nuis_params
info = {
"likelihood": {
"mflike.TT": {
Expand All @@ -118,16 +129,17 @@ def test_cobaya_TT(self):
},
"theory": {"camb": {"extra_args": {"lens_potential_accuracy": 1}},
"mflike.BandpowerForeground": {}},
"params": cosmo_params | TT_nuis_params,
"params": cosmo_params | nuis_params,
"packages_path": packages_path,
}

model = get_model(info)
my_mflike = model.likelihood["mflike.TT"]
chi2 = -2 * (model.loglike(TT_nuis_params, return_derived=False) - my_mflike.logp_const)
chi2 = -2 * (model.loglike(nuis_params, return_derived=False) - my_mflike.logp_const)
self.assertAlmostEqual(chi2, chi2s["tt"], 2)

def test_cobaya_TE(self):
nuis_params = common_nuis_params | TT_nuis_params | TE_nuis_params | EE_nuis_params
info = {
"likelihood": {
"mflike.TE": {
Expand All @@ -147,7 +159,7 @@ def test_cobaya_TE(self):
self.assertAlmostEqual(chi2, chi2s["te-et"], 2)

def test_cobaya_EE(self):
EE_nuis_params = {k: v for k, v in nuis_params.items() if "calT" not in k}
nuis_params = common_nuis_params | TT_nuis_params | TE_nuis_params | EE_nuis_params
info = {
"likelihood": {
"mflike.EE": {
Expand All @@ -157,16 +169,17 @@ def test_cobaya_EE(self):
},
"theory": {"camb": {"extra_args": {"lens_potential_accuracy": 1}},
"mflike.BandpowerForeground": {}},
"params": cosmo_params | EE_nuis_params,
"params": cosmo_params | nuis_params,
"packages_path": packages_path,
}

model = get_model(info)
my_mflike = model.likelihood["mflike.EE"]
chi2 = -2 * (model.loglike(EE_nuis_params, return_derived=False) - my_mflike.logp_const)
chi2 = -2 * (model.loglike(nuis_params, return_derived=False) - my_mflike.logp_const)
self.assertAlmostEqual(chi2, chi2s["ee"], 2)

def test_cobaya_TTTEEE(self):
nuis_params = common_nuis_params | TT_nuis_params | TE_nuis_params | EE_nuis_params
info = {
"likelihood": {
"mflike.TTTEEE": {
Expand All @@ -182,13 +195,11 @@ def test_cobaya_TTTEEE(self):

model = get_model(info)
my_mflike = model.likelihood["mflike.TTTEEE"]
print("logp_const", my_mflike.logp_const)
print("loglike", model.loglike(nuis_params, return_derived=False))
print("test", model.loglikes(nuis_params, return_derived=False))
chi2 = -2 * (model.loglike(nuis_params, return_derived=False) - my_mflike.logp_const)
self.assertAlmostEqual(chi2, chi2s["tt-te-et-ee"], 2)

def test_top_hat_bandpasses(self):
nuis_params = common_nuis_params | TT_nuis_params | TE_nuis_params | EE_nuis_params
# Let's vary values of bandint_shift parameters
params = nuis_params | {
k: {"prior": {"min": 0.9 * v, "max": 1.1 * v}}
Expand Down

0 comments on commit ec27371

Please sign in to comment.