def load_ivar_curvedsky(aobj):

    if aobj.ivar == 'vc':
        if '16' in aobj.wind:
            return hp.fitsfunc.read_map(aobj.fivar16, verbose=False)
        elif '15' in aobj.wind:
            return hp.fitsfunc.read_map(aobj.fivar15, verbose=False)
        else:
            sys.exit('ivar is not well defined')
    elif aobj.ivar == 'vd':
        ivar = enmap.read_map(aobj.fivarvd)
        return enmap.to_healpix(ivar[0], nside=aobj.nside)
    elif aobj.ivar == 'v3':
        ivar = enmap.read_map(local.init_analysis_params(qid='boss_d03').fivar)
        return enmap.to_healpix(ivar[0], nside=aobj.nside)
    elif aobj.ivar == 'V3':
        ivar = enmap.read_map(
            local.init_analysis_params(qid='boss_d03').fivar)**2
        return enmap.to_healpix(ivar[0], nside=aobj.nside)
    elif aobj.ivar == 'noivar':
        return 1.
    elif aobj.ivar == 'base':
        ivar = enmap.read_map(aobj.fivar)
        return enmap.to_healpix(ivar[0], nside=aobj.nside)
    else:
        sys.exit('ivar is not well defined')
Esempio n. 2
0
def interface(run=[], kwargs={}, kwargs_ov={}):

    aobj = local.init_analysis_params(**kwargs)

    if 'map' in run:
        generate_map(aobj, **kwargs_ov)

    if 'alm' in run:
        map2alm(aobj, **kwargs_ov)

    if 'aps' in run:
        alm2aps(aobj, **kwargs_ov)
def alm_comb(qids,
             qidc,
             overwrite=False,
             verbose=True,
             mtypes=['T', 'E', 'B'],
             ep=1e-30,
             **kwargs):

    # qids = qid to be combined
    # qidc = output qid

    aobj = {
        q: local.init_analysis_params(qid=q, **kwargs)
        for q in qids + [qidc]
    }
    mid = {'T': 1, 'E': 2, 'B': 3}

    ncl = {}
    Ncl = {}
    for mi, m in mtype:
        # pre-computed noise spectra for inverse-variance weighting
        ncl[m] = {q: (np.loadtxt(aobj[q].fscl['n'])).T[mid[m]] for q in qids}
        # norm
        Ncl[m] = comb_Nl(qids, ncl)

    for rlz in tqdm.tqdm(aobj[qids[0]].rlz, desc='combine alms'):

        for m in mtype:

            if misctools.check_path(
                [aobj[qidc].falm['c'][m][rlz], aobj[qidc].falm['n'][m][rlz]],
                    overwrite=overwrite,
                    verbose=verbose):
                continue

            walm = {}
            for s in ['c', 'n']:

                if rlz == 0 and s in ['n']: continue
                walm[s, m] = 0.
                for q in qids:
                    # walm = 1/N alm = 1/(N/r^2) alm/r
                    walm[s, m] += 1. / ncl[m][q][:, None] * pickle.load(
                        open(aobj[q].falm[s][m][rlz], "rb"))  #/ w1[q]
                    #wTlm[s,m] += rcl[q][:,None]/(ncl[q][:,None]+ep) * pickle.load(open(aobj[q].falm[s]['T'][rlz],"rb")) #/ w1[q]
                    walm[s, m][:2, :] = 0.

                walm[s, m] *= Ncl[m][:, None]
                # save alm for each rlz
                pickle.dump((walm[s, m]),
                            open(aobj[qidc].falm[s][m][rlz], "wb"),
                            protocol=pickle.HIGHEST_PROTOCOL)
def get_wfactors(qids,
                 ascale,
                 wind='base',
                 ivar='base',
                 ptsr='base',
                 fltr='none',
                 with_ivar=True,
                 ivar_norm=False,
                 wnmax=5):
    w = {}
    for q in qids:
        aobj = local.init_analysis_params(qid=q,
                                          ascale=ascale,
                                          wind=wind,
                                          ivar=ivar,
                                          ptsr=ptsr,
                                          fltr=fltr)
        mask = load_window_curvedsky(aobj,
                                     with_ivar=with_ivar,
                                     ivar_norm=ivar_norm)
        w[q] = get_wfactor(mask, wnmax=wnmax)
    return w
def wiener_cinv_core(qids,
                     wqid,
                     white=False,
                     kwargs_ov={
                         'overwrite': False,
                         'verbose': True
                     },
                     kwargs_cmb={},
                     kwargs_cinv={}):

    # parameter
    vb = kwargs_ov['verbose']

    # specify output filename
    aobj = local.init_analysis_params(qid=wqid, **kwargs_cmb)

    # input CMB data
    Aobj = {q: local.init_analysis_params(qid=q, **kwargs_cmb) for q in qids}

    mn = len(qids)
    bl = np.zeros((mn, aobj.lmax + 1))
    Nij = np.zeros((1, mn, aobj.npix))
    mask = {}
    inl = np.ones((1, mn, aobj.lmax + 1))

    for i, q in enumerate(qids):

        # beam
        bl[i, :] = beam_func(Aobj[q].lmax, Aobj[q].qid)

        # binary mask
        mask[q] = load_window_curvedsky(Aobj[q], with_ivar=False)
        mask[q][mask[q] != 0] = 1.

        # inv noise covariance
        #os.system('echo "'+q+',constructing noise covariance" >> test.txt')
        if vb: print(q, 'constructing noise covariance')

        Nvar = load_ivar_curvedsky(Aobj[q])

        if white:

            Nij[0,
                i, :] = mask[q] * Nvar / np.max(Nvar) / local.qid_wnoise(q)**2

        else:

            if q in local.boss_d:
                # averaged noise spectrum at S16 region
                bobj = local.init_analysis_params(qid=q,
                                                  fltr='none',
                                                  wind='com16',
                                                  ivar='base',
                                                  ptsr=aobj.ptsr)
            if q in local.boss_n or q in local.s_16_d:
                bobj = local.init_analysis_params(qid=q,
                                                  fltr='none',
                                                  wind='base',
                                                  ivar='base',
                                                  ptsr=aobj.ptsr)

            Nl = np.loadtxt(bobj.fscl['n'], unpack=True)[1]
            inl[0, i, 2:] = 1. / (Nl[2:] * bl[i, 2:]**2)
            Nvar[Nvar <= 0] = 1e-60
            Nij[0, i, :] = mask[q] * np.sqrt(
                Nvar / np.max(Nvar))  #/ local.qid_wnoise(q)

        del Nvar

    # temperature map
    T = np.zeros((1, mn, aobj.npix))

    for rlz in aobj.rlz:

        if misctools.check_path(aobj.falm['c']['T'][rlz], **kwargs_ov):
            continue

        #os.system('echo "'+str(rlz)+',loading temperature obs map" >> test.txt')
        if rlz == 0:
            for i, q in enumerate(qids):
                if vb: print(rlz, q, 'loading temperature obs map')
                Tc = enmap.read_map(Aobj[q].fmap['s'][rlz])[0]
                T[0, i, :] = mask[q] * enmap.to_healpix(remove_lxly(
                    Tc, lmin=aobj.clmin, lmax=aobj.lmax),
                                                        nside=aobj.nside)
        else:
            for i, q in enumerate(qids):
                if vb: print(rlz, q, 'loading temperature sim map')
                Ts = enmap.read_map(Aobj[q].fmap['s'][rlz])[0]
                Tn = enmap.read_map(Aobj[q].fmap['n'][rlz])[0]
                T[0, i, :] = mask[q] * enmap.to_healpix(remove_lxly(
                    Ts + Tn, lmin=aobj.clmin, lmax=aobj.lmax),
                                                        nside=aobj.nside)

        # cinv
        if vb: print('cinv filtering')
        #os.system('echo "cinv filter" >> test.txt')
        if white:
            Tlm = curvedsky.cninv.cnfilter_freq(1,
                                                mn,
                                                aobj.nside,
                                                aobj.lmax,
                                                aobj.lcl[0:1, :],
                                                bl,
                                                Nij,
                                                T,
                                                verbose=kwargs_ov['verbose'],
                                                **kwargs_cinv)
        else:
            Tlm = curvedsky.cninv.cnfilter_freq(1,
                                                mn,
                                                aobj.nside,
                                                aobj.lmax,
                                                aobj.lcl[0:1, :],
                                                bl,
                                                Nij,
                                                T,
                                                verbose=kwargs_ov['verbose'],
                                                inl=inl,
                                                **kwargs_cinv)
        pickle.dump((Tlm[0, :, :]),
                    open(aobj.falm['c']['T'][rlz], "wb"),
                    protocol=pickle.HIGHEST_PROTOCOL)
def diff_day_night(qid_d,
                   qid_n,
                   qid,
                   overwrite=False,
                   verbose=True,
                   mtype=['T'],
                   **kwargs):

    aobj = {
        q: local.init_analysis_params(qid=q, **kwargs)
        for q in [qid_d, qid_n, qid]
    }
    cl = {
        s: np.zeros((len(aobj[qid].rlz), 6, aobj[qid].lmax + 1))
        for s in ['c', 's', 'n']
    }

    for ii, rlz in enumerate(tqdm.tqdm(aobj[qid_d].rlz, desc='day - night')):

        if misctools.check_path(aobj[qid].falm['c']['T'][rlz],
                                overwrite=overwrite,
                                verbose=verbose):
            continue

        for s in ['c', 's', 'n']:

            if rlz == 0 and s in ['s', 'n']: continue

            # empirical Window correction from each day and night masks
            if s in ['s']:
                calm0 = pickle.load(open(aobj[qid_d].falm['c']['T'][rlz],
                                         "rb"))
                calm1 = pickle.load(open(aobj[qid_n].falm['c']['T'][rlz],
                                         "rb"))
                nalm0 = pickle.load(open(aobj[qid_d].falm['n']['T'][rlz],
                                         "rb"))
                nalm1 = pickle.load(open(aobj[qid_n].falm['n']['T'][rlz],
                                         "rb"))
                Talm0 = calm0 - nalm0
                Talm1 = calm1 - nalm1
            else:
                Talm0 = pickle.load(open(aobj[qid_d].falm[s]['T'][rlz], "rb"))
                Talm1 = pickle.load(open(aobj[qid_n].falm[s]['T'][rlz], "rb"))

            dTalm = Talm0 - Talm1

            if s == 'c':
                pickle.dump(dTalm,
                            open(aobj[qid].falm[s]['T'][rlz], "wb"),
                            protocol=pickle.HIGHEST_PROTOCOL)

            # aps
            cl[s][ii, 0, :] = curvedsky.utils.alm2cl(aobj[qid].lmax, dTalm)

            # save cl for each rlz
            np.savetxt(
                aobj[qid].fcls[s][rlz],
                np.concatenate((aobj[qid].l[None, :], cl[s][ii, :, :])).T)

    # save mean cl to files
    if aobj[qid].rlz[-1] >= 2:
        if verbose: print('save averaged diff day-night spectrum')
        imin = max(0, 1 - aobj[qid].rlz[0])
        for s in ['c', 's', 'n']:
            np.savetxt(
                aobj[qid].fscl[s],
                np.concatenate(
                    (aobj[qid].l[None, :], np.mean(cl[s][imin:, :, :], axis=0),
                     np.std(cl[s][imin:, :, :], axis=0))).T)
def alm2aps(qids,
            overwrite=False,
            verbose=True,
            mtype=['T', 'E', 'B'],
            cns=['c', 'n', 's'],
            W2=None,
            **kwargs):

    for qid in qids:

        aobj = local.init_analysis_params(qid=qid, **kwargs)
        if aobj.fltr == 'cinv': cns = ['c']

        if W2 is None:
            mask = load_window_curvedsky(aobj)
            w2 = get_wfactor(mask)[2]
        else:
            if isinstance(W2, dict):
                w2 = W2[qid]
            else:
                w2 = W2

        cl = {s: np.zeros((len(aobj.rlz), 6, aobj.lmax + 1)) for s in cns}

        for ii, rlz in enumerate(tqdm.tqdm(aobj.rlz, desc='alm -> aps')):

            if misctools.check_path(aobj.fcls['c'][rlz],
                                    overwrite=overwrite,
                                    verbose=verbose):
                continue

            if rlz == 0:
                alms = {
                    m: pickle.load(open(aobj.falm['c'][m][rlz], "rb"))
                    for m in mtype
                }
                cl['c'][ii, :, :] = alm2aps_core(aobj.lmax, alms, w2=w2)
            else:
                for s in cns:
                    if s == 's':
                        continue  # signal part will be computed from combined - noise
                    alms = {
                        m: pickle.load(open(aobj.falm[s][m][rlz], "rb"))
                        for m in mtype
                    }
                    cl[s][ii, :, :] = alm2aps_core(aobj.lmax, alms, w2=w2)

                # signal part
                if 's' in cns:
                    # combined - noise = signal
                    alms = {
                        m: pickle.load(open(aobj.falm['c'][m][rlz], "rb")) -
                        pickle.load(open(aobj.falm['n'][m][rlz], "rb"))
                        for m in mtype
                    }
                    cl['s'][ii, :, :] = alm2aps_cor(aobj.lmax, alms, w2=w2)

            # save cl for each rlz
            np.savetxt(aobj.fcls['c'][rlz],
                       np.concatenate((aobj.l[None, :], cl['c'][ii, :, :])).T)
            if rlz >= 1:
                if 's' in cns:
                    np.savetxt(
                        aobj.fcls['s'][rlz],
                        np.concatenate((aobj.l[None, :], cl['s'][ii, :, :])).T)
                if 'n' in cns:
                    np.savetxt(
                        aobj.fcls['n'][rlz],
                        np.concatenate((aobj.l[None, :], cl['n'][ii, :, :])).T)

        # save mean cl to files
        if aobj.rlz[-1] >= 2:
            if verbose: print('save averaged spectrum over rlz')
            imin = max(0, 1 - aobj.rlz[0])
            for s in cns:
                if misctools.check_path(aobj.fscl[s],
                                        overwrite=overwrite,
                                        verbose=verbose):
                    continue
                np.savetxt(
                    aobj.fscl[s],
                    np.concatenate(
                        (aobj.l[None, :], np.mean(cl[s][imin:, :, :], axis=0),
                         np.std(cl[s][imin:, :, :], axis=0))).T)
def map2alm(qids, overwrite=False, verbose=True, ascale=1., **kwargs):

    # loop over qid
    for q in qids:

        aobj = local.init_analysis_params(qid=q, ascale=ascale, **kwargs)

        # beam
        Bl = beam_func(aobj.lmax, q)

        # total mask
        mask = load_window_curvedsky(aobj)

        # loop for map -> alm
        for i in tqdm.tqdm(aobj.rlz, desc='map -> alm'):

            for tp in ['T', 'P']:

                if tp == 'T' and misctools.check_path(aobj.falm['c']['T'][i],
                                                      overwrite=overwrite,
                                                      verbose=verbose):
                    continue
                if tp == 'P' and misctools.check_path(
                    [aobj.falm['c']['E'][i], aobj.falm['c']['B'][i]],
                        overwrite=overwrite,
                        verbose=verbose):
                    continue

                if i == 0:

                    if tp == 'T':
                        Tmap_c = enmap.read_map(aobj.fmap['s'][i])[0]
                        Talm_c = map2alm_core(Tmap_c, aobj, mask) / Bl[:, None]
                        pickle.dump((Talm_c),
                                    open(aobj.falm['c']['T'][i], "wb"),
                                    protocol=pickle.HIGHEST_PROTOCOL)

                    if tp == 'P':
                        Qmap_c = enmap.read_map(aobj.fmap['s'][i])[1]
                        Umap_c = enmap.read_map(aobj.fmap['s'][i])[2]
                        Ealm_c, Balm_c = map2alm_core_spin(
                            Qmap_c, Umap_c, aobj, mask) / Bl[:, None]
                        pickle.dump((Ealm_c),
                                    open(aobj.falm['c']['E'][i], "wb"),
                                    protocol=pickle.HIGHEST_PROTOCOL)
                        pickle.dump((Balm_c),
                                    open(aobj.falm['c']['E'][i], "wb"),
                                    protocol=pickle.HIGHEST_PROTOCOL)

                else:

                    if tp == 'T':
                        Tmap_s = enmap.read_map(aobj.fmap['s'][i])[0]
                        Tmap_n = enmap.read_map(aobj.fmap['n'][i])[0]
                        Talm_s = map2alm_core(Tmap_s, aobj, mask) / Bl[:, None]
                        Talm_n = map2alm_core(Tmap_n, aobj, mask) / Bl[:, None]
                        pickle.dump((Talm_n),
                                    open(aobj.falm['n']['T'][i], "wb"),
                                    protocol=pickle.HIGHEST_PROTOCOL)
                        pickle.dump((Talm_s + Talm_n),
                                    open(aobj.falm['c']['T'][i], "wb"),
                                    protocol=pickle.HIGHEST_PROTOCOL)

                    if tp == 'P':

                        Qmap_s = enmap.read_map(aobj.fmap['s'][i])[1]
                        Qmap_n = enmap.read_map(aobj.fmap['n'][i])[1]
                        Umap_s = enmap.read_map(aobj.fmap['s'][i])[2]
                        Umap_n = enmap.read_map(aobj.fmap['n'][i])[2]

                        Ealm_s, Balm_s = map2alm_core_spin(
                            Qmap_s, Umap_s, aobj, mask) / Bl[:, None]
                        Ealm_n, Balm_n = map2alm_core_spin(
                            Qmap_n, Umap_n, aobj, mask) / Bl[:, None]

                        pickle.dump((Ealm_n),
                                    open(aobj.falm['n']['E'][i], "wb"),
                                    protocol=pickle.HIGHEST_PROTOCOL)
                        pickle.dump((Ealm_s + Ealm_n),
                                    open(aobj.falm['c']['E'][i], "wb"),
                                    protocol=pickle.HIGHEST_PROTOCOL)
                        pickle.dump((Balm_n),
                                    open(aobj.falm['n']['B'][i], "wb"),
                                    protocol=pickle.HIGHEST_PROTOCOL)
                        pickle.dump((Balm_s + Balm_n),
                                    open(aobj.falm['c']['B'][i], "wb"),
                                    protocol=pickle.HIGHEST_PROTOCOL)
def generate_map(qids, overwrite=False, verbose=True, dg=2, **kwargs):
    # Here we compute the real coadd map and simulated maps from the noise covariance and pre-computed fullsky signal
    # This function uses actsims "simgen" code

    for qid in qids:

        if qid in ['boss_d04', 's16_d03', 'boss_04']:
            # Here, the simulation is performed for each array, not frequency, to take into account their correlation
            # For pa3, there are two frequency bands
            if verbose:
                print('skip ' + qid +
                      ': the map is generated by running f090 case.')
            continue

        if '_d0' in qid:
            version = 'v6.3.0_calibrated_mask_version_masks_20200723'
        else:
            version = 'v6.3.0_calibrated_mask_version_padded_v1'

        # define qid_array to take into account multi-frequency case
        if qid == 'boss_d03':
            qid_array = ['boss_d03', 'boss_d04']
        elif qid == 's16_d02':
            qid_array = ['s16_d02', 's16_d03']
        elif qid == 'boss_03':
            qid_array = ['boss_03', 'boss_04']
        else:
            # single frequency case
            qid_array = [qid]

        # define filename
        aobj = {
            q: local.init_analysis_params(qid=q, **kwargs)
            for q in qid_array
        }

        # load survey mask
        mask = load_survey_mask(qid, dg=1)

        # Define an object for sim generation
        model, season, array, patch, freq = local.qid_info(qid)
        if model == 'dr5':
            simobj = simgen.SimGen(version=version, qid=qid_array, model=model)
        if model == 'act_mr3':
            simobj = simgen.SimGen(version=version, model=model)

        # save 1/var map
        if not misctools.check_path(aobj[qid_array[0]].fivar,
                                    overwrite=overwrite,
                                    verbose=verbose):
            ivars = get_ivar(qid_array, mask)
            civars = np.average(ivars, axis=1)  # coadd ivar
            for qi, q in enumerate(qid_array):
                enmap.write_map(aobj[q].fivar, civars[qi, :, :, :])

        # loop over realizations
        for i in tqdm.tqdm(aobj[qid].rlz):

            if misctools.check_path(aobj[qid].fmap['s'][i],
                                    overwrite=overwrite,
                                    verbose=verbose):
                continue

            # maps will have signal ('s') and noise ('n') and each has [Nfreq, NTPol, Coord1, Coord2]
            maps = {}

            # real data
            if i == 0:

                # take coadd data
                maps['s'] = coadd_real_data(qid_array, mask)

                # SZ map subtraction
                shape, wcs = maps['s'][0, 0, :, :].shape, maps['s'].wcs
                if q in [
                        'boss_d03', 's16_d02', 'boss_03'
                ]:  # need both freqs for combined data array of two freqs
                    sz_map_090 = enmap.project(
                        enmap.read_map(
                            'data_local/input/S18d_202006_confirmed_model_f090.fits'
                        ), shape, wcs) / local.Tcmb
                    sz_map_150 = enmap.project(
                        enmap.read_map(
                            'data_local/input/S18d_202006_confirmed_model_f150.fits'
                        ), shape, wcs) / local.Tcmb
                    maps['s'][0, 0, :, :] -= sz_map_090
                    maps['s'][1, 0, :, :] -= sz_map_150
                else:
                    sz_map = enmap.project(
                        enmap.read_map(
                            'data_local/input/S18d_202006_confirmed_model_f150.fits'
                        ), shape, wcs) / local.Tcmb
                    maps['s'][0, 0, :, :] -= sz_map

            # simulation
            else:
                maps['s'], maps['n'], ivars = simobj.get_sim(season,
                                                             patch,
                                                             array,
                                                             sim_num=i,
                                                             set_idx=0)

                # coadd with civars weight implicitly multiplied
                civars = np.average(ivars, axis=1)
                civars[civars == 0] = np.inf
                maps['s'] = mask[None, None, :, :] * np.average(
                    maps['s'] * ivars, axis=1) / civars / local.Tcmb
                maps['n'] = mask[None, None, :, :] * np.average(
                    maps['n'] * ivars, axis=1) / civars / local.Tcmb

                # downgrade
                maps['s'] = enmap.downgrade(maps['s'], dg)
                maps['n'] = enmap.downgrade(maps['n'], dg)

            # save signal and noise to files
            for s in ['s', 'n']:
                if s == 'n' and i == 0:
                    continue  # real data is saved to a signal file
                for qi, q in enumerate(qid_array):
                    enmap.write_map(aobj[q].fmap[s][i], maps[s][qi, :, :, :])
Esempio n. 10
0
#!/usr/bin/env python
# coding: utf-8

import numpy as np, healpy as hp, curvedsky as cs, sys, local, tools_cmb
from pixell import enmap

for wtype in ['comdy']:
    #for wtype in ['com15','com16']:

    aobj = local.init_analysis_params(qid='boss_d03', ascale=3., wtype=wtype)

    if wtype in ['com15', 'com16']:
        amask = hp.fitsfunc.read_map(aobj.amask)
        amask[amask != 0] = 1.
    else:
        amask = 1.

    if wtype == 'com16':
        qids = local.qid_all
        fivar = aobj.fivar16
    if wtype == 'com15':
        qids = local.boss_dn
        fivar = aobj.fivar15
    if wtype == 'comdy':
        qids = local.day_all
        fivar = aobj.fivarvd

    var = 0.
    for q in qids:
        ivars = enmap.read_map(local.init_analysis_params(qid=q).fivar)
        ivars = enmap.to_healpix(ivars[0], nside=aobj.nside)
Esempio n. 11
0
def interface(qid,run=['norm','qrec','n0','mean','aps'],mean_sub=True,kwargs_ov={},kwargs_cmb={},kwargs_qrec={}):

    aobj = local.init_analysis_params(qid=qid,**kwargs_cmb)
    
    if qid == 'diff_dn':
        aobj_c = local.init_analysis_params(qid='comb_dn',**kwargs_cmb)
    else:
        # same as aobj
        aobj_c = local.init_analysis_params(qid=qid,**kwargs_cmb)

    if aobj.fltr == 'cinv':

        # filter
        ep  = 1e-30
        
        # noise
        if aobj.qid in local.wqids:
            nl = 0.
            qids = local.get_subqids(aobj.qid)
            for q in qids:
                if q in local.boss_d:
                    bobj = local.init_analysis_params(qid=q,fltr='none',wind='com16',ivar='base')
                if q in local.boss_n or q in local.s_16_d:
                    bobj = local.init_analysis_params(qid=q,fltr='none',wind='base',ivar='base')
                nl += 1. / ( np.loadtxt(bobj.fscl['n'],unpack=True)[1] + ep )
            nl = 1./(nl+ep)
            # load wfactors
            print('computing W factor')
            W = 1.
            for q in qids:
                W *= 1. - enmap.to_healpix(tools_cmb.load_survey_mask(q),nside=aobj.nside)
            wn = np.zeros(5)
            wn[0] = np.mean(1.-W)
            wn[:] = wn[0]
            print('W factor:',wn[0])
        else:
            # white
            bl  = tools_cmb.beam_func(aobj.lmax,aobj.qid)
            nl  = ( local.qid_wnoise(qid) / bl )**2
            wn = tools_cmb.get_wfactors([aobj.qid],aobj.ascale,wind=aobj.wind,ivar=aobj.ivar,ptsr=aobj.ptsr,fltr=aobj.fltr)[aobj.qid]
            wn[:] = wn[0]
        
        # corrected factors
        cnl = aobj.lcl[0,:] + nl
        #wcl = (np.loadtxt(aobj.fscl['c'])).T[1] # wiener-fileterd CMB aps
        #ocl, ifl = quad_func.cinv_empirical_fltr(aobj.lcl[0,:],wcl,cnl)
        #ocl = np.reshape( aobj.lcl[0,:]**2/(wcl+ep) ,(1,aobj.lmax+1) )
        ocl = np.reshape( cnl ,(1,aobj.lmax+1) )
        ifl = np.reshape( aobj.lcl[0,:], (1,aobj.lmax+1) )

        #wn = tools_cmb.get_wfactors([aobj.qid],1.,wind='base',ptsr=aobj.ptsr,fltr='cinv')[aobj.qid]

    else:

        # load wfactors
        wn = tools_cmb.get_wfactors([aobj.qid],aobj.ascale,wind=aobj.wind,ivar=aobj.ivar,ptsr=aobj.ptsr,fltr=aobj.fltr)[aobj.qid]

        # filter
        ocl = np.ones((3,aobj_c.lmax+1))
        ocl[0,:] = (np.loadtxt(aobj_c.fscl['c'])).T[1]
        ifl = ocl.copy()
    

    dirs = local.data_directory()
    qobj = quad_func.reconstruction(dirs['local'],aobj.ids,rlz=aobj.rlz,stag=aobj.stag,run=run,wn=wn,lcl=aobj.lcl,ocl=ocl,ifl=ifl,falm=aobj.falm['c'],**kwargs_ov,**kwargs_qrec)

    # Aps of reconstructed phi
    if 'aps' in run:
        aps(qobj,aobj.rlz,aobj.fiklm,wn,mean_sub=mean_sub)
Esempio n. 12
0
#!/usr/bin/env python
# coding: utf-8

import numpy as np
import local
import tools_cmb

# global fixed parameters
kwargs = {'snmin':0,'snmax':100,'ascale':3.0,'wtype':'com15'}
kwargs_ov = {'overwrite':True,'verbose':False}

kwargs_qrec0 = {'n0max':50,'mfmax':100,'rlmin':500,'qlist':['TT'],'bhe':['src']}
kwargs_qrec1 = {'n0max':50,'mfmax':100,'rlmin':500,'qlist':['TT']}

run_cmb = ['map','alm','aps']


tools_cmb.interface(run_cmb,kwargs=kwargs,kwargs_ov=kwargs_ov)

for kwargs_qrec in [kwargs_qrec0,kwargs_qrec1]:
    aobj = local.init_analysis_params(**kwargs)
    tools_lens.interface(aobj,run=['norm','qrec','n0','rdn0','mean','aps'],kwargs_ov=kwargs_ov,kwargs_qrec=kwargs_qrec)

Esempio n. 13
0
#!/usr/bin/env python
# coding: utf-8

import numpy as np, healpy as hp, curvedsky as cs, sys, local, tools_cmb

sys.path.append("/global/homes/t/toshiyan/Work/Lib/actlib/actsims/")
sys.path.append("/global/homes/t/toshiyan/Work/Lib/actlib/soapack/")
sys.path.append("/global/homes/t/toshiyan/Work/Lib/actlib/")
sys.path.append("/global/homes/t/toshiyan/Work/Lib/actlib/orphics/")
sys.path.append("/global/homes/t/toshiyan/Work/Lib/actlib/tilec/")
from pixell import enmap
from soapack import interfaces

#qids = ['boss_dcom15','boss_com15','boss_dcom16','boss_com']

aobj = {q: local.init_analysis_params(qid=q, ascale=ap) for q in local.qid_all}

mask = {}

for q in qids:
    mask_iv = tools_cmb.load_mask(q, with_ivar=False)
    mask[q] = enmap.to_healpix(mask_iv, nside=2048)

if wqid == 'boss_dcom15':
    mask['boss_d03']
    hp.fitsfunc.write_map(aobj_dcom15.amask, mask, overwrite=True)
Esempio n. 14
0
#!/usr/bin/env python
# coding: utf-8

import numpy as np, sys, os
import local
import tools_lens
import quad_func

kwargs = {'snmin':1,'snmax':50,'ascale':3.0,'wtype':'com16v3pt'}
kwargs_ov = {'overwrite':False}
kwargs_qrec0 = {'n0max':50,'mfmax':100,'rlmin':500,'qlist':['TT'],'rd4sim':True}

for kwargs_qrec in [kwargs_qrec0]:
    for qid in ['comb_dn']:
        aobj_d = local.init_analysis_params(qid=qid,**kwargs)
        tools_lens.interface(aobj_d,run=['rdn0'],kwargs_ov=kwargs_ov,kwargs_qrec=kwargs_qrec)
Esempio n. 15
0
#run = ['com']
run = ['PTSR']
ptsr = 'base'
#run = ['cinv']

    
if 'apod' in run:

    #qids = ['boss_d01']
    qids = ['boss_01','boss_d02','boss_02','boss_d03','boss_03','boss_d04','boss_04','s16_d01','s16_d02','s16_d03']
    
    # for different apodization scales
    for ap in [1.,2.,3.,4.,5.]:
    #or ap in [1.,5.]:

        aobj = {q: local.init_analysis_params(qid=q,ascale=ap) for q in qids}

        for q in qids:
        
            mask_iv = tools_cmb.load_survey_mask(q)
            mask = enmap.to_healpix(mask_iv[0],nside=2048)
    
            if ap != 1.:
                mask[mask!=0] = 1. # binary mask
                amask = cs.utils.apodize(2048,mask,aobj[q].ascale)
            else:
                amask = mask.copy()
        
            print(q,np.average(amask),np.max(amask))        
            hp.fitsfunc.write_map(aobj[q].amask,amask,overwrite=True)