def _get_nhl(qes1, qes2, cls_ivfs, lmax_out, cls_ivfs_bb=None, cls_ivfs_ab=None, ret_terms=False): GG_N0 = np.zeros(lmax_out + 1, dtype=float) CC_N0 = np.zeros(lmax_out + 1, dtype=float) GC_N0 = np.zeros(lmax_out + 1, dtype=float) CG_N0 = np.zeros(lmax_out + 1, dtype=float) cls_ivfs_aa = cls_ivfs cls_ivfs_bb = cls_ivfs if cls_ivfs_bb is None else cls_ivfs_bb cls_ivfs_ab = cls_ivfs if cls_ivfs_ab is None else cls_ivfs_ab cls_ivfs_ba = cls_ivfs_ab if ret_terms: terms = [] for qe1 in qes1: cL1 = qe1.cL(np.arange(lmax_out + 1)) for qe2 in qes2: cL2 = qe2.cL(np.arange(lmax_out + 1)) si, ti, ui, vi = (qe1.leg_a.spin_in, qe1.leg_b.spin_in, qe2.leg_a.spin_in, qe2.leg_b.spin_in) so, to, uo, vo = (qe1.leg_a.spin_ou, qe1.leg_b.spin_ou, qe2.leg_a.spin_ou, qe2.leg_b.spin_ou) assert so + to >= 0 and uo + vo >= 0, (so, to, uo, vo) clsu = utils.joincls([qe1.leg_a.cl, qe2.leg_a.cl.conj(), uspin.spin_cls(si, ui, cls_ivfs_aa)]) cltv = utils.joincls([qe1.leg_b.cl, qe2.leg_b.cl.conj(), uspin.spin_cls(ti, vi, cls_ivfs_bb)]) R_sutv = utils.joincls([uspin.wignerc(clsu, cltv, so, uo, to, vo, lmax_out=lmax_out), cL1, cL2]) clsv = utils.joincls([qe1.leg_a.cl, qe2.leg_b.cl.conj(), uspin.spin_cls(si, vi, cls_ivfs_ab)]) cltu = utils.joincls([qe1.leg_b.cl, qe2.leg_a.cl.conj(), uspin.spin_cls(ti, ui, cls_ivfs_ba)]) R_sutv = R_sutv + utils.joincls([uspin.wignerc(clsv, cltu, so, vo, to, uo, lmax_out=lmax_out), cL1, cL2]) # we now need -s-t uv sgnms = (-1) ** (si + so) sgnmt = (-1) ** (ti + to) clsu = utils.joincls([sgnms * qe1.leg_a.cl.conj(), qe2.leg_a.cl.conj(), uspin.spin_cls(-si, ui, cls_ivfs_aa)]) cltv = utils.joincls([sgnmt * qe1.leg_b.cl.conj(), qe2.leg_b.cl.conj(), uspin.spin_cls(-ti, vi, cls_ivfs_bb)]) R_msmtuv = utils.joincls([uspin.wignerc(clsu, cltv, -so, uo, -to, vo, lmax_out=lmax_out), cL1, cL2]) clsv = utils.joincls([sgnms * qe1.leg_a.cl.conj(), qe2.leg_b.cl.conj(), uspin.spin_cls(-si, vi, cls_ivfs_ab)]) cltu = utils.joincls([sgnmt * qe1.leg_b.cl.conj(), qe2.leg_a.cl.conj(), uspin.spin_cls(-ti, ui, cls_ivfs_ba)]) R_msmtuv = R_msmtuv + utils.joincls([uspin.wignerc(clsv, cltu, -so, vo, -to, uo, lmax_out=lmax_out), cL1, cL2]) GG_N0 += 0.5 * R_sutv.real GG_N0 += 0.5 * (-1) ** (to + so) * R_msmtuv.real CC_N0 += 0.5 * R_sutv.real CC_N0 -= 0.5 * (-1) ** (to + so) * R_msmtuv.real GC_N0 -= 0.5 * R_sutv.imag GC_N0 -= 0.5 * (-1) ** (to + so) * R_msmtuv.imag CG_N0 += 0.5 * R_sutv.imag CG_N0 -= 0.5 * (-1) ** (to + so) * R_msmtuv.imag if ret_terms: terms += [0.5 * R_sutv, 0.5 * (-1) ** (to + so) * R_msmtuv] return (GG_N0, CC_N0, GC_N0, CG_N0) if not ret_terms else (GG_N0, CC_N0, GC_N0, CG_N0, terms)
def get_covresp(source, s1, s2, cls, lmax): r"""Defines the responses terms for a CMB covariance anisotropy source. \delta < s_d(n) _td^*(n')> \equiv _r\alpha(n) W^{r, st}_l _{s - r}Y_{lm}(n) _tY^*_{lm}(n') + _r\alpha^*(n') W^{r, ts}_l _{s}Y_{lm}(n) _{t-r}Y^*_{lm}(n') """ if source in ['p','x', 'f', 'a', 'a_p']: # Lensing, modulation, or pol. rotation field from the field representation s_source, prR, mrR, cL_scal = get_resp_legs(source, lmax)[s1] coupl = uspin.spin_cls(s1, s2, cls)[:lmax + 1] return s_source, prR * coupl, mrR * coupl, cL_scal elif source in ['stt', 's']: # Point source 'S^2': Cov -> Cov + B delta_nn' S^2(n) B^\dagger on the diagonal. # From the def. there are actually 4 identical W terms hence a factor 1/4. cond = s1 == 0 and s2 == 0 s_source = 0 prR = 0.25 * cond * np.ones(lmax + 1, dtype=float) mrR = 0.25 * cond * np.ones(lmax + 1, dtype=float) cL_scal = lambda ell : np.ones(len(ell), dtype=float) return s_source, prR, mrR, cL_scal else: assert 0, 'source ' + source + ' cov. response not implemented'
def get_mf_resp(qe_key, cls_cmb, cls_ivfs, lmax_qe, lmax_out): """Deflection-induced mean-field response calculation. See Carron & Lewis 2019 in prep. """ # This version looks stable enough assert qe_key in ['p_p', 'ptt'], qe_key GL = np.zeros(lmax_out + 1, dtype=float) CL = np.zeros(lmax_out + 1, dtype=float) if qe_key == 'ptt': lmax_cmb = len(cls_cmb['tt']) - 1 spins = [0] elif qe_key == 'p_p': lmax_cmb = min(len(cls_cmb['ee']) - 1, len(cls_cmb['bb'] - 1)) spins = [-2, 2] elif qe_key == 'p': lmax_cmb = min(len(cls_cmb['ee']) - 1, len(cls_cmb['bb']) - 1, len(cls_cmb['tt']) - 1, len(cls_cmb['te']) - 1) spins = [0, -2, 2] else: assert 0, qe_key + ' not implemented' assert lmax_qe <= lmax_cmb if qe_key == 'ptt': cl_cmbtoticmb = {'tt': cls_cmb['tt'][:lmax_qe + 1] ** 2 * cls_ivfs['tt'][:lmax_qe + 1]} cl_cmbtoti = {'tt': cls_cmb['tt'][:lmax_qe + 1] * cls_ivfs['tt'][:lmax_qe + 1]} elif qe_key == 'p_p': cl_cmbtoticmb = {'ee': cls_cmb['ee'][:lmax_qe + 1] ** 2 * cls_ivfs['ee'][:lmax_qe + 1], 'bb': cls_cmb['bb'][:lmax_qe + 1] ** 2 * cls_ivfs['bb'][:lmax_qe + 1]} cl_cmbtoti = {'ee': cls_cmb['ee'][:lmax_qe + 1] * cls_ivfs['ee'][:lmax_qe + 1], 'bb': cls_cmb['bb'][:lmax_qe + 1] * cls_ivfs['bb'][:lmax_qe + 1]} else: assert 0, 'not implemented' # Build remaining fisher term II: FisherGII = np.zeros(lmax_out + 1, dtype=float) FisherCII = np.zeros(lmax_out + 1, dtype=float) for s1 in spins: for s2 in spins: cl1 = uspin.spin_cls(s1, s2, cls_ivfs)[:lmax_qe + 1] * (0.5 ** (s1 != 0) * 0.5 ** (s2 != 0)) # These 1/2 factor from the factor 1/2 in each B of B Covi B^dagger, where B maps spin-fields to T E B. cl2 = np.copy(uspin.spin_cls(s2, s1, cls_cmb)[:lmax_cmb + 1]) cl2[:lmax_qe + 1] -= uspin.spin_cls(s2, s1, cl_cmbtoticmb)[:lmax_qe + 1] if np.any(cl1) and np.any(cl2): for a in [-1, 1]: ai = uspin.get_spin_lower(s2, lmax_cmb) if a == - 1 else uspin.get_spin_raise(s2, lmax_cmb) for b in [1]: # a, b symmetry aj = uspin.get_spin_lower(-s1, lmax_cmb) if b == 1 else uspin.get_spin_raise(-s1, lmax_cmb) hL = 2 * (-1) ** (s1 + s2) * uspin.wignerc(cl1, cl2 * ai * aj, s2, s1, -s2 - a, -s1 - b, lmax_out=lmax_out) GL += (- a * b) * hL CL += (-1) * hL # Build remaining Fisher term II: for s1 in spins: for s2 in spins: cl1 = uspin.spin_cls(s2, s1, cl_cmbtoti)[:lmax_qe + 1] * (0.5 ** (s1 != 0)) cl2 = uspin.spin_cls(s1, s2, cl_cmbtoti)[:lmax_qe + 1] * (0.5 ** (s2 != 0)) if np.any(cl1) and np.any(cl2): for a in [-1, 1]: ai = uspin.get_spin_lower(s2, lmax_qe) if a == -1 else uspin.get_spin_raise(s2, lmax_qe) for b in [1]: aj = uspin.get_spin_lower(s1, lmax_qe) if b == 1 else uspin.get_spin_raise(s1, lmax_qe) hL = 2 * (-1) ** (s1 + s2) * uspin.wignerc(cl1 * ai, cl2 * aj, -s2 - a, -s1, s2, s1 - b, lmax_out=lmax_out) FisherGII += (- a * b) * hL FisherCII += (-1) * hL GL -= FisherGII CL -= FisherCII print("CL[1] ",CL[1]) print("GL[1] (before subtraction) ", GL[1]) print("GL[1] (after subtraction) ", GL[1] - CL[1]) GL -= CL[1] CL -= CL[1] GL *= 0.25 * np.arange(lmax_out + 1) * np.arange(1, lmax_out + 2) CL *= 0.25 * np.arange(lmax_out + 1) * np.arange(1, lmax_out + 2) return GL, CL