コード例 #1
0
ファイル: lens_utils.py プロジェクト: carronj/MLlens
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]
コード例 #2
0
ファイル: test_suite.py プロジェクト: carronj/MLlens
cl_noise = (sN_uKamin * np.pi / 180.0 / 60.0) ** 2 * np.ones(20000)  # simple flat noise Cls


path_to_libs = "/Users/jcarron/data/flatsky_lens_simlibs/test_wPL2015" if path_to_libs is None else path_to_libs
path_to_figs = path_to_libs + "/figs"

if not os.path.exists(path_to_libs):
    os.mkdir(path_to_libs)
if not os.path.exists(path_to_figs):
    os.mkdir(path_to_figs)

lib_cmb_unl = sims_generic.Gauss_sim_generic(path_to_libs + "/unl_cmb", cl_unl, HD_shape, lside, nsims_max=nsims)
lib_pp = sims_generic.Gauss_sim_generic(path_to_libs + "/pp", cl_pp, 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_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,
)
sim_lib_fixedphi = sims.flatsky_sim_lib(
    lib_cmb_len_displ0,