Beispiel #1
0
def get_fiducial_sim_lib(path_to_libs = None):
    from fslens.sims import sims
    import sims_generic
    import covmatrices
    import likelihoods
    import displacements as dp
    from fslens.misc import jc_camb as camb
    # Needs about 748 sim to 4pi surface with this params.
    # Let's do twice as much.

    """
    There is a trade-off between high resolution and number of iteration in the conjugate gradient.
    If the resolution is lower each step is  much faster but the inacuracy in the inverse maping drives the erros
    and make it need a higher number of iterates.
    E.g. for PL2015 params, with res 8 I need 50 iterate , done in 5 sec total.
    with res 9 I ned 20 iterates, done in 10 sec total.
    """
    LD_res = 8
    HD_res = 8
    beam_FWHM_amin = 5.
    sN_uKamin = 35.
    nsims = 100

    HD_shape = (2**HD_res,2**HD_res) # resolution for CMB and lensing operation done at
    LD_shape = (2**LD_res,2**LD_res) # resolution of the dat map
    lcell_side_amin = 1.7 # length of lcell of the data resolution
    lside = lcell_side_amin / 60./180.*np.pi * LD_shape[0]*np.ones(2) # pixel res always the same always at 1.7 amin.

    cl_unl = camb.spectra_fromcambfile('/Users/jcarron/SpyderProjects/jpipe/inputs'
                                       '/cls/base_plikHM_TT_lowTEB_lensing_lenspotentialCls.dat')['tt'][:]
    cl_len = camb.spectra_fromcambfile('/Users/jcarron/SpyderProjects/jpipe/inputs'
                                       '/cls/base_plikHM_TT_lowTEB_lensing_lensedCls.dat')['tt'][:]
    cl_pp = camb.spectra_fromcambfile('/Users/jcarron/SpyderProjects/jpipe/inputs'
                                      '/cls/base_plikHM_TT_lowTEB_lensing_lenspotentialCls.dat')['pp'][:]
    cl_noise = (sN_uKamin * np.pi / 180. / 60.) ** 2*np.ones(20000)  # simple flat noise Cls
    cl_pp[0:2] = cl_pp[2]
    path_to_libs = '/Users/jcarron/data/flatsky_lens_simlibs/test_wPL2015' if path_to_libs is None else path_to_libs
    lib_cmb_unl = sims_generic.Gauss_sim_generic(path_to_libs + '/unl_cmb', cl_unl, HD_shape, lside, nsims_max=nsims)
    lib_noise = sims_generic.Gauss_sim_generic(path_to_libs + '/noise', cl_noise, LD_shape, lside, nsims_max=nsims)
    lib_pp = sims_generic.Gauss_sim_generic(path_to_libs + '/pp', cl_pp, LD_shape, lside, nsims_max=nsims)
    lib_OO = None
    lib_displ = sims.displ_2dsim(lib_pp, lib_OO)
    lib_displ_sim0 = sims_generic.sim_lib_shuffle(lib_displ, shuffle=lambda idx : 0)


    lib_cmb_len = sims.lencmb_sim_lib(lib_cmb_unl, lib_displ) # Library for lensed CMB
    lib_cmb_len_displ0 = sims.lencmb_sim_lib(lib_cmb_unl, lib_displ_sim0) # Library for lensed CMB's by identical potential

    sim_lib = sims.flatsky_sim_lib(lib_cmb_len, lib_noise, lib_dir=path_to_libs + '/full_sims',
                                   beam_FWHM_amin=beam_FWHM_amin, cache_sims=True, mask_map = None)
    fixedphi_sim_lib = sims.flatsky_sim_lib(lib_cmb_len_displ0, lib_noise, beam_FWHM_amin=beam_FWHM_amin,
                                            lib_dir=path_to_libs+'/fxp_sims', cache_sims=True, mask_map = None)
    unl_cov = covmatrices.flatsky_unlcov(cl_unl, (HD_res, HD_res), lside, sN_uKamin=sN_uKamin, Beam_FWHM_amin=beam_FWHM_amin, verbose=False)
    len_cov = covmatrices.flatsky_lencov(cl_unl, cl_len, LD_res, HD_res, lside,
                                         f = dp.identity_displacement(HD_shape), f_inv = dp.identity_displacement(HD_shape),
                                         verbose=False, sN_uKamin=sN_uKamin, Beam_FWHM_amin =beam_FWHM_amin)
    Fisher_lib = likelihoods.flatsky_Fisher_lib(cl_unl, (HD_res, HD_res), lside, sN_uKamin, beam_FWHM_amin, verbose=False)
    return [sim_lib,fixedphi_sim_lib,LD_res,HD_res,lside,sN_uKamin,beam_FWHM_amin,cl_unl,cl_len,cl_pp,cl_noise,unl_cov,len_cov,Fisher_lib]
Beispiel #2
0
def plot_curvature():
    """
    Plot the total curvature (F. info) for phi and Omega for different volumes.
    """
    import pylab as pl

    pl.ioff()
    pl.figure()
    d_ress = [0, 2]
    print "+++++++++++++++++++++++++++++++++++++++++++++++++++"
    for d_res in d_ress:
        if d_res == d_ress[0]:
            print "+plot_curvature::  doing res", HD_res + d_res
        else:
            print "+                  doing res", HD_res + d_res
        res = HD_res + d_res
        lsides = lside * 2 ** d_res
        Fisher = likelihoods.flatsky_Fisher_lib(cl_unl, (res, res), lsides, sN_uKamin, beam_FWHM_amin, verbose=False)
        FT_p_lik = likelihoods.circulant_Gauss_pdf_fourierspace(cl_pp, (res, res), lsides)
        idcs = np.arange(1, 2 ** (res - 1))
        Fpp, FOO, FpO = Fisher.get_curvature_matrix_PhiOmega_ell()
        Fpp = Fpp[0, idcs]
        FOO = FOO[0, idcs]
        Fpp += FT_p_lik.eval_curv().real[0, idcs]
        kx = Fisher.kx_from_index(idcs)
        Nlev_pp = 1.0 / Fpp * 2  # On complex modes
        Nlev_OO = 1.0 / FOO * 2  # On complex modes
        pl.loglog(kx, Nlev_pp * kx ** 2 * (kx + 1) ** 2 / 2.0 / np.pi * 1e7, label="$\phi$, res =" + str(res))
        pl.loglog(kx, Nlev_OO * kx ** 2 * (kx + 1) ** 2 / 2.0 / np.pi * 1e7, label="$\Omega$, res =" + str(res))
        pl.plot(
            np.arange(len(cl_pp)),
            cl_pp * np.arange(len(cl_pp)) ** 2 * (np.arange(len(cl_pp)) + 1) ** 2 / 2.0 / np.pi * 1e7,
            label="$C^{\phi\phi}$",
        )

    pl.legend(frameon=False)
    pl.title("Total inverse curvature")
    pl.xlabel("$\ell$")
    pl.ylabel("$C_\ell \ell^2 (\ell + 1)^2 /2\pi $")

    print "+plot_curvature::   saving fig curvatures.pdf"
    pl.savefig(path_to_figs + "/curvatures.pdf")
    pl.close()
    print "+++++++++++++++++++++++++++++++++++++++++++++++++++"
Beispiel #3
0
def plot_noiselevels():
    """
    Tests the noise levels for phi and Omega for different volumes.
    """
    import pylab as pl

    pl.ioff()
    pl.figure()
    d_ress = [0, 3]
    print "+++++++++++++++++++++++++++++++++++++++++++++++++++"
    for d_res in d_ress:
        if d_res == d_ress[0]:
            print "+test_noiselevels::  doing res", HD_res + d_res
        else:
            print "+                    doing res", HD_res + d_res
        res = HD_res + d_res
        lsides = lside * 2 ** d_res
        Fisher = likelihoods.flatsky_Fisher_lib(cl_unl, (res, res), lsides, sN_uKamin, beam_FWHM_amin, verbose=False)
        Fpp, FOO, FpO = Fisher.get_curvature_matrix_PhiOmega_ell()
        Fpp *= 0.5  # alm
        FOO *= 0.5  # alm
        Nlev_pp = 1.0 / (Fpp[0, np.arange(1, 2 ** (res - 1))])
        Nlev_OO = 1.0 / (FOO[0, np.arange(1, 2 ** (res - 1))])
        kx = Fisher.kx_from_index(np.arange(1, 2 ** (res - 1)))
        pl.loglog(kx, Nlev_pp * kx ** 2 * (kx + 1) ** 2 / 2.0 / np.pi * 1e7, label="$\phi$, res =" + str(res))
        pl.loglog(kx, Nlev_OO * kx ** 2 * (kx + 1) ** 2 / 2.0 / np.pi * 1e7, label="$\Omega$, res =" + str(res))

    pl.legend(frameon=False)
    pl.title("Noise levels")
    pl.xlabel("$\ell$")
    pl.ylabel("$C_\ell \ell^2 (\ell + 1)^2 /2\pi $")

    print "+test_noiselevels::saving fig noise_levels.pdf"
    pl.savefig(path_to_figs + "/noise_levels.pdf")
    pl.close()
    print "+++++++++++++++++++++++++++++++++++++++++++++++++++"
Beispiel #4
0
    cl_len, (LD_res, LD_res), lside, sN_uKamin=sN_uKamin, Beam_FWHM_amin=beam_FWHM_amin, verbose=False
)

len_cov = covmatrices.flatsky_lencov(
    cl_unl,
    cl_len,
    LD_res,
    HD_res,
    lside,
    f=dp.identity_displacement(HD_shape),
    f_inv=dp.identity_displacement(HD_shape),
    verbose=False,
    sN_uKamin=sN_uKamin,
    Beam_FWHM_amin=beam_FWHM_amin,
)
Fisher_lib = likelihoods.flatsky_Fisher_lib(cl_unl, (HD_res, HD_res), lside, sN_uKamin, beam_FWHM_amin, verbose=False)

# Dumping params for convenience
f = open(path_to_libs + "/params.dat", "w")
f.write("LD res         : " + str(LD_res) + "\n")
f.write("HD res         : " + str(LD_res) + "\n")
f.write("sN_uKamin      : " + str(np.round(sN_uKamin, 2)) + "\n")
f.write("beam_FWHM_amin : " + str(np.round(beam_FWHM_amin, 2)) + "\n")
f.write("nsims          : " + str(nsims) + "\n")
f.close()


def generate_sims(sim_lib, label=""):
    for i, idx in enumerate_progress(xrange(nsims), "test_suite::regenerating sims: " + label):
        sim = sim_lib.get_sim(idx)