Beispiel #1
0
def demo_uk_interp():
    co = CosmoParameters()
    nu = NuisanceParameters(sigma_lambda=1e-5, lgM0=0, alpha_M=1,
                            lambda0=1)  #1-1,no scatter
    su = Survey()
    pshm = PowerSpectrumHaloMatter(co=co, nu=nu, su=su, zh=0.5)
    pshm.calc_uk_M_interp(1e+14, 2e+14)
Beispiel #2
0
def demo_cov(plotting=False):
    co = CosmoParameters(OmegaM=0.286, sigma8=0.82, h=0.7, OmegaDE=0.714)
    nu = NuisanceParameters(sigma_lambda=1e-5, lgM0=0, alpha_M=1,
                            lambda0=1)  #1-1,no scatter
    su = Survey(zs_min=0.56,
                zs_max=0.65,
                top_hat=True,
                n_src_arcmin=10,
                sigma_gamma=0.3)

    cds = CovDeltaSigma(co=co, nu=nu, su=su)
    rp_min = 1
    rp_max = 10
    n_rp = 2  #5
    cds.calc_cov(rp_min=rp_min,
                 rp_max=rp_max,
                 n_rp=n_rp,
                 zh_min=0.1,
                 zh_max=0.3,
                 Mmin=1e14,
                 Mmax=1e16,
                 diag_only=False)
    print(cds.cov_cosmic_shear)
    print(cds.cov_shape_noise)

    ### compare with the old code
    from clens.lensing.cov_DeltaSigma_old import CovDeltaSigmaOld
    cdso = CovDeltaSigmaOld(co=co, nu=nu, su=su)
    ## cov
    output = cdso.calc_cov_thin_slice(rp_min=rp_min,
                                      rp_max=rp_max,
                                      n_rp=n_rp,
                                      zh_min=0.1,
                                      zh_max=0.3,
                                      Mmin=1e14,
                                      Mmax=1e16)
    #rp_mid, cov_cosmic_shear, cov_shape_noise, x = output
    print(cdso.cov_cosmic_shear)
    print(cdso.cov_shape_noise)

    if plotting == True:
        plt.plot(cds.rp_mid_list,
                 cds.cov_cosmic_shear.diagonal(),
                 label='cosmic shear')
        plt.plot(cds.rp_mid_list,
                 cds.cov_shape_noise.diagonal(),
                 label='shape noise')
        #plt.plot(cds.rp_mid_list, cds.cov_halo_intrinsic.diagonal(), label='halo intrinsic')
        #plt.plot(cds.thmid_list*cn.radian_to_arcmin, cds.cov_sum.diagonal(), label='sum')
        plt.legend()
        plt.xscale('log')
        plt.yscale('log')
        plt.xlabel(r'$\rm r_p\ [Mpc]$')
        plt.ylabel(r'$\rm Var[\Delta\Sigma]$')
        plt.show()
Beispiel #3
0
def demo_cov(save_files=False):
    co = CosmoParameters(OmegaM=0.286, sigma8=0.82, h=0.7, OmegaDE=0.714)
    nu = NuisanceParameters(sigma_lambda=1e-5, lgM0=0, alpha_M=1, lambda0=1)#1-1,no scatter
    su = Survey()
    cj = Covgammat(co=co, nu=nu, su=su)
    thmin = 5e-4
    thmax = 5e-2
    nth = 2#10#4
    zh_min = 0.1
    zh_max = 0.3
    Mmin = 1e14
    Mmax = 1e16
    cj.calc_cov_gammat_integration(thmin=thmin, thmax=thmax, nth=nth, zh_min=zh_min, zh_max=zh_max, Mmin=Mmin, Mmax=Mmax)
    plt.figure(figsize=(14,7))
    plt.subplot(121)
    plt.plot(cj.thmid_list*cn.radian_to_arcmin, cj.cov_cosmic_shear.diagonal(), label='cosmic shear')
    plt.plot(cj.thmid_list*cn.radian_to_arcmin, cj.cov_shape_noise.diagonal(), label='shape noise')
    plt.plot(cj.thmid_list*cn.radian_to_arcmin, cj.cov_halo_intrinsic.diagonal(), label='halo intrinsic')
    plt.plot(cj.thmid_list*cn.radian_to_arcmin, cj.cov_sum.diagonal(), label='sum')
    plt.legend()
    plt.xscale('log')
    plt.yscale('log')
    plt.xlabel(r'$\rm\theta\ [arcmin]$')
    plt.ylabel(r'$\rm Var[\gamma_t]$')

    plt.subplot(122)
    plt.imshow(np.log10(cj.cov_sum))
    plt.colorbar()

    if save_files==True:
        plot_loc = '../../plots/lensing/'
        if os.path.isdir(plot_loc)==False: os.makedirs(plot_loc)
        output_loc = '../../output/lensing/'
        if os.path.isdir(output_loc)==False: os.makedirs(output_loc)


        plt.savefig(plot_loc+'cov_cosmic_shear_nbins_%i.pdf'%(nth))
        ## save var_cosmic_shear
        outfile = open(output_loc+'var_cosmic_shear_fullsky_z_%g_%g_M_%.0e_%.0e.dat'%(zh_min,zh_max,Mmin,Mmax),'w')
        outfile.write('# theta[radian], var gammat \n')
        for it in range(len(cj.thmid_list)):
            outfile.write('%g %g\n'%(cj.thmid_list[it], cj.cov_cosmic_shear.diagonal()[it]))
        outfile.close()

        ## save var_shape_noise
        outfile = open(output_loc+'var_shape_noise_fullsky_z_%g_%g_M_%.0e_%.0e.dat'%(zh_min,zh_max,Mmin,Mmax),'w')
        outfile.write('# theta[radian], var gammat \n')
        for it in range(len(cj.thmid_list)):
            outfile.write('%g %g\n'%(cj.thmid_list[it], cj.cov_shape_noise.diagonal()[it]))
        outfile.close()

        ## save the entire cov
        outfile = open(output_loc+'cov_sum_fullsky_z_%g_%g_M_%.0e_%.0e.dat'%(zh_min,zh_max,Mmin,Mmax),'w')
        np.savetxt(outfile, cj.cov_sum)
        outfile.close()
Beispiel #4
0
def demo_uk():
    co = CosmoParameters()
    nu = NuisanceParameters(sigma_lambda=1e-5, lgM0=0, alpha_M=1,
                            lambda0=1)  #1-1,no scatter
    su = Survey()
    pshm = PowerSpectrumHaloMatter(co=co, nu=nu, su=su, zh=0.5)
    pshm._check_convergence_Ci()
    pshm._check_convergence_Si()

    plt.figure()
    pshm.calc_uk(M200m=1e14, c=4, plotting=True)
    pshm.calc_uk(M200m=1e16, c=4, plotting=True)
Beispiel #5
0
def demo_pk():
    co = CosmoParameters()
    nu = NuisanceParameters(sigma_lambda=1e-5, lgM0=0, alpha_M=1,
                            lambda0=1)  #1-1,no scatter
    su = Survey()

    pshm = PowerSpectrumHaloMatter(co=co, nu=nu, su=su, zh=0.5)
    pshm.calc_Pk_hm_full(Mmin=1e14, Mmax=1e16)

    plt.figure()
    plt.loglog(pshm.k_list, pshm.P1h_list)
    plt.loglog(pshm.k_list, pshm.P2h_list)
    plt.loglog(pshm.k_list, np.exp(pshm.lnPk_lnk_interp(pshm.lnk_list)))
Beispiel #6
0
def demo_var_slicing():
    co = CosmoParameters(OmegaM=0.286, sigma8=0.82, h=0.7, OmegaDE=0.714)
    nu = NuisanceParameters(sigma_lambda=1e-5, lgM0=0, alpha_M=1, lambda0=1)#1-1,no scatter
    su = Survey()
    cj = Covgammat(co=co, nu=nu, su=su, slicing=True, dz_slicing=0.03)
    thmin = 5e-4
    thmax = 5e-2
    nth = 2#10#4
    cj.calc_cov_gammat_integration(thmin=thmin, thmax=thmax, nth=nth, zh_min=0.1, zh_max=0.3, Mmin=1e14, Mmax=1e16, diag_only=True)
    plt.plot(cj.thmid_list*cn.radian_to_arcmin, cj.var_cosmic_shear, label='cosmic shear, slicing',ls='--')
    plt.legend()
    plt.xscale('log')
    plt.yscale('log')
    plt.xlabel(r'$\rm\theta\ [arcmin]$')
    plt.ylabel(r'$\rm Var[\gamma_t]$')
Beispiel #7
0
def demo_var_slicing():
    co = CosmoParameters(OmegaM=0.286, sigma8=0.82, h=0.7, OmegaDE=0.714)
    nu = NuisanceParameters(sigma_lambda=1e-5, lgM0=0, alpha_M=1,
                            lambda0=1)  #1-1,no scatter
    su = Survey(zs_min=0.56,
                zs_max=0.65,
                top_hat=True,
                n_src_arcmin=10,
                sigma_gamma=0.3)
    rp_min = 1
    rp_max = 10
    n_rp = 2  #5
    cds = CovDeltaSigma(co=co, nu=nu, su=su, slicing=True, dz_slicing=0.033)
    cds.calc_cov(rp_min=rp_min,
                 rp_max=rp_max,
                 n_rp=n_rp,
                 zh_min=0.1,
                 zh_max=0.3,
                 Mmin=1e14,
                 Mmax=1e16,
                 diag_only=True)
    print(cds.cov_cosmic_shear)
Beispiel #8
0
    Mmax_hiMsun = float(sys.argv[4]) 
    n_rp = int(sys.argv[5])
    scatter = float(sys.argv[6])


    if scatter==0:
        Mmin_obs = Mmin_hiMsun
    else:
        ## NEW Mobs threshold with scatter
        boxsize = 720
        den, M_lim_noscat, Mobs_lim_scat = np.loadtxt('../data/abacus_scatter%g/%i_planck_10percent/z%g/Mobs_threshold.dat'%(scatter,boxsize,zh_mid), unpack=True)
        select = (M_lim_noscat == Mmin_hiMsun)
        Mmin_obs = Mobs_lim_scat[select]

        


    co = CosmoParameters(h=0.673, OmegaDE=0.686, OmegaM=0.314, sigma8=0.83) # Abacus cosmology
    if scatter==0:
        nu = NuisanceParameters(sigma_lambda=1e-5, lgM0=0, alpha_M=1, lambda0=1) # 1-1,no scatter
    else:
        nu = NuisanceParameters(sigma_lambda=scatter, lgM0=0, alpha_M=1, lambda0=1) 

    su = Survey(top_hat=True, zs_min=zs_mid-0.05, zs_max=zs_mid+0.05, n_src_arcmin=10)

    cp = DemoAnalytic(co=co, nu=nu, su=su, zh_mid=zh_mid, Mmin_hiMsun=Mmin_obs, Mmax_hiMsun=Mmax_hiMsun, rp_min_hiMpc=0.1, rp_max_hiMpc=100., n_rp=n_rp)
    cp.calc_cov_full() # takes some time
    #cp.calc_cov_slice()# takes some time
    #cp.calc_cov_full_no_shot_noise()# takes some time
    #cp.plot_analytic()
        kernel_list = self.kernel_z_interp(zl_list)
        plt.plot(zl_list, kernel_list)
        plt.xlabel(r'$\rm z_{lens}$')
        plt.ylabel(
            r'$\rm Kernel(z_l) = \displaystyle\int dz_s n(z_s)/\Sigma_{crit}(z_s, z_l)$'
        )
        plt.minorticks_on()
        plt.xlim(0, None)

        plt.subplot(224)
        plt.title('lensing kernel vs. ' + r'$\rm\chi$')
        chi_l_list = self.chi(z=zl_list).value
        plt.plot(chi_l_list, kernel_list)
        plt.minorticks_on()
        plt.xlabel(r'$\rm \chi_{lens}\ [Mpc]$')
        plt.ylabel(r'$\rm Kernel(\chi_l)$')
        plt.minorticks_on()
        plt.xlim(0, None)

        plt.savefig('../../plots/lensing/kernel_sanity.pdf')


if __name__ == "__main__":
    co = CosmoParameters()
    su = Survey()
    lk = LensingKernel(co=co, su=su)
    lk.distance_sanity()
    lk.kernel_sanity()

    plt.show()
        return mean_inv_Sigma_crit

    def calc_gammmat(self):
        rp, DeltaSigma = self.calc_DeltaSigma()

        zh = 0.5 * (self.zh_min + self.zh_max)
        mean_inv_Sigma_crit = self.mean_inv_Sigma_crit(zh)
        gammat_avg = DeltaSigma * mean_inv_Sigma_crit  #* (1e-12)
        chi_l = self.chi(zh).value
        theta = rp / chi_l

        return theta, gammat_avg


if __name__ == "__main__":
    co = CosmoParameters(OmegaM=0.286, sigma8=0.82, h=0.7, OmegaDE=0.714)
    nu = NuisanceParameters(sigma_lambda=1e-5, lgM0=0, alpha_M=1,
                            lambda0=1)  #1-1,no scatter
    su = Survey(zs_min=0.508, zs_max=0.574)
    lp = LensingProfiles(co=co,
                         nu=nu,
                         su=su,
                         zh_min=0.155,
                         zh_max=0.323,
                         Mmin=1e+14,
                         Mmax=1e+16)
    theta, gammat = lp.calc_gammmat()
    plt.plot(theta, gammat)
    plt.xscale('log')
    plt.yscale('log')
    plt.show()