Exemplo n.º 1
0
    def get_sim_stats_qcl(self,
                          k1,
                          mc_sims,
                          k2=None,
                          recache=False,
                          lmax=None):
        """Returns the sim-average of the input *plancklens.qecl* list QE power spectra average

            Args:
                k1: QE anisotropy key 1
                mc_sims: the simulation indices to average the spectra over
                k2: QE anisotropy key 2 (defaults to k1)

            Returns:
                *plancklens.utils.stats* instance

        """
        if k2 is None: k2 = k1
        if lmax is None: lmax = self.get_lmaxqcl(k1, k2)
        tfname = os.path.join(
            self.lib_dir, 'sim_qcl_stats_%s_%s_%s_%s.pk' %
            (k1, k2, lmax, utils.mchash(mc_sims)))
        if not os.path.exists(tfname) or recache:
            stats_qcl = utils.stats(lmax + 1, docov=False)
            for i, idx in utils.enumerate_progress(
                    mc_sims,
                    label='building sim_stats qcl (k1,k2)=' + str((k1, k2))):
                stats_qcl.add(self.get_sim_qcl(k1, idx, k2=k2, lmax=lmax))
            pk.dump(stats_qcl, open(tfname, 'wb'), protocol=2)
        return pk.load(open(tfname, 'rb'))
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def _mcmf_hash(self):
     return utils.mchash(self.mc_sims_mf)