コード例 #1
0
def interface(run=[], kwargs_cmb={}, kwargs_ov={}):

    # define parameters, filenames and functions
    aobj = local.init_analysis(**kwargs_cmb)

    # read survey window
    wind, M, wn = local.set_mask(aobj.famask)
    if aobj.fltr == 'cinv': wn[:] = wn[0]

    # generate ptsr
    if 'fg' in run and aobj.biref == 0:
        # compute signal and noise spectra but need to change file names
        q = local.init_analysis(**kwargs_cmb)
        q.fcmb.scl = q.fcmb.scl.replace('.dat', '_tmp.dat')
        q.fcmb.ocl = q.fcmb.ocl.replace('.dat', '_tmp.dat')
        if not misctools.check_path(q.fcmb.scl, **kwargs_ov):
            # compute signal and noise alms
            map2alm_all(aobj, wind, **kwargs_ov)
            alm2aps(q, wn[2], stype=['s', 'n'], cli_out=False, **kwargs_ov)
        # generate ptsr alm from obs - (sig+noi) spectrum
        gen_ptsr(aobj.rlz,
                 q.fcmb,
                 aobj.ibl,
                 aobj.fpseed,
                 aobj.fptsrcl,
                 aobj.fimap,
                 wind,
                 olmax=aobj.lmax,
                 ilmin=ilmin,
                 ilmax=ilmax,
                 **kwargs_ov)

    # use normal transform to alm
    if aobj.freq == '857':
        mtype = ['T']
    else:
        mtype = ['T', 'E', 'B']

    if aobj.fltr == 'none':

        if 'alm' in run:  # combine signal, noise and ptsr
            map2alm_all(aobj, wind, **kwargs_ov)
            alm_comb(aobj.rlz, aobj.fcmb.alms, mtype=mtype, **kwargs_ov)

        if 'aps' in run:  # compute cl
            alm2aps(aobj, wn[2], **kwargs_ov)

    # map -> alm with cinv filtering
    if aobj.fltr == 'cinv':

        if 'alm' in run:  # cinv filtering here
            wiener_cinv(aobj, M, kwargs_ov=kwargs_ov)

        if 'aps' in run:  # aps of filtered spectrum
            alm2aps(aobj, wn[0], stype=['c'], **kwargs_ov)
コード例 #2
0
ファイル: tools_qrec.py プロジェクト: toshiyan/planck-ilens
def n0_template(aobj,
                iobj,
                mb,
                quad=['TB', 'EB', 'BB']):  # template for non-zero biref
    bobj = local.init_analysis(freq=aobj.freq,
                               dtype=aobj.dtype,
                               wind=aobj.wind,
                               fltr=aobj.fltr,
                               biref=1.)
    robj = init_quad(bobj.snmax,
                     ids=bobj.ids,
                     rlz=bobj.rlz,
                     stag=bobj.stag,
                     qtypes=['ilens'],
                     rlmin=100,
                     rlmax=2048)
    yobj = cross(robj['ilens'], iobj, bobj.ids)
    Mkk = bn.binning(aobj.ckk, mb) * np.pi / 180.
    tcb = binned_spec(mb, bobj, robj, yobj, 3, doreal=False)[0]
    for q in quad:
        tcb[q] = (tcb[q] - Mkk) * .4
    return tcb
コード例 #3
0
ファイル: tools_cib.py プロジェクト: toshiyan/planck-ilens
def map2alm(iobj, W, TK=2.726, **kwargs_ov):

    nside = hp.pixelfunc.get_nside(W)
    l = np.linspace(0, iobj.lmax, iobj.lmax + 1)
    w2 = np.mean(W**2)

    for i in tqdm.tqdm(iobj.rlz,
                       ncols=100,
                       desc='map2alm (' + iobj.dtype + ',' + str(iobj.freq) +
                       ')'):

        if misctools.check_path(iobj.falm[i], **kwargs_ov): continue

        if i == 0:  # real data

            if iobj.freq == '545':
                unit = 0.0059757149 * 9113.0590
            elif iobj.freq == '857':
                unit = 9.6589431e-05 * 22533.716
            else:
                unit = 1.

            Imap = W * hp.fitsfunc.read_map(
                iobj.fcib, verbose=False) / unit / TK  # MJy/sr -> Kcmb
            Ialm = cs.utils.hp_map2alm(nside, iobj.lmax, iobj.lmax,
                                       Imap) * iobj.ibl[:, None]
            clII = cs.utils.alm2cl(iobj.lmax, Ialm) / w2

            # cross with official kappa
            aobj = local.init_analysis()
            rklm = cs.utils.lm_healpy2healpix(hp.read_alm(
                aobj.flens['MV'][0]), 4096)[:iobj.lmax + 1, :iobj.lmax + 1]

            # wfactor
            wlen = hp.read_map(aobj.flens['mask'])
            wcib = hp.read_map(iobj.famask)
            wfac = np.mean(wcib * wlen**2)

            # cross spectrum
            clIk = cs.utils.alm2cl(iobj.lmax, rklm, Ialm) / wfac

        else:  # generate sim

            clII, clIk = np.loadtxt(iobj.fcII, unpack=True, usecols=(1, 2))

            #Ialm = cs.utils.gauss1alm(iobj.lmax,clII[:iobj.lmax+1])
            aobj = local.init_analysis()
            iklm = hp.read_alm(aobj.flens['IN'][i])
            iklm = cs.utils.lm_healpy2healpix(iklm, 4096)[:iobj.lmax +
                                                          1, :iobj.lmax + 1]
            clIIs = savgol_filter(clII, 91, 0)
            clIks = savgol_filter(clIk, 91, 0)
            __, Ialm = cs.utils.gauss2alm_const(iobj.lmax, aobj.ckk, clIIs,
                                                clIks, iklm)

            # apply mask
            Imap = W * cs.utils.hp_alm2map(nside, iobj.lmax, iobj.lmax, Ialm)
            Ialm = cs.utils.hp_map2alm(nside, iobj.lmax, iobj.lmax, Imap)

        if i == 0:
            np.savetxt(iobj.fcII, np.array((l, clII, clIk)).T)

        pickle.dump((Ialm),
                    open(iobj.falm[i], "wb"),
                    protocol=pickle.HIGHEST_PROTOCOL)
コード例 #4
0
ファイル: tools_qrec.py プロジェクト: toshiyan/planck-ilens
def interface(run=['norm', 'qrec', 'n0', 'mean'],
              qtypes=['lens', 'ilens'],
              kwargs_ov={},
              kwargs_cmb={},
              kwargs_cib={},
              rlmin=100,
              rlmax=2048,
              ep=1e-30):

    aobj = local.init_analysis(**kwargs_cmb)
    iobj = tools_cib.init_cib(**kwargs_cib)

    # wfactor
    Wcmb, __, wn = local.set_mask(aobj.famask)
    Wcib = hp.fitsfunc.read_map(iobj.famask, verbose=False)
    Wlen = hp.fitsfunc.read_map(aobj.flens['mask'], verbose=False)
    wfac = {}
    wfac['II'] = np.mean(Wcib**2)
    wfac['iI'] = np.mean(Wcmb**2 * Wcib)
    wfac['kI'] = np.mean(Wlen**2 * Wcib)
    wfac['kk'] = np.mean(Wlen**4)
    wfac['ik'] = np.mean(Wcmb**2 * Wlen**2)

    #//// load obscls ////#
    if aobj.fltr == 'none':
        ocl = np.loadtxt(aobj.fcmb.scl['c'], unpack=True, usecols=(1, 2, 3, 4))
        ifl = ocl.copy()

    if aobj.fltr == 'cinv':
        # model spectra
        ncl = np.zeros((4, aobj.lmax + 1))
        ncl[0] = (aobj.ibl * aobj.sigma)**2
        ncl[1] = 2 * ncl[0]
        ncl[2] = 2 * ncl[0]
        cnl = aobj.lcl[0:4, :] + ncl
        # wiener-filtered spectrum
        wcl = (np.loadtxt(aobj.fcmb.scl['c'], usecols=(1, 2, 3, 4))).T
        # obs and inv cl
        ocl, ifl = quad_func.cinv_empirical_fltr(aobj.lcl, wcl, cnl)
        # wfactor
        wn[:] = wn[0]

    #//// define objects ////#
    qobj = init_quad(aobj.snmax,
                     qtypes,
                     ids=aobj.ids,
                     stag=aobj.stag,
                     rlz=aobj.rlz,
                     wn=wn,
                     lcl=aobj.lcl,
                     ocl=ocl,
                     ifl=ifl,
                     falm=aobj.fcmb.alms['c'],
                     rlmin=rlmin,
                     rlmax=rlmax,
                     **kwargs_ov)

    # reconstruction, cross spectrum
    for qt in qobj.keys():
        print(qt)
        qobj[qt].qrec_flow(run=run)
        if 'aps' in run:
            xobj = cross(qobj[qt], iobj, aobj.ids)
            aps(aobj.rlz, qobj[qt], xobj, wfac, aobj.flens, iobj.falm,
                **kwargs_ov)
コード例 #5
0
import numpy as np, healpy as hp, local, misctools

ascale = 1.0

#for freq in ['100','143','217','353','smica']:
#for freq in ['smica']:
for freq in ['nilc']:

    # ptsr
    Mptsr = local.mask_ptsr(freq)
    # CO
    Mco = local.mask_co_line(freq)

    for dtype in ['full', 'hm1', 'hm2']:

        for wind in ['Lens', 'LG60', 'LG40', 'LG20']:

            print(freq, dtype, wind)

            aobj = local.init_analysis(dtype=dtype,
                                       wind=wind,
                                       freq=freq,
                                       ascale=ascale)

            if misctools.check_path(aobj.famask, overwrite=True,
                                    verbose=False):
                continue

            local.create_mask(aobj, Mptsr, Mco)