Exemplo n.º 1
0
def get_qlms(_type, lib_sky, Res_TEBlms, cls_unl, lib_qlm, Res_TEBlms2=None, f=None, use_Pool=0, **kwargs):
    # FIXME : Seems to work but D_f to Reslm is a super small scale map in close to in configuration with little noise.
    # FIXME : The map B^t Covi d has spec 1 / (P + N/B^2) which can peak at a farily small scale.
    # FIXME there is probably a better way.
    """
    Stand alone qlm estimator starting from lib_sky and unlensed Cls
    Likelihood gradient (from the quadratic part).
    (B^t F^t Cov^-1 d)^a(z) (D dxi_unl/da D^t B^t F^t Cov^-1 d)_a(z)
    Only lib_skys enter this.
    Sign is correct for pot. estimate, not gradient.

    This can written as (D_f (Res lms))(z) (D_f P_a Res lms)(z) * |M_f|(z)
    Only forward displacement is needed.

    Res lms is here D^t B^t Cov^-1 data. This can be written in general
    as  D^t B^t Ni (data - B D MLIK(data)) in T E B space. For non-singular modes
    this may be written as P_TEB^{-1} MLIK. (but we can't use pseudo inverse
    for singular modes.)
    P_a Res lms are always the max. likelihood modes however.
    N0  * output is normalized qest for MV estimates

    1/2 (VX WY  +  VY WX)
    1/2 VX WY  +  VY WX

    1/4 (VVt WW^t + VVt WWt + WV^t VW^t + V W^t WV^t)

    We can get something without having to lens any weird maps through
    ( B^t Ni (data - B D Xmap))(z)    (D Xmap)(z)
    """
    _Res_TEBlms2 = Res_TEBlms if Res_TEBlms2 is None else Res_TEBlms2
    assert len(Res_TEBlms) == len(_type) and len(_Res_TEBlms2) == len(_type)
    t = fs.misc.misc_utils.timer(verbose, prefix=__name__)
    if f is not None: print " qlms.py :: consider using get_qlms_wl for qlms with lensing, to avoid lensing noisy maps"
    if f is None: f = fs.ffs_deflect.ffs_deflect.ffs_id_displacement(lib_sky.shape, lib_sky.lsides)

    TQUmlik = SM.TEB2TQUlms(_type, lib_sky, SM.apply_TEBmat(_type, lib_sky, cls_unl, _Res_TEBlms2))

    def left(S_id):
        assert S_id in range(len(_type)), (S_id, _type)
        return f.alm2lenmap(lib_sky, SM.get_SlmfromTEBlms(_type, lib_sky, Res_TEBlms, _type[S_id]), use_Pool=use_Pool)

    def Right(S_id, axis):
        assert S_id in range(len(_type)), (S_id, _type)
        assert axis in [0, 1]
        kfunc = lib_sky.get_ikx if axis == 1 else lib_sky.get_iky
        return f.alm2lenmap(lib_sky, TQUmlik[S_id] * kfunc(), use_Pool=use_Pool)

    retdx = left(0) * Right(0, 1)
    for _i in range(1, len(_type)): retdx += left(_i) * Right(_i, 1)
    retdx = lib_qlm.map2alm(f.mult_wmagn(retdx))
    t.checkpoint("get_likgrad::Cart. gr. x done. (%s map(s) lensed, %s fft(s)) " % (2 * len(_type), 2 * len(_type) + 1))

    retdy = left(0) * Right(0, 0)
    for _i in range(1, len(_type)): retdy += left(_i) * Right(_i, 0)
    retdy = lib_qlm.map2alm(f.mult_wmagn(retdy))
    t.checkpoint("get_likgrad::Cart. gr. y done. (%s map(s) lensed, %s fft(s)) " % (2 * len(_type), 2 * len(_type) + 1))

    return np.array([- retdx * lib_qlm.get_ikx() - retdy * lib_qlm.get_iky(),
                     retdx * lib_qlm.get_iky() - retdy * lib_qlm.get_ikx()])  # N0  * output is normalized qest
Exemplo n.º 2
0
 def __call__(self, TEBlms):
     TQUlms = SM.TEB2TQUlms(_type, self.cov.lib_skyalm, TEBlms)
     for i, f in enumerate(_type):
         self.cov.apply_alm(f, TQUlms[i], inplace=True)
     ret = SM.apply_pinvTEBmat(_type, self.lib_alm, self.cov.cls,
                               TEBlms) + SM.TQU2TEBlms(
                                   _type, self.lib_alm, TQUlms)
     return filtTEBlms(ret, self.cov)
Exemplo n.º 3
0
def apply_fini_BINV(soltn, cov, maps, **kwargs):
    """
    Output TEB skyalms shaped
    B^t Cov^-1 d = B^t Ni data - (B^t Ni B) MLIK(data)
             = B^t Ni (data - B MLIK(data))
    """
    TQUmlik = SM.TEB2TQUlms(_type, cov.lib_skyalm,
                            apply_fini_MLIK(soltn, cov, maps, **kwargs))
    for i, f in enumerate(_type):
        _map = maps[i] - cov.apply_R(f, TQUmlik[i])
        cov.apply_map(f, _map, inplace=True)
        TQUmlik[i] = cov.apply_Rt(f, _map)
    del _map
    return SM.TQU2TEBlms(_type, cov.lib_skyalm, TQUmlik)
Exemplo n.º 4
0
def MLIK2BINV(soltn, cov, maps, **kwargs):
    """
    Output TEB skyalms shaped
    R^t Cov^-1 d = R^t Ni data - (R^t Ni R) MLIK(data)
             = R^t Ni (data - R MLIK(data))
    """
    assert len(soltn) == TEBlen(_type)
    assert len(maps) == TQUlen(_type)
    TQUmlik = SM.TEB2TQUlms(_type, cov.lib_skyalm, soltn)
    for i, f in enumerate(_type):
        _map = maps[i] - cov.apply_R(f, TQUmlik[i])
        cov.apply_map(f, _map, inplace=True)
        TQUmlik[i] = cov.apply_Rt(f, _map)
    del _map
    return SM.TQU2TEBlms(_type, cov.lib_skyalm, TQUmlik)
Exemplo n.º 5
0
 def apply_Rs(self, TQUtype, TEBlms):
     """
     Apply transfer function, T E B skyalm to T Q U map.
     """
     assert TQUtype in ['T', 'QU', 'TQU']
     TEBtype = {'T': 'T', 'QU': 'EB', 'TQU': 'TEB'}[TQUtype]
     assert TEBlms.shape == (len(TEBtype), self.lib_skyalm.alm_size), (
         TEBlms.shape, TEBtype, self.lib_skyalm.alm_size)
     ret = np.zeros((len(TEBtype), self.lib_datalm.alm_size), dtype=complex)
     for i, f in enumerate(TEBtype):
         for j, g in enumerate(TEBtype):
             cl_t = self.cltransf_dict.get(g + f, None)
             if cl_t is not None:
                 ret[i] += self._deg(self.lib_skyalm.almxfl(
                     TEBlms[j], cl_t))
     return np.array([
         self.lib_datalm.alm2map(alm)
         for alm in ffs_specmat.TEB2TQUlms(TQUtype, self.lib_datalm, ret)
     ])
Exemplo n.º 6
0
def soltn2TQUMlik(soltn, cov):
    assert len(soltn) == TEBlen(_type)
    return SM.TEB2TQUlms(_type, cov.lib_skyalm, soltn)