Esempio n. 1
0
for ar in arrays:
    t = time.time()

    window = so_map.read_map(d['window_T_%s' % ar])
    window = so_map.get_submap_car(window, box, mode='round')

    window_tuple = (window, window)

    print("compute mcm and Bbl ...")
    beam = np.loadtxt(d['beam_%s' % ar])
    l, bl = beam[:, 0], beam[:, 1]
    bl_tuple = (bl, bl)

    mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0and2(window_tuple,
                                                binning_file,
                                                niter=niter,
                                                bl1=bl_tuple,
                                                lmax=lmax,
                                                type=type)

    almList = []
    nameList = []

    if d['use_filtered_maps'] == True:
        map_T = d['map_T_%s_filtered' % ar]
        map_Q = d['map_Q_%s_filtered' % ar]
        map_U = d['map_U_%s_filtered' % ar]
    else:
        map_T = d['map_T_%s' % ar]
        map_Q = d['map_Q_%s' % ar]
        map_U = d['map_U_%s' % ar]
Esempio n. 2
0
subtasks = so_mpi.taskrange(imin=0, imax=n_mcms - 1)
print(subtasks)
for task in subtasks:
    task = int(task)
    sv1, ar1, sv2, ar2 = sv1_list[task], ar1_list[task], sv2_list[
        task], ar2_list[task]

    print("%s_%s x %s_%s" % (sv1, ar1, sv2, ar2))

    l, bl1 = pspy_utils.read_beam_file(d["beam_%s_%s" % (sv1, ar1)])
    win1_T = so_map.read_map(d["window_T_%s_%s" % (sv1, ar1)])
    win1_pol = so_map.read_map(d["window_pol_%s_%s" % (sv1, ar1)])

    l, bl2 = pspy_utils.read_beam_file(d["beam_%s_%s" % (sv2, ar2)])
    win2_T = so_map.read_map(d["window_T_%s_%s" % (sv2, ar2)])
    win2_pol = so_map.read_map(d["window_pol_%s_%s" % (sv2, ar2)])

    mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0and2(win1=(win1_T, win1_pol),
                                                win2=(win2_T, win2_pol),
                                                bl1=(bl1, bl1),
                                                bl2=(bl2, bl2),
                                                binning_file=d["binning_file"],
                                                niter=d["niter"],
                                                lmax=d["lmax"],
                                                type=d["type"],
                                                l_exact=l_exact,
                                                l_band=l_band,
                                                l_toep=l_toep,
                                                save_file="%s/%s_%sx%s_%s" %
                                                (mcm_dir, sv1, ar1, sv2, ar2))
Esempio n. 3
0
window.data *= mask.data

#let's look at it
window.plot(file_name="%s/window" % (test_dir), ticks_spacing_car=4)

#for spin0 and 2 the window need to be a tuple made of two objects
#the window used for spin0 and the one used for spin 2
window = (window, window)

# Compute spin 0 spin 2 spectra a la pspy
print("Compute spin0 and spin2 power spectra a la pspy")

t0 = time.time()
mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0and2(window,
                                            binning_file,
                                            lmax=lmax,
                                            type=type,
                                            niter=niter)
alms = sph_tools.get_alms(split, window, niter, lmax)
l, ps = so_spectra.get_spectra(alms, spectra=spectra)
lb_py, Cb_pspy = so_spectra.bin_spectra(l,
                                        ps,
                                        binning_file,
                                        lmax,
                                        type=type,
                                        mbb_inv=mbb_inv,
                                        spectra=spectra)

print("pspy run in %.2f s" % (time.time() - t0))

print("Compute spin0 and spin2 power spectra a la namaster")
Esempio n. 4
0
def compute_mode_coupling(window,
                          type,
                          lmax,
                          binning_file,
                          ps_method="master",
                          beam=None,
                          lmax_pad=None,
                          l_thres=None,
                          l_toep=None,
                          compute_T_only=False):
    """Compute the mode coupling corresponding the the window function

    Parameters
    ----------

    window: so_map
        the window function of the patch
    type: string
        the type of binning, either bin Cl or bin Dl
    lmax : integer
        the maximum multipole to consider for the spectra computation
    binning_file: text file
      a binning file with three columns bin low, bin high, bin mean
      note that either binning_file or bin_size should be provided
    ps_method: string
        the method for the computation of the power spectrum
        can be "master", "pseudo", or "2dflat" for now
    beam: text file
        file describing the beam of the map, expect bl to be the second column and start at l=0 (standard is : l,bl, ...)
    lmax_pad: integer
        the maximum multipole to consider for the mcm computation (optional)
        lmax_pad should always be greater than lmax
    compute_T_only: boolean
        True to compute only T spectra
    """

    bin_lo, bin_hi, bin_c, bin_size = pspy_utils.read_binning_file(
        binning_file, lmax)
    n_bins = len(bin_hi)

    fsky = enmap.area(window.data.shape, window.data.wcs) / 4. / np.pi
    fsky *= np.mean(window.data)

    if beam is not None:
        beam_data = np.loadtxt(beam)
        if compute_T_only:
            beam = beam_data[:, 1]
        else:
            beam = (beam_data[:, 1], beam_data[:, 1])

    if compute_T_only:
        if ps_method == "master":
            mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0(window,
                                                    binning_file,
                                                    bl1=beam,
                                                    lmax=lmax,
                                                    type=type,
                                                    niter=0,
                                                    lmax_pad=lmax_pad,
                                                    l_thres=l_thres,
                                                    l_toep=l_toep)

        elif ps_method == "pseudo":
            mbb_inv = np.identity(n_bins)
            mbb_inv *= 1 / fsky
    else:
        window = (window, window)
        if ps_method == "master":
            print("compute master MCM")
            mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0and2(window,
                                                        binning_file,
                                                        bl1=beam,
                                                        lmax=lmax,
                                                        type=type,
                                                        niter=0,
                                                        lmax_pad=lmax_pad,
                                                        l_thres=l_thres,
                                                        l_toep=l_toep)

        elif ps_method == "pseudo":
            mbb_inv = {}
            spin_list = ["spin0xspin0", "spin0xspin2", "spin2xspin0"]
            for spin in spin_list:
                mbb_inv[spin] = np.identity(n_bins)
                mbb_inv[spin] *= 1 / fsky
            mbb_inv["spin2xspin2"] = np.identity(4 * n_bins)
            mbb_inv["spin2xspin2"] *= 1 / fsky

    if ps_method == "2dflat":
        mbb_inv = None

    return mbb_inv
Esempio n. 5
0
    if pixwin == True:
        bl1_t *= hp.pixwin(window_tuple1[0].nside)[:len(bl1_t)]
        bl1_pol *= hp.pixwin(window_tuple1[0].nside)[:len(bl1_pol)]

    bl_tuple1 = (bl1_t, bl1_pol)

    del win_t2, win_pol2

    l, bl2_t = np.loadtxt(d["beam_%s_%s_T" % (freq2, hm2)], unpack=True)
    l, bl2_pol = np.loadtxt(d["beam_%s_%s_pol" % (freq2, hm2)], unpack=True)

    if pixwin == True:
        bl2_t *= hp.pixwin(window_tuple2[0].nside)[:len(bl2_t)]
        bl2_pol *= hp.pixwin(window_tuple2[0].nside)[:len(bl2_pol)]

    bl_tuple2 = (bl2_t, bl2_pol)

    mcm_inv, mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0and2(
        win1=window_tuple1,
        win2=window_tuple2,
        binning_file=binning_file,
        bl1=bl_tuple1,
        bl2=bl_tuple2,
        lmax=lmax,
        niter=niter,
        type=type,
        unbin=True,
        save_file="%s/%s_%sx%s_%s-%sx%s" %
        (mcm_dir, experiment, freq1, experiment, freq2, hm1, hm2))
Esempio n. 6
0
    pass

# create a binningfile with format, lmin,lmax,lmean
pspy_utils.create_binning_file(bin_size=50, n_bins=300, file_name="%s/binning.dat" % test_dir)
binning_file = "%s/binning.dat" % test_dir

window = so_window.create_apodization(binary, apo_type="C1", apo_radius_degree=apo_radius_degree_survey)
    
cmb=template.synfast(clfile)

# Compute spin 0 spin 2 spectra a la pspy
t0=time.time()

mbb_inv_pure, Bbl_pure = so_mcm.mcm_and_bbl_spin0and2((window,window),
                                                           binning_file,
                                                           lmax=lmax,
                                                           niter=niter,
                                                           type=type,
                                                           pure=True)

alm_pure = sph_tools.get_pure_alms(cmb, (window,window), niter, lmax)
l, ps_pure = so_spectra.get_spectra(alm_pure, alm_pure, spectra=spectra)

lb, ps_dict_pure = so_spectra.bin_spectra(l,
                                          ps_pure,
                                          binning_file,
                                          lmax,
                                          type=type,
                                          mbb_inv=mbb_inv_pure,
                                          spectra=spectra)

print("pspy run in %.2f s"%(time.time()-t0))
        window1 = so_map.read_map("%s/window_%s_%s.fits" %
                                  (window_dir, exp1, freq1))

        for id_exp2, exp2 in enumerate(experiments):
            freqs2 = d["freqs_%s" % exp2]

            for id_f2, freq2 in enumerate(freqs2):
                # This ensures that we do not repeat equivalent computation
                if (id_exp1 == id_exp2) & (id_f1 > id_f2): continue
                if (id_exp1 > id_exp2): continue

                print("%s_%s x %s_%s" % (exp1, freq1, exp2, freq2))

                l, bl2 = np.loadtxt("sim_data/beams/beam_%s_%s.dat" %
                                    (exp2, freq2),
                                    unpack=True)
                window2 = so_map.read_map("%s/window_%s_%s.fits" %
                                          (window_dir, exp2, freq2))

                mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0and2(
                    win1=(window1, window1),
                    win2=(window2, window2),
                    bl1=(bl1, bl1),
                    bl2=(bl2, bl2),
                    binning_file=d["binning_file"],
                    niter=d["niter"],
                    lmax=d["lmax"],
                    type=d["type"],
                    save_file="%s/%s_%sx%s_%s" %
                    (mcm_dir, exp1, freq1, exp2, freq2))
Esempio n. 8
0
            for id_f2, f2 in enumerate(freqs2):

                # The following if statement ensures that no wasteful computation are made
                # LAT 145 x LAT 225 as the same mode coupling matrix as LAT 225 x LAT 145

                if (id_exp1 == id_exp2) & (id_f1 > id_f2): continue
                if (id_exp1 > id_exp2): continue

                #read the beam file and the window function corresponding to exp2 and f2

                l, bl2 = np.loadtxt(d['beam_%s_%s' % (exp2, f2)], unpack=True)

                window2_T = so_map.read_map('%s/window_T_%s_%s.fits' %
                                            (window_dir, exp2, f2))
                window2_P = so_map.read_map('%s/window_P_%s_%s.fits' %
                                            (window_dir, exp2, f2))

                print(exp1, f1, exp2, f2)

                # compute the mode coupling matrices and binning matrices
                mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0and2(
                    win1=(window1_T, window1_P),
                    win2=(window2_T, window2_P),
                    bl1=(bl1, bl1),
                    bl2=(bl2, bl2),
                    binning_file=d['binning_file'],
                    niter=0,
                    lmax=d['lmax'],
                    type=d['type'],
                    save_file='%s/%s_%sx%s_%s' % (mcm_dir, exp1, f1, exp2, f2))
Esempio n. 9
0
                                   (map_dir["split0"], scan))
            window.data *= hmap.data
        else:
            print("Uniform weighting")

        window.write_map("%s/window_%s_%s.fits" % (window_dir, scan, run))

        window.plot(file_name="%s/window_%s_%s" % (plot_dir, scan, run),
                    title=scan)

        window = (window, window)

        mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0and2(window,
                                                    binning_file,
                                                    lmax=lmax,
                                                    type="Dl",
                                                    niter=niter,
                                                    save_file="%s/%s_%s" %
                                                    (mcm_dir, scan, run))

        alm = {}
        for split in split_list:
            alm[split] = sph_tools.get_alms(sim[split], window, niter, lmax)

        for c0, s0 in enumerate(split_list):
            for c1, s1 in enumerate(split_list):
                if c1 > c0: continue

                spec_name = "%s_%sx%s_%s" % (scan, s0, s1, run)

                l, ps = so_spectra.get_spectra(alm[s0],
Esempio n. 10
0
    window = so_map.read_map(d['window_T_%s' % ar])
    window = so_map.get_submap_car(window, box, mode='round')

    window_tuple = (window, window)

    print("compute mcm and Bbl ...")
    beam = np.loadtxt(d['beam_%s' % ar])
    l, bl = beam[:, 0], beam[:, 1]
    bl_tuple = (bl, bl)

    if recompute_mcm == True:
        mbb_inv, Bbl = so_mcm.mcm_and_bbl_spin0and2(window_tuple,
                                                    binning_file,
                                                    niter=niter,
                                                    bl1=bl_tuple,
                                                    lmax=lmax,
                                                    type=type,
                                                    save_file='%s/%s' %
                                                    (mcmDir, ar))
    else:
        spin_pairs = [
            'spin0xspin0', 'spin0xspin2', 'spin2xspin0', 'spin2xspin2'
        ]
        mbb_inv, Bbl = so_mcm.read_coupling(prefix='%s/%s' % (mcmDir, ar),
                                            spin_pairs=spin_pairs)

    almList = []
    nameList = []

    map_T = d['map_T_%s' % ar][0]
    map_Q = d['map_Q_%s' % ar][0]