示例#1
0
    def __call__(self, get_alm, nside):
        """Returns the spin-weighted real-space map of the estimator.

        We first build X_lm in the wanted _{si}X_lm _{so}Y_lm and then convert this alm2map_spin conventions.

        """
        lmax = self.get_lmax()
        glm = np.zeros(hp.Alm.getsize(lmax), dtype=complex)
        clm = np.zeros(hp.Alm.getsize(lmax),
                       dtype=complex)  # X_{lm} is here glm + i clm
        for i, (si, cl) in enumerate(zip(self.spins_in, self.cls)):
            assert si in [0, -2, 2], str(si) + ' input spin not implemented'
            gclm = [get_alm('e'), get_alm('b')
                    ] if abs(si) == 2 else [-get_alm('t'), 0.]
            assert len(gclm) == 2
            sgn_g = -(-1)**si if si < 0 else -1
            sgn_c = (-1)**si if si < 0 else -1
            glm += hp.almxfl(ut.alm_copy(gclm[0], lmax), sgn_g * cl)
            if np.any(gclm[1]):
                clm += hp.almxfl(ut.alm_copy(gclm[1], lmax), sgn_c * cl)
        glm *= -1
        if self.spin_ou > 0: clm *= -1
        Red, Imd = uspin.alm2map_spin((glm, clm), nside, abs(self.spin_ou),
                                      lmax)
        if self.spin_ou < 0 and self.spin_ou % 2 == 1: Red *= -1
        if self.spin_ou < 0 and self.spin_ou % 2 == 0: Imd *= -1
        return Red + 1j * Imd
示例#2
0
    def get_sim_qlm(self, k, idx, lmax=None):
        """Returns a QE estimate, by computing and caching it if not done previously.

            Args:
                k: quadratic estimator key
                idx: simulation index
                lmax: optionally reduces the lmax of the output healpy array.

        """
        assert k in self.keys, (k, self.keys)
        if lmax is None:
            lmax = self.get_lmax_qlm(k)
        assert lmax <= self.get_lmax_qlm(k)
        if k in ['p_tp', 'x_tp', 'f_tp', 's_tp']:
            return self.get_sim_qlm('%stt' % k[0], idx,
                                    lmax=lmax) + self.get_sim_qlm(
                                        '%s_p' % k[0], idx, lmax=lmax)
        if k in ['p_te', 'p_tb', 'p_eb', 'x_te', 'x_tb', 'x_eb']:
            return self.get_sim_qlm(k[0] + k[2] + k[3], idx,
                                    lmax=lmax) + self.get_sim_qlm(
                                        k[0] + k[3] + k[2], idx, lmax=lmax)

        if '_bh_' in k:  # Bias-hardening
            assert self.resplib is not None, 'resplib arg necessary for this'
            kQE, ksource = k.split('_bh_')
            assert len(ksource) == 1 and ksource + kQE[1:] in self.keys, (
                ksource, kQE)
            assert self.get_lmax_qlm(kQE) == self.get_lmax_qlm(
                ksource + kQE[1:]), 'fix this (easy)'
            lmax = self.get_lmax_qlm(kQE)
            wL = self.resplib.get_response(kQE, ksource) * ut.cli(
                self.resplib.get_response(ksource + kQE[1:], ksource))
            ret = self.get_sim_qlm(kQE, idx, lmax=lmax)
            return ret - hp.almxfl(
                self.get_sim_qlm(ksource + kQE[1:], idx, lmax=lmax), wL)

        assert k in self.keys_fund, (k, self.keys_fund)
        fname = os.path.join(
            self.lib_dir,
            'sim_%s_%04d.fits' % (k, idx) if idx != -1 else 'dat_%s.fits' % k)
        if not os.path.exists(fname):
            if k in ['ptt', 'xtt']: self._build_sim_Tgclm(idx)
            elif k in ['p_p', 'x_p']: self._build_sim_Pgclm(idx)
            elif k in ['p', 'x']: self._build_sim_MVgclm(idx)
            elif k in ['f']: self._build_sim_f(idx)
            elif k in ['stt']: self._build_sim_stt(idx)
            elif k in ['ftt']: self._build_sim_ftt(idx)
            elif k in ['f_p']: self._build_sim_f_p(idx)
            elif k in ['ntt']: self._build_sim_ntt(idx)
            elif k in ['a_p']: self._build_sim_a_p(idx)
            elif k in [
                    'ptt', 'pte', 'pet', 'ptb', 'pbt', 'pee', 'peb', 'pbe',
                    'pbb', 'xtt', 'xte', 'xet', 'xtb', 'xbt', 'xee', 'xeb',
                    'xbe', 'xbb'
            ]:
                self._build_sim_xfiltMVgclm(idx, k)
            else:
                assert 0, k

        return ut.alm_copy(hp.read_alm(fname), lmax=lmax)
示例#3
0
    def get_sim_qlm_mf(self, k, mc_sims, lmax=None):
        """Returns a QE mean-field estimate, by averaging QE estimates from a set simulations (caches the result).

            Args:
                k: quadratic estimator key
                mc_sims: simulation indices to use for the estimate.
                lmax: optionally reduces the lmax of the output healpy array.

        """
        if lmax is None:
            lmax = self.get_lmax_qlm(k)
        assert lmax <= self.get_lmax_qlm(k)
        if k in ['p_tp', 'x_tp']:
            return (self.get_sim_qlm_mf('%stt' % k[0], mc_sims, lmax=lmax) +
                    self.get_sim_qlm_mf('%s_p' % k[0], mc_sims, lmax=lmax))
        if k in ['p_te', 'p_tb', 'p_eb', 'x_te', 'x_tb', 'x_eb']:
            return  self.get_sim_qlm_mf(k[0] + k[2] + k[3], mc_sims, lmax=lmax)  \
                    + self.get_sim_qlm_mf(k[0] + k[3] + k[2], mc_sims, lmax=lmax)
        if '_bh_' in k:  # Bias-hardening
            assert self.resplib is not None, 'resplib arg necessary for this'
            kQE, ksource = k.split('_bh_')
            assert len(ksource) == 1 and ksource + kQE[1:] in self.keys, (
                ksource, kQE)
            assert self.get_lmax_qlm(kQE) == self.get_lmax_qlm(
                ksource + kQE[1:]), 'fix this (easy)'
            lmax = self.get_lmax_qlm(kQE)
            wL = self.resplib.get_response(kQE, ksource) * ut.cli(
                self.resplib.get_response(ksource + kQE[1:], ksource))
            ret = self.get_sim_qlm_mf(kQE, mc_sims, lmax=lmax)
            return ret - hp.almxfl(
                self.get_sim_qlm_mf(ksource + kQE[1:], mc_sims, lmax=lmax), wL)

        assert k in self.keys_fund, (k, self.keys_fund)
        fname = os.path.join(self.lib_dir,
                             'simMF_k1%s_%s.fits' % (k, ut.mchash(mc_sims)))
        if not os.path.exists(fname):
            this_mcs = np.unique(mc_sims)
            MF = np.zeros(hp.Alm.getsize(lmax), dtype=complex)
            if len(this_mcs) == 0: return MF
            for i, idx in ut.enumerate_progress(this_mcs,
                                                label='calculating %s MF' % k):
                MF += self.get_sim_qlm(k, idx, lmax=lmax)
            MF /= len(this_mcs)
            _write_alm(fname, MF)
            print("Cached ", fname)
        return ut.alm_copy(hp.read_alm(fname), lmax=lmax)
示例#4
0
 def get_sim_bmliklm(self, idx):
     return hp.almxfl(
         utils.alm_copy(self.ivfs.get_sim_bmliklm(idx), lmax=self.lmax),
         self.lfilt_b)
示例#5
0
 def almxfm(alm, fm, lmax):
     ret = utils.alm_copy(alm, lmax=lmax)
     for m in range(lmax + 1):
         ret[hp.Alm.getidx(lmax, np.arange(m, lmax + 1, dtype=int),
                           m)] *= fm[m]
     return ret