Skip to content

Commit

Permalink
qb_only option for computing bandpowers
Browse files Browse the repository at this point in the history
Use this option to skip computing signal window functions and Cb or Db
bandpowers.  Useful for testing and gcorr runs, for example.
  • Loading branch information
arahlin committed Nov 5, 2023
1 parent 5264afb commit 4a44649
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
68 changes: 39 additions & 29 deletions xfaster/xfaster_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -5321,6 +5321,7 @@ def fisher_iterate(
delta_beta_prior=None,
cond_noise=None,
cond_criteria=None,
qb_only=False,
like_profiles=False,
like_profile_sigma=3.0,
like_profile_points=100,
Expand Down Expand Up @@ -5370,6 +5371,9 @@ def fisher_iterate(
cond_criteria : float
The maximum condition number allowed for Dmat1 to be acceptable
for taking its inverse.
qb_only : bool
If True, compute just maximum likelihood qb's, and skip
calculation of window functions and Cb bandpowers.
like_profiles : bool
If True, compute profile likelihoods for each qb, leaving all
others fixed at their maximum likelihood values. Profiles are
Expand Down Expand Up @@ -5718,36 +5722,37 @@ def fisher_iterate(
invfish_nosampvar=inv_fish_ns,
)

# compute window functions for signal bins
self.log("Calculating signal window functions", "info")
wbl_qb = self.fisher_calc(
qb,
cbl,
obs,
cls_noise=nell,
cls_debias=None,
cond_noise=None,
delta_beta_prior=delta_beta_prior,
null_first_cmb=null_first_cmb,
windows=True,
inv_fish=inv_fish,
)
out.update(wbl_qb=wbl_qb)
if like_profiles or not qb_only:
# compute window functions for signal bins
self.log("Calculating signal window functions", "info")
wbl_qb = self.fisher_calc(
qb,
cbl,
obs,
cls_noise=nell,
cls_debias=None,
cond_noise=None,
delta_beta_prior=delta_beta_prior,
null_first_cmb=null_first_cmb,
windows=True,
inv_fish=inv_fish,
)
out.update(wbl_qb=wbl_qb)

# compute bandpowers and covariances
cb, dcb, ellb, cov, qb2cb, wbl_cb = self.do_qb2cb(qb, inv_fish, wbl_qb)
_, dcb_ns, _, cov_ns, _, _ = self.do_qb2cb(qb, inv_fish_ns, wbl_qb)
# compute bandpowers and covariances
cb, dcb, ellb, cov, qb2cb, wbl_cb = self.do_qb2cb(qb, inv_fish, wbl_qb)
_, dcb_ns, _, cov_ns, _, _ = self.do_qb2cb(qb, inv_fish_ns, wbl_qb)

out.update(
cb=cb,
dcb=dcb,
ellb=ellb,
cov=cov,
qb2cb=qb2cb,
wbl_cb=wbl_cb,
dcb_nosampvar=dcb_ns,
cov_nosampvar=cov_ns,
)
out.update(
cb=cb,
dcb=dcb,
ellb=ellb,
cov=cov,
qb2cb=qb2cb,
wbl_cb=wbl_cb,
dcb_nosampvar=dcb_ns,
cov_nosampvar=cov_ns,
)

if like_profiles:
# compute bandpower likelihoods
Expand Down Expand Up @@ -6065,6 +6070,7 @@ def get_bandpowers(
cond_criteria=None,
null_first_cmb=False,
return_cls=False,
qb_only=False,
like_profiles=False,
like_profile_sigma=3.0,
like_profile_points=100,
Expand Down Expand Up @@ -6108,6 +6114,9 @@ def get_bandpowers(
Keep first CMB bandpowers fixed to input shape (qb=1).
return_cls : bool
If True, return C_ls rather than D_ls
qb_only : bool
If True, compute just maximum likelihood qb's, and skip
calculation of window functions and Cb bandpowers.
like_profiles : bool
If True, compute profile likelihoods for each qb, leaving all
others fixed at their maximum likelihood values. Profiles are
Expand Down Expand Up @@ -6163,7 +6172,7 @@ def get_bandpowers(

if self.template_type is not None:
opts.update(template_alpha=self.template_alpha)
self.return_cls = return_cls
self.return_cls = False if qb_only else return_cls

ret = self.load_data(
save_name,
Expand Down Expand Up @@ -6195,6 +6204,7 @@ def get_bandpowers(
cond_criteria=cond_criteria,
null_first_cmb=null_first_cmb,
delta_beta_prior=delta_beta_prior,
qb_only=qb_only,
like_profiles=like_profiles,
like_profile_sigma=like_profile_sigma,
like_profile_points=like_profile_points,
Expand Down
6 changes: 6 additions & 0 deletions xfaster/xfaster_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def xfaster_run(
iter_max=200,
save_iters=False,
return_cls=False,
qb_only=False,
fix_bb_transfer=False,
null_first_cmb=False,
delta_beta_prior=None,
Expand Down Expand Up @@ -393,6 +394,8 @@ def xfaster_run(
the end result.
return_cls : bool
If True, return C_l spectrum rather than the D_l spectrum
qb_only : bool
If True, do not compute signal window functions or C_l or D_l bandpowers
fix_bb_transfer : bool
If True, after transfer functions have been calculated, impose that the
BB transfer function is exactly equal to the EE transfer function.
Expand Down Expand Up @@ -660,6 +663,7 @@ def xfaster_run(
cond_criteria=cond_criteria,
null_first_cmb=null_first_cmb,
return_cls=return_cls,
qb_only=qb_only,
like_profiles=like_profiles,
like_profile_sigma=like_profile_sigma,
like_profile_points=like_profile_points,
Expand All @@ -678,6 +682,7 @@ def xfaster_run(
transfer_opts.pop("delta_beta_prior")
transfer_opts.pop("null_first_cmb")
transfer_opts.pop("return_cls")
transfer_opts.pop("qb_only")
transfer_opts.pop("like_profiles")
transfer_opts.pop("like_profile_sigma")
transfer_opts.pop("like_profile_points")
Expand Down Expand Up @@ -1207,6 +1212,7 @@ def add_arg(
add_arg(G, "iter_max", argtype=int)
add_arg(G, "save_iters")
add_arg(G, "return_cls")
add_arg(G, "qb_only")
add_arg(G, "fix_bb_transfer")
add_arg(G, "null_first_cmb")
add_arg(G, "delta_beta_prior", argtype=float)
Expand Down

0 comments on commit 4a44649

Please sign in to comment.