示例#1
0
 def hashdict(self):
     return {'n_inv': clhash(self.n_inv),
             'b_transf': clhash(self.b_transf),
             'marge_monopole': self.marge_monopole,
             'marge_dipole': self.marge_dipole,
             'templates_hash': self.templates_hash,
             'marge_uptolmin': self.marge_uptolmin}
示例#2
0
 def hashdict(self):
     return {
         'ivfs': self.ivfs.hashdict(),
         'filt_t': utils.clhash(self.lfilt_t[:self.lmax + 1]),
         'filt_e': utils.clhash(self.lfilt_e[:self.lmax + 1]),
         'filt_b': utils.clhash(self.lfilt_b[:self.lmax + 1])
     }
示例#3
0
 def hashdict(self):
     return {
         'cltt': clhash(self.cltt),
         'clte': clhash(self.clte),
         'clee': clhash(self.clee),
         'dL': self.dL,
         'lps': self.lps
     }
示例#4
0
 def hashdict(self):
     return {
         'n_inv': [clhash(n) for n in self.n_inv],
         'b_transf': clhash(self.b_transf),
         'marge_monopole': self.marge_monopole,
         'marge_dipole': self.marge_dipole,
         'templates_t_hash': self.templates_t_hash
     }
示例#5
0
 def hashdict(self):
     ret = {'lmaxqe':self.lmax_qe, 'lmax_qlm':self.lmax_qlm}
     for k in self.cls_weight.keys():
         ret['clsweight ' + k] = ut.clhash(self.cls_weight[k])
     for k in self.cls_cmb.keys():
         ret['clscmb ' + k] = ut.clhash(self.cls_cmb[k])
     for k in self.fal.keys():
         ret['fal' + k] = ut.clhash(self.fal[k])
     return ret
示例#6
0
 def hashdict(self):
     return {
         'lmax': self.lmax,
         'nside': self.nside,
         'clee': utils.clhash(self.cl.get('ee', np.array([0.]))),
         'cleb': utils.clhash(self.cl.get('eb', np.array([0.]))),
         'clbb': utils.clhash(self.cl.get('bb', np.array([0.]))),
         'transf': utils.clhash(self.transf),
         'ninv': self._ninv_hash()
     }
示例#7
0
 def hashdict(self):
     return {
         'lmax': self.lmax,
         'nside': self.nside,
         'cltt': utils.clhash(self.cl['tt'][:self.lmax + 1]),
         'transf': utils.clhash(self.transf[:self.lmax + 1]),
         'ninv': self._ninv_hash(),
         'marge_monopole': self.marge_monopole,
         'marge_dipole': self.marge_dipole,
         'marge_maps': self.marge_maps
     }
示例#8
0
 def hashdict(self):
     return {
         'sim_lib': self.sim_lib.hashdict(),
         'transf': utils.clhash(self.transf),
         'cl_len':
         {k: utils.clhash(self.cl[k])
          for k in ['tt', 'ee', 'bb']},
         'ftl': utils.clhash(self.ftl),
         'fel': utils.clhash(self.fel),
         'fbl': utils.clhash(self.fbl)
     }
示例#9
0
 def hashdict(self):
     return {
         'lmax': self.lmax,
         'nside': self.nside,
         'rescal_cl': utils.clhash(self.rescal_cl),
         'cls': {k: utils.clhash(self.cl[k])
                 for k in self.cl.keys()},
         'transf': utils.clhash(self.transf),
         'ninv': self._ninv_hash(),
         'marge_maps_t': self.marge_maps_t,
         'marge_maps_p': self.marge_maps_p
     }
示例#10
0
        def _get_n1_L(self, L, kA, kB, k_ind, cl_kind, ftlA, felA, fblA, ftlB,
                      felB, fblB, clttfid, cltefid, cleefid):
            if kB is None: kB = kA
            assert kA in estimator_keys and kB in estimator_keys
            assert len(cl_kind) > self.lmaxphi
            if kA in estimator_keys and kB in estimator_keys:
                if kA < kB:
                    return self._get_n1_L(L, kB, kA, k_ind, cl_kind, ftlA,
                                          felA, fblA, ftlB, felB, fblB,
                                          clttfid, cltefid, cleefid)
                else:
                    lmin_ftlA = np.min([
                        np.where(np.abs(fal) > 0.)[0]
                        for fal in [ftlA, felA, fblA]
                    ])
                    lmin_ftlB = np.min([
                        np.where(np.abs(fal) > 0.)[0]
                        for fal in [ftlB, felB, fblB]
                    ])
                    lmax_ftl = np.max([
                        len(fal)
                        for fal in [ftlA, felA, fblA, ftlB, felB, fblB]
                    ]) - 1
                    assert len(clttfid) > lmax_ftl and len(
                        self.cltt) > lmax_ftl
                    assert len(cltefid) > lmax_ftl and len(
                        self.clte) > lmax_ftl
                    assert len(cleefid) > lmax_ftl and len(
                        self.clee) > lmax_ftl

                    idx = str(L) + 'kA' + kA + '_kB' + kB + '_ind' + k_ind
                    idx += '_clpp' + clhash(cl_kind)
                    idx += '_ftlA' + clhash(ftlA)
                    idx += '_felA' + clhash(felA)
                    idx += '_fblA' + clhash(fblA)
                    idx += '_ftlB' + clhash(ftlB)
                    idx += '_felB' + clhash(felB)
                    idx += '_fblB' + clhash(fblB)
                    idx += '_clttfid' + clhash(clttfid)
                    idx += '_cltefid' + clhash(cltefid)
                    idx += '_cleefid' + clhash(cleefid)

                    if self.fldb.get(idx) is None:
                        n1_L = n1f.n1l(L, cl_kind, kA, kB, k_ind, self.cltt,
                                       self.clte, self.clee, clttfid, cltefid,
                                       cleefid, ftlA, felA, fblA, ftlB, felB,
                                       fblB, lmin_ftlA, lmin_ftlB, self.dL,
                                       self.lps)
                        self.fldb.add(idx, n1_L)
                        return n1_L
                    return self.fldb.get(idx)
            assert 0
示例#11
0
 def hashdict(self):
     return {
         'cinv_tp': self.cinv_tp.hashdict(),
         'clw': {k: utils.clhash(self.cl[k])
                 for k in self.cl.keys()},
         'sim_lib': self.sim_lib.hashdict()
     }
示例#12
0
 def hashdict(self):
     return {
         'transf': utils.clhash(self.transf),
         'nlevt': np.float32(self.nlevt),
         'nlevp': np.float32(self.nlevp),
         'pix_phas': self.pix_libphas.hashdict()
     }
示例#13
0
    def __init__(self, cls_unl, lib_pha):
        lmax = lib_pha.lmax
        lmin = 0
        fields = _get_fields(cls_unl)
        Nf = len(fields)
        if verbose: print("I see %s fields: " % Nf + " ".join(fields))
        rmat = np.zeros((lmax + 1, Nf, Nf), dtype=float)
        str = ''
        for _i, _t1 in enumerate(fields):
            for _j, _t2 in enumerate(fields):
                if _j >= _i:
                    if _t1 + _t2 in cls_unl.keys():
                        rmat[lmin:, _i, _j] = cls_unl[_t1 + _t2][:lmax + 1]
                        rmat[lmin:, _j, _i] = rmat[lmin:, _i, _j]
                    else:
                        str += " " + _t1 + _t2
        if verbose and str != '': print(str + ' set to zero')
        for ell in range(lmin, lmax + 1):
            t, v = np.linalg.eigh(rmat[ell, :, :])
            assert np.all(t >= 0.), (ell, t, rmat[ell, :, :]
                                     )  # Matrix not positive semidefinite
            rmat[ell, :, :] = np.dot(v, np.dot(np.diag(np.sqrt(t)), v.T))

        self._cl_hash = {}
        for k in cls_unl.keys():
            self._cl_hash[k] = utils.clhash(cls_unl[k])
        self.rmat = rmat
        self.lib_pha = lib_pha
        self.fields = fields
示例#14
0
 def _ninv_hash(self):
     ret = []
     for ninv_comp in self.ninv:
         if isinstance(ninv_comp, np.ndarray) and ninv_comp.size > 1:
             ret.append(utils.clhash(ninv_comp))
         else:
             ret.append(ninv_comp)
     return [ret]
示例#15
0
 def hashdict(self):
     ret = {
         k: utils.clhash(self.cls_weight[k])
         for k in self.cls_weight.keys()
     }
     ret['ivfs'] = self.ivfs.hashdict()
     ret['lmax_qlm'] = self.lmax_qlm
     return ret
示例#16
0
 def hashdict(self):
     return {
         'sims_cmb_len': self.sims_cmb_len.hashdict(),
         'nside': self.nside,
         'cl_transf': clhash(self.cl_transf),
         'nlev_t': self.nlev_t,
         'nlev_p': self.nlev_p,
         'pixphas': self.pix_lib_phas.hashdict()
     }
示例#17
0
 def hashdict(self):
     ret = {
         'lmax': self.lmax,
         'nside': self.nside,
         'rescal_cl': {
             k: utils.clhash(self.rescal_cl[k])
             for k in self.rescal_cl.keys()
         },
         'cls': {k: utils.clhash(self.cl[k])
                 for k in self.cl.keys()},
         'transf': utils.clhash(self.transf_t),
         'ninv': self._ninv_hash(),
         'marge_maps_t': self.marge_maps_t,
         'marge_maps_p': self.marge_maps_p
     }
     if self.transf_p is not self.transf_t:
         ret['transf_p'] = utils.clhash(self.transf_p)
     return ret
示例#18
0
文件: n1.py 项目: markm42/plancklens
    def _get_n1_L_jtp(self, L, kA, kB, k_ind, cl_kind, Xp, Yp, Ip, Jp, fAlmat, fBlmat, clttfid, cltefid, cleefid):
            if kB is None: kB = kA
            if kA in estimator_keys and kB in estimator_keys:
                if kA < kB:
                    assert 0, 'fix this'
                else:
                    X, Y = kA[1:]
                    I, J = kB[1:]
                    FXXp = fAlmat.get(X + Xp, fAlmat.get(Xp + X, None))
                    if FXXp is None: return 0.

                    FYYp = fAlmat.get(Y + Yp, fAlmat.get(Yp + Y, None))
                    if FYYp is None: return 0.

                    FIIp = fBlmat.get(I + Ip, fBlmat.get(Ip + I, None))
                    if FIIp is None: return 0.

                    FJJp = fBlmat.get(J + Jp, fBlmat.get(Jp + J, None))
                    if FJJp is None: return 0.

                    lmax_ftl = np.max([FXXp.size, FYYp.size, FIIp.size, FJJp.size]) - 1
                    lmin_ftlA = np.min([np.where(np.abs(fal) > 0.)[0] for fal in [FXXp, FYYp]])
                    lmin_ftlB = np.min([np.where(np.abs(fal) > 0.)[0] for fal in [FIIp, FJJp]])
                    assert len(clttfid) > lmax_ftl and len(self.cltt) > lmax_ftl
                    assert len(cltefid) > lmax_ftl and len(self.clte) > lmax_ftl
                    assert len(cleefid) > lmax_ftl and len(self.clee) > lmax_ftl
                    assert (FXXp.size == FYYp.size) and (FIIp.size == FJJp.size)
                    assert len(cl_kind) > self.lmaxphi

                    idx = str(L)  + X + Xp + Y + Yp + I + Ip + J + Jp
                    idx += '_clpp' + clhash(cl_kind)
                    idx += '_fXXp' + clhash(FXXp)
                    idx += '_fYYp' + clhash(FYYp)
                    idx += '_fIIp' + clhash(FIIp)
                    idx += '_fJJp' + clhash(FJJp)
                    idx += '_clttfid' + clhash(clttfid)
                    idx += '_cltefid' + clhash(cltefid)
                    idx += '_cleefid' + clhash(cleefid)
                    # n1L_jtp(L, cl_kI, kA, kB, XpIp, YpJp, kI, cltt, clte, clee, clttfid, cltefid,
                    #        cleefid, &
                    # fXXp, fYYp, fIIp, fJJp, lminA, lmaxA, lminB, lmaxB, lmaxI, &
                    # lmaxtt, lmaxte, lmaxee, lmaxttfid, lmaxtefid, lmaxeefid, dL, lps, nlps)
                    if self.fldb.get(idx) is None:
                        n1_L = n1f.n1l_jtp(L, cl_kind, kA, kB, Xp, Yp, Ip, Jp, k_ind,
                                       self.cltt, self.clte, self.clee, clttfid, cltefid, cleefid,
                                       FXXp, FYYp, FIIp, FJJp,
                                       lmin_ftlA, lmin_ftlB, self.dL, self.lps)
                        self.fldb.add(idx, n1_L)
                        return n1_L
                    return self.fldb.get(idx)
            assert 0
示例#19
0
def mask_hash(m, dtype=bool):
    if m is None:
        return "none"
    if isinstance(m, list):
        mh = mask_hash(m[0], dtype=dtype)
        for m2 in m[1:]:
            mh += mask_hash(m2, dtype=dtype)
        return mh
    if isinstance(m, str):
        return m.replace('/', '_sl_').replace('.', '_')
    elif isinstance(m, np.ndarray):
        return utils.clhash(m, dtype=dtype)
    elif callable(m):
        return 'callable'
    assert 0, 'not implemented'
示例#20
0
 def hashdict(self):
     return {'slinv': clhash(self.slinv.flatten())}
示例#21
0
def get_responses(qe_key,
                  cls_cmb_dat,
                  cls_cmb_filt,
                  cls_weight,
                  lmin,
                  lmax,
                  lmax_qlm,
                  transf,
                  nlevts_filt,
                  nlevps_filt,
                  joint_TP=False,
                  cacher=cachers.cacher_mem(),
                  source='p'):
    """Collects estimator responses for a list of filtering noise levels


        Args:
            qe_key: QE estimator key
            cls_cmb_dat: CMB cls of the data maps
            cls_cmb_filt: CMB cls used for the filtering
            cls_weight: CMB cls in the QE weights
            lmin: minimum CMB multipole considered
            lmax: maximum CMB multipole considered
            lmax_qlm: QE output lmax
            transf: CMB transfer function
            nlevts_filt: list or array of filtering temperature noise levels
            nlevps_filt: list or array of filtering polarization noise levels
            joint_TP: uses joint temperature and polarization filtering if set, separate if not
            cacher: can be used to store results
            source: QE response anisotropy source (defaults to lensing)

        Returns:
            lists of responses (GG, CC, GC CG for spin-weight QE)

        Note:
            Results may be stored with the cacher but only the filtering noise levels, QE keys and joint_TP are differentiated in the filename

    """
    resps = []
    for i, (nlevt_f, nlevp_f) in utils.enumerate_progress(
            list(zip(nlevts_filt, nlevps_filt)), 'collecting responses'):
        fname = 'vmapresps%s_%s_%s' % ('jTP' * joint_TP, qe_key,
                                       qe_key) + utils.clhash(
                                           np.array([nlevt_f, nlevp_f]))
        if not cacher.is_cached(fname):
            cls_filt_i = get_ivf_cls(cls_cmb_dat,
                                     cls_cmb_filt,
                                     lmin,
                                     lmax,
                                     nlevt_f,
                                     nlevp_f,
                                     nlevt_f,
                                     nlevp_f,
                                     transf,
                                     jt_tp=joint_TP)[1]
            this_resp = qresp.get_response(qe_key,
                                           lmax,
                                           source,
                                           cls_weight,
                                           cls_cmb_dat,
                                           cls_filt_i,
                                           lmax_qlm=lmax_qlm)
            cacher.cache(fname, this_resp)
        resps.append(cacher.load(fname))
    return resps
示例#22
0
文件: n1.py 项目: markm42/plancklens
    def get_n1_jtp(self, kA, k_ind, cl_kind, fAlmat, Lmax, kB=None, fBlmat=None,
            clttfid=None, cltefid=None, cleefid=None, n1_flat=lambda ell: np.ones(len(ell), dtype=float)):

        if kB is None: kB = kA
        # FIXME:
        if kA[0] == 's' or kB[0] == 's':
            assert kA[0] == kB[0], 'point source implented following DH gradient convention, you wd probably need to pick a sign there'
        if fBlmat is None: fBlmat = fAlmat

        clttfid = self.cltt if clttfid is None else clttfid
        cltefid = self.clte if cltefid is None else cltefid
        cleefid = self.clee if cleefid is None else cleefid


        if kA in estimator_keys and kB in estimator_keys:
            if kA < kB:
                return self.get_n1_jtp(kB, k_ind, cl_kind, fBlmat, Lmax, fBlmat=fAlmat, kB=kA,
                                   clttfid=clttfid, cltefid=cltefid, cleefid=cleefid, n1_flat=n1_flat)


            X, Y = kA[1:]
            I, J = kB[1:]
            assert np.all(i in ['t', 'e', 'b'] for i in [X, Y, I, J]),  [X, Y, I, J]
            ret = 0.
            for Xp in ['t', 'e', 'b']:
                FXXp = fAlmat.get(X + Xp, fAlmat.get(Xp + X, [0.]))
                if np.any(FXXp):
                    for Yp in ['t', 'e', 'b']:
                        FYYp = fAlmat.get(Y + Yp, fAlmat.get(Yp + Y, [0.]))
                        if np.any(FYYp):
                            for Ip in ['t', 'e', 'b']:
                                FIIp = fBlmat.get(I + Ip, fBlmat.get(Ip + I, [0.]))
                                if np.any(FIIp):
                                    for Jp in ['t', 'e', 'b']:
                                        FJJp = fBlmat.get(J + Jp, fBlmat.get(Jp + J, [0.]))
                                        if np.any(FJJp):
                                            idx = 'splined_' + X + Xp + Y + Yp + I + Ip + J + Jp
                                            idx += '_clpp' + clhash(cl_kind)
                                            idx += '_fXXp' + clhash(FXXp)
                                            idx += '_fYYp' + clhash(FYYp)
                                            idx += '_fIIp' + clhash(FIIp)
                                            idx += '_fJJp' + clhash(FJJp)
                                            idx += '_clttfid' + clhash(clttfid)
                                            idx += '_cltefid' + clhash(cltefid)
                                            idx += '_cleefid' + clhash(cleefid)
                                            idx += '_Lmax%s' % Lmax

                                            if self.npdb.get(idx) is None:
                                                Ls = np.unique(np.concatenate([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], np.arange(1, Lmax + 1)[::20], [Lmax]]))
                                                n1L = np.zeros(len(Ls), dtype=float)
                                                for i, L in enumerate(Ls):
                                                    print("n1: doing L %s kA %s kB %s kind %s " % (L, kA, kB, k_ind)  + Xp + Yp + Ip + Jp)
                                                    n1L[i] = (self._get_n1_L_jtp(L, kA, kB, k_ind, cl_kind, Xp, Yp, Ip, Jp, fAlmat, fBlmat, clttfid, cltefid, cleefid))
                                                ret = np.zeros(Lmax + 1)
                                                ret[1:] =  spline(Ls, np.array(n1L) * n1_flat(Ls), s=0., ext='raise', k=3)(np.arange(1, Lmax + 1) * 1.)
                                                ret[1:] *= cli(n1_flat(np.arange(1, Lmax + 1) * 1.))
                                                self.npdb.add(idx, ret)
                                            ret = ret +  self.npdb.get(idx)
            return ret
        if (kA in estimator_keys_derived) or (kB in estimator_keys_derived):
            ret = 0.
            for (tk1, cl1) in _get_est_derived(kA, Lmax):
                for (tk2, cl2) in _get_est_derived(kB, Lmax):
                    tret = self.get_n1_jtp(tk1, k_ind, cl_kind, fAlmat, Lmax, kB=tk2, fBlmat=fBlmat,
                                    clttfid=clttfid, cltefid=cltefid, cleefid=cleefid, n1_flat=n1_flat)
                    ret = ret + tret * cl1[:Lmax + 1] * cl2[:Lmax + 1]
            return ret
        assert 0
示例#23
0
文件: n1.py 项目: markm42/plancklens
    def get_n1(self, kA, k_ind, cl_kind, ftlA, felA, fblA, Lmax, kB=None, ftlB=None, felB=None, fblB=None,
               clttfid=None, cltefid=None, cleefid=None, n1_flat=lambda ell: np.ones(len(ell), dtype=float),
               recache=False, remove_only=False, sglLmode=True):
        r"""Calls a N1 bias

            Args:
                kA: qe_key of QE spectrum first leg
                k_ind: anisotropy source key ('p', for standard lensing N1)
                cl_kind: spectrum of anisotropy source ('p', for standard lensing N1)
                ftlA: first leg T-filtering isotropic approximation
                      (typically :math:`\frac{1}{C_\ell^{TT} + N_\ell^{TT}}`)
                felA: first leg E-filtering isotropic approximation
                      (typically :math:`\frac{1}{C_\ell^{EE} + N_\ell^{EE}}`)
                fblA: first leg B-filtering isotropic approximation
                     (typically :math:`\frac{1}{C_\ell^{BB} + N_\ell^{BB}}`)
                Lmax: maximum multipole of output N1
                kB(optional): qe_key of QE spectrum second leg (if different from the first)
                ftlB(optional): second leg T-filtering isotropic approximation (if different from the first)
                felB(optional): second leg E-filtering isotropic approximation (if different from the first)
                fblB(optional): second leg B-filtering isotropic approximation (if different from the first)
                clttfid(optional): CMB TT spectrum used in QE weights (if different from instance cltt for map-level CMB spectrum)
                cltefid(optional): CMB TE spectrum used in QE weights (if different from instance clte for map-level CMB spectrum)
                cleefid(optional): CMB EE spectrum used in QE weights (if different from instance clee for map-level CMB spectrum)
                n1_flat(optional): function used to flatten the discretized output before returning splined entire array

            Returns:
                N1 bias in the form of a numpy array of size Lmax + 1

            Note:
                This can be called with MPI using a number of processes; in this case the calculations for each multipole will be distributed among these.

        """
        if kB is None: kB = kA
        # FIXME:
        if kA[0] == 's' or kB[0] == 's':
            assert kA[0] == kB[0], 'point source implented following DH gradient convention, you wd probably need to pick a sign there'
        if ftlB is None: ftlB = ftlA
        if felB is None: felB = felA
        if fblB is None: fblB = fblA

        clttfid = self.cltt if clttfid is None else clttfid
        cltefid = self.clte if cltefid is None else cltefid
        cleefid = self.clee if cleefid is None else cleefid


        if kA in estimator_keys and kB in estimator_keys:
            if kA < kB:
                return self.get_n1(kB, k_ind, cl_kind, ftlB, felB, fblB, Lmax, ftlB=ftlA, felB=felA, fblB=fblA, kB=kA,
                                   clttfid=clttfid, cltefid=cltefid, cleefid=cleefid, n1_flat=n1_flat, sglLmode=sglLmode)

            idx = 'splined_kA' + kA + '_kB' + kB + '_ind' + k_ind
            idx += '_clpp' + clhash(cl_kind)
            idx += '_ftlA' + clhash(ftlA)
            idx += '_felA' + clhash(felA)
            idx += '_fblA' + clhash(fblA)
            idx += '_ftlB' + clhash(ftlB)
            idx += '_felB' + clhash(felB)
            idx += '_fblB' + clhash(fblB)
            idx += '_clttfid' + clhash(clttfid)
            idx += '_cltefid' + clhash(cltefid)
            idx += '_cleefid' + clhash(cleefid)
            idx += '_Lmax%s' % Lmax

            ret = self.npdb.get(idx)
            if ret is not None:
                if not recache and not remove_only:
                    return ret
                else:
                    self.npdb.remove(idx)
                    if remove_only:
                        return np.zeros_like(ret)
                    ret = None
            if ret is None:
                Ls = np.unique(np.concatenate([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], np.arange(1, Lmax + 1)[::20], [Lmax]]))
                if sglLmode:
                    n1L = np.zeros(len(Ls), dtype=float)
                    for i, L in enumerate(Ls[mpi.rank::mpi.size]):
                        print("n1: doing L %s kA %s kB %s kind %s" % (L, kA, kB, k_ind))
                        n1L[i] = (self._get_n1_L(L, kA, kB, k_ind, cl_kind, ftlA, felA, fblA, ftlB, felB, fblB, clttfid, cltefid, cleefid, remove_only=remove_only))
                    if mpi.size > 1:
                        mpi.barrier()
                        for i, L in enumerate(Ls): # reoading cached n1L's
                            n1L[i] = (self._get_n1_L(L, kA, kB, k_ind, cl_kind, ftlA, felA, fblA, ftlB, felB, fblB, clttfid,
                                             cltefid, cleefid, remove_only=remove_only))

                else: # entire vector from f90 openmp call
                    lmin_ftlA = np.min([np.where(np.abs(fal) > 0.)[0] for fal in [ftlA, felA, fblA]])
                    lmin_ftlB = np.min([np.where(np.abs(fal) > 0.)[0] for fal in [ftlB, felB, fblB]])
                    n1L = n1f.n1(Ls, cl_kind, kA, kB, k_ind, self.cltt, self.clte, self.clee,
                                 clttfid, cltefid, cleefid,  ftlA, felA, fblA, ftlB, felB, fblB,
                                  lmin_ftlA, lmin_ftlB,  self.dL, self.lps)

                ret = np.zeros(Lmax + 1)
                ret[1:] =  spline(Ls, np.array(n1L) * n1_flat(Ls), s=0., ext='raise', k=3)(np.arange(1, Lmax + 1) * 1.)
                ret[1:] *= cli(n1_flat(np.arange(1, Lmax + 1) * 1.))
                self.npdb.add(idx, ret)
                return ret
            return self.npdb.get(idx)

        if (kA in estimator_keys_derived) and (kB in estimator_keys_derived):
            ret = 0.
            for (tk1, cl1) in _get_est_derived(kA, Lmax):
                for (tk2, cl2) in _get_est_derived(kB, Lmax):
                    tret = self.get_n1(tk1, k_ind, cl_kind, ftlA, felA, fblA, Lmax, ftlB=ftlB, felB=felB, fblB=fblB,
                                       clttfid=clttfid, cltefid=cltefid, cleefid=cleefid,
                                       kB=tk2, n1_flat=n1_flat, sglLmode=sglLmode)
                    tret *= cl1[:Lmax + 1]
                    tret *= cl2[:Lmax + 1]
                    ret += tret
            return ret
        elif (kA in estimator_keys_derived) and (kB in estimator_keys):
            ret = 0.
            for (tk1, cl1) in _get_est_derived(kA, Lmax):
                tret = self.get_n1(tk1, k_ind, cl_kind, ftlA, felA, fblA, Lmax, ftlB=ftlB, felB=felB, fblB=fblB, kB=kB,
                                   clttfid=clttfid, cltefid=cltefid, cleefid=cleefid,
                                   n1_flat=n1_flat, sglLmode=sglLmode)
                tret *= cl1[:Lmax + 1]
                ret += tret
            return ret
        elif (kA in estimator_keys) and (kB in estimator_keys_derived):
            ret = 0.
            for (tk2, cl2) in _get_est_derived(kB, Lmax):
                tret = self.get_n1(kA, k_ind, cl_kind, ftlA, felA, fblA, Lmax, ftlB=ftlB, felB=felB, fblB=fblB, kB=tk2,
                                   clttfid=clttfid, cltefid=cltefid, cleefid=cleefid,
                                   n1_flat=n1_flat, sglLmode=sglLmode)
                tret *= cl2[:Lmax + 1]
                ret += tret
            return ret
        assert 0
示例#24
0
def get_nhls(qe_key1,
             qe_key2,
             cls_cmb_dat,
             cls_cmb_filt,
             cls_weight,
             lmin,
             lmax,
             lmax_qlm,
             transf,
             nlevts_filt,
             nlevts_map,
             nlevps_filt,
             nlevps_map,
             joint_TP=False,
             cacher=cachers.cacher_mem()):
    """Collects unnormalized estimator noise levels for a list of filtering noise levels and data map noise levels


        Args:
            qe_key1: first QE estimator key
            qe_key2: second QE estimator key
            cls_cmb_dat: CMB cls of the data maps
            cls_cmb_filt: CMB cls used for the filtering
            cls_weight: CMB cls in the QE weights
            lmin: minimum CMB multipole considered
            lmax: maximum CMB multipole considered
            lmax_qlm: QE output lmax
            transf: CMB transfer function
            nlevts_filt: list or array of filtering temperature noise levels
            nlevts_map: list or array of data map temperature noise levels
            nlevps_filt: list or array of filtering polarization noise levels
            nlevps_map: list or array of data maptemperature noise levels
            joint_TP: uses joint temperature and polarization filtering if set, separate if not
            cacher: can be used to store results

        Returns:
            lists of reconstruction noise levels (GG, CC, GC CG for spin-weight QE)

        Note:
            Results may be stored with the cacher but only the filtering and data noise levels, QE keys and joint_TP are differentiated in the filename

    """
    Nhls = []
    for i, (nlevt_f, nlevt_m, nlevp_f, nlevp_m) in utils.enumerate_progress(
            list(zip(nlevts_filt, nlevts_map, nlevps_filt, nlevps_map)),
            'collecting nhls'):
        fname = 'vmapnhl%s_%s_%s' % (
            'jTP' * joint_TP, qe_key1, qe_key2) + utils.clhash(
                np.array([nlevt_f, nlevt_m, nlevp_f, nlevp_m]))
        if not cacher.is_cached(fname):
            ivf_cls = get_ivf_cls(cls_cmb_dat,
                                  cls_cmb_filt,
                                  lmin,
                                  lmax,
                                  nlevt_f,
                                  nlevp_f,
                                  nlevt_m,
                                  nlevp_m,
                                  transf,
                                  jt_tp=joint_TP)[0]
            this_nhl = nhl.get_nhl(qe_key1,
                                   qe_key2,
                                   cls_weight,
                                   ivf_cls,
                                   lmax,
                                   lmax,
                                   lmax_out=lmax_qlm)
            cacher.cache(fname, this_nhl)
        Nhls.append(cacher.load(fname))
    return Nhls
示例#25
0
        def get_n1(self,
                   kA,
                   k_ind,
                   cl_kind,
                   ftlA,
                   felA,
                   fblA,
                   Lmax,
                   kB=None,
                   ftlB=None,
                   felB=None,
                   fblB=None,
                   clttfid=None,
                   cltefid=None,
                   cleefid=None,
                   n1_flat=lambda ell: np.ones(len(ell), dtype=float),
                   sglLmode=True):
            """

            """
            if kB is None: kB = kA
            # FIXME:
            if kA[0] == 's' or kB[0] == 's':
                assert kA[0] == kB[
                    0], 'point source implented following DH gradient convention, you wd probably need to pick a sign there'
            if ftlB is None: ftlB = ftlA
            if felB is None: felB = felA
            if fblB is None: fblB = fblA

            clttfid = self.cltt if clttfid is None else clttfid
            cltefid = self.clte if cltefid is None else cltefid
            cleefid = self.clee if cleefid is None else cleefid

            if kA in estimator_keys and kB in estimator_keys:
                if kA < kB:
                    return self.get_n1(kB,
                                       k_ind,
                                       cl_kind,
                                       ftlA,
                                       felA,
                                       fblA,
                                       Lmax,
                                       ftlB=ftlB,
                                       felB=felB,
                                       fblB=fblB,
                                       kB=kA,
                                       clttfid=clttfid,
                                       cltefid=cltefid,
                                       cleefid=cleefid,
                                       n1_flat=n1_flat)

                idx = 'splined_kA' + kA + '_kB' + kB + '_ind' + k_ind
                idx += '_clpp' + clhash(cl_kind)
                idx += '_ftlA' + clhash(ftlA)
                idx += '_felA' + clhash(felA)
                idx += '_fblA' + clhash(fblA)
                idx += '_ftlB' + clhash(ftlB)
                idx += '_felB' + clhash(felB)
                idx += '_fblB' + clhash(fblB)
                idx += '_clttfid' + clhash(clttfid)
                idx += '_cltefid' + clhash(cltefid)
                idx += '_cleefid' + clhash(cleefid)
                idx += '_Lmax%s' % Lmax

                if self.npdb.get(idx) is None:
                    Ls = np.unique(
                        np.concatenate([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                                        np.arange(1, Lmax + 1)[::10], [Lmax]]))
                    if sglLmode:
                        n1L = np.zeros(len(Ls), dtype=float)
                        for i, L in enumerate(Ls):
                            print("n1: doing L %s kA %s kB %s kind %s" %
                                  (L, kA, kB, k_ind))
                            n1L[i] = (self._get_n1_L(L, kA, kB, k_ind, cl_kind,
                                                     ftlA, felA, fblA, ftlB,
                                                     felB, fblB, clttfid,
                                                     cltefid, cleefid))
                    else:  # entire vector from f90 openmp call
                        lmin_ftlA = np.min([
                            np.where(np.abs(fal) > 0.)[0]
                            for fal in [ftlA, felA, fblA]
                        ])
                        lmin_ftlB = np.min([
                            np.where(np.abs(fal) > 0.)[0]
                            for fal in [ftlB, felB, fblB]
                        ])
                        n1L = n1f.n1(Ls, cl_kind, kA, kB, k_ind, self.cltt,
                                     self.clte, self.clee, clttfid, cltefid,
                                     cleefid, ftlA, felA, fblA, ftlB, felB,
                                     fblB, lmin_ftlA, lmin_ftlB, self.dL,
                                     self.lps)
                    ret = np.zeros(Lmax + 1)
                    ret[1:] = spline(Ls,
                                     np.array(n1L) * n1_flat(Ls),
                                     s=0.,
                                     ext='raise',
                                     k=3)(np.arange(1, Lmax + 1) * 1.)
                    ret[1:] *= cli(n1_flat(np.arange(1, Lmax + 1) * 1.))
                    self.npdb.add(idx, ret)
                return self.npdb.get(idx)

            assert  np.all([np.all(ftlA == ftlB), np.all(felA == felB), np.all(fblA == fblB)]), \
                    'check the est. breakdown is OK for non-identical legs'
            if (kA in estimator_keys_derived) and (kB
                                                   in estimator_keys_derived):
                ret = 0.
                for (tk1, cl1) in _get_est_derived(kA, Lmax):
                    for (tk2, cl2) in _get_est_derived(kB, Lmax):
                        tret = self.get_n1(tk1,
                                           k_ind,
                                           cl_kind,
                                           ftlA,
                                           felA,
                                           fblA,
                                           Lmax,
                                           ftlB=ftlB,
                                           felB=felB,
                                           fblB=fblB,
                                           clttfid=clttfid,
                                           cltefid=cltefid,
                                           cleefid=cleefid,
                                           kB=tk2,
                                           n1_flat=n1_flat)
                        tret *= cl1[:Lmax + 1]
                        tret *= cl2[:Lmax + 1]
                        ret += tret
                return ret
            elif (kA in estimator_keys_derived) and (kB in estimator_keys):
                ret = 0.
                for (tk1, cl1) in _get_est_derived(kA, Lmax):
                    tret = self.get_n1(tk1,
                                       k_ind,
                                       cl_kind,
                                       ftlA,
                                       felA,
                                       fblA,
                                       Lmax,
                                       ftlB=ftlB,
                                       felB=felB,
                                       fblB=fblB,
                                       kB=kB,
                                       clttfid=clttfid,
                                       cltefid=cltefid,
                                       cleefid=cleefid,
                                       n1_flat=n1_flat)
                    tret *= cl1[:Lmax + 1]
                    ret += tret
                return ret
            elif (kA in estimator_keys) and (kB in estimator_keys_derived):
                ret = 0.
                for (tk2, cl2) in _get_est_derived(kB, Lmax):
                    tret = self.get_n1(kA,
                                       k_ind,
                                       cl_kind,
                                       ftlA,
                                       felA,
                                       fblA,
                                       Lmax,
                                       ftlB=ftlB,
                                       felB=felB,
                                       fblB=fblB,
                                       kB=tk2,
                                       clttfid=clttfid,
                                       cltefid=cltefid,
                                       cleefid=cleefid,
                                       n1_flat=n1_flat)
                    tret *= cl2[:Lmax + 1]
                    ret += tret
                return ret
            assert 0
示例#26
0
 def hashdict(self):
     return {
         'clkk_inv': clhash(self.clkk_inv),
         'n_inv_filt': self.n_inv_filt.hashdict()
     }
示例#27
0
    def __init__(self,
                 n_inv,
                 b_transf,
                 b_transf_e=None,
                 b_transf_b=None,
                 marge_monopole=False,
                 marge_dipole=False,
                 marge_maps_t=(),
                 marge_maps_p=()):
        # n_inv = [util.load_map(n[:]) for n in n_inv]
        self.n_inv = []
        for i, tn in enumerate(n_inv):
            if isinstance(tn, list):
                n_inv_prod = read_map(tn[0][:])
                if len(tn) > 1:
                    for n in tn[1:]:
                        n_inv_prod = n_inv_prod * read_map(n[:])
                self.n_inv.append(n_inv_prod)
                # assert (np.std(self.n_inv[i][np.where(self.n_inv[i][:] != 0.0)]) / np.average(
                #    self.n_inv[i][np.where(self.n_inv[i][:] != 0.0)]) < 1.e-7)
            else:
                self.n_inv.append(read_map(n_inv[i]))

        n_inv = self.n_inv
        npix = len(n_inv[0])
        nside = hp.npix2nside(npix)
        for n in n_inv[1:]:
            assert (len(n) == npix)

        templates_t = []
        templates_t_hash = []
        for tmap in [read_map(m) for m in marge_maps_t]:
            assert (npix == len(tmap))
            templates_t.append(template_removal.template_map(tmap))
            templates_t_hash.append(clhash(tmap))

        if marge_monopole:
            templates_t.append(template_removal.template_monopole())
        if marge_dipole: templates_t.append(template_removal.template_dipole())

        if len(templates_t) != 0:
            nmodes = np.sum([t.nmodes for t in templates_t])
            modes_idx_t = np.concatenate(
                ([t.nmodes * [int(im)] for im, t in enumerate(templates_t)]))
            modes_idx_i = np.concatenate(
                ([range(0, t.nmodes) for t in templates_t]))

            Pt_Nn1_P = np.zeros((nmodes, nmodes))
            for ir in range(0, nmodes):
                tmap = np.copy(n_inv[0])
                templates_t[modes_idx_t[ir]].apply_mode(
                    tmap, int(modes_idx_i[ir]))

                ic = 0
                for tc in templates_t[0:modes_idx_t[ir] + 1]:
                    Pt_Nn1_P[ir, ic:(ic + tc.nmodes)] = tc.dot(tmap)
                    Pt_Nn1_P[ic:(ic + tc.nmodes),
                             ir] = Pt_Nn1_P[ir, ic:(ic + tc.nmodes)]
                    ic += tc.nmodes

            self.Pt_Nn1_P_inv = np.linalg.inv(Pt_Nn1_P)

        self.n_inv = n_inv
        self.b_transf_t = b_transf
        self.b_transf_e = b_transf_e if b_transf_e is not None else b_transf
        self.b_transf_b = b_transf_b if b_transf_b is not None else b_transf
        assert len(self.b_transf_t) == len(self.b_transf_e) and len(
            self.b_transf_t) == len(self.b_transf_e)
        self.b_transf = (self.b_transf_t + self.b_transf_e +
                         self.b_transf_t) / 3.

        self.marge_monopole = marge_monopole
        self.marge_dipole = marge_dipole

        self.templates_t = templates_t
        self.templates_t_hash = templates_t_hash

        assert len(marge_maps_p) == 0
        self.templates_p = []

        self.npix = npix
        self.nside = nside
示例#28
0
 def hashdict(self):
     return {'n_inv': [clhash(n) for n in self.n_inv],
             'b_transf': clhash(self.b_transf), 'templates_p':self.templates_p}
示例#29
0
 def hashdict(self):
     return {
         'ivfs': self.ivfs.hashdict(),
         'nside': self.nside,
         'clte': ut.clhash(self.clte)
     }
示例#30
0
 def hashdict(self):
     return {
         'sims_cmb_len': self.sims_cmb_len.hashdict(),
         'nside': self.nside,
         'cl_transf': clhash(self.cl_transf)
     }