# AlTau = np.zeros(lmax+1) # for L in xrange(2,lmax+1): # for l in xrange(lmax+1): # for lp in xrange(lmax+1): # print L, l, lp # fact = cltt[l]**2/((cltt[l]+nltt[l])+(cltt[lp]+nltt[lp])) # fact *= (2*l+1)*(2*lp+1)/16./np.pi # # embed() # try: # wig2 = wc.wigner3j(2*L,2*l,2*lp,0.,0.,0.)**2 # except: # wig2 = 0. # AlTau[L] += fact * wig2 # return np.nan_to_num(1./AlTau) if __name__ == '__main__': Delta_T = 3. # microK-arcmin fwhm = 0. # arcmin lmax = 500 cosmo = Cosmo() cltt = cosmo.cmb_spectra(lmax)[:, 0] nltt = nl_cmb(Delta_T, fwhm, lmax=lmax) norm = GetAlTau(cltt, nltt, lmax) embed()
def main(args): SetPlotStyle() # Params 'n' stuff fits_planck_mask = '../Data/mask_convergence_planck_2015_512.fits' fits_planck_map = '../Data/convergence_planck_2015_512.fits' twoMPZ_mask = 'fits/2MPZ_mask_tot_256.fits' # N_side = 256 twoMPZ_cat = 'fits/results16_23_12_14_73.fits' twoMPZ_cat2 = 'fits/results2_14_20_37_1053.fits.gz' fits_ebv = 'fits/lambda_sfd_ebv.fits' nsidelow = 64 nside = args.nside do_plots = False delta_ell = args.delta_ell lmin = args.lmin lmax = args.lmax K_S_min = args.K_S_min K_S_max = args.K_S_max # lbmin = 2 # lbmax = 10 # Load Cat and Mask print("...loading 2MPZ catalogue...") twompz = Load2MPZ(twoMPZ_cat, K_S_min=K_S_min, K_S_max=K_S_max) twompz2 = Load2MPZ(twoMPZ_cat2, K_S_min=K_S_min, K_S_max=K_S_max) print("...done...") # E(B-V) reddening map by Schlegel+ in gal coord at nside=512 ebv = hp.read_map(fits_ebv, verbose=False) ebv = hp.ud_grade(ebv, nsidelow, pess=True) A_K = ebv * 0.367 # K-band correction for Galactic extinction print("...Reddening map loaded...") # Get nstar map nstar = GetNstarMap(twompz['RA'], twompz['DEC'], twompz['STARDENSITY'], nsidelow, rad=True) # Get 2MPZ mask (A_K + nstar + counts) # !!! "torque rod gashes" still need to be removed !!! mask2mpz = Get2MPZMask(A_K, nstar, nside=nside, maskcnt=hpy.GuessMask(twompz['RA'], twompz['DEC'], nsidelow, rad=True)) print("Mask f_sky is %3.2f" % np.mean(mask2mpz)) # Load Planck CMB lensing map 'n' mask print("...loading Planck map/mask...") planck_map, planck_mask = LoadPlanck(fits_planck_map, fits_planck_mask, nside, do_plots=0, filt_plank_lmin=0) print("...done...") print("...reading 2MPZ mask...") mask = hp.read_map(twoMPZ_mask, verbose=False) nside_mask = hp.npix2nside(mask.size) if nside_mask != nside: mask = hp.ud_grade(mask, nside) print("...done...") # Common Planck & WISExSCOS mask mask *= planck_mask # embed() # Counts n overdesnity map cat_tmp = twompz[(twompz.ZPHOTO >= args.zmin) & (twompz.ZPHOTO < args.zmax)] a, b = train_test_split(cat_tmp, test_size=0.5) counts_a = hpy.GetCountsMap(a.RA, a.DEC, nside, coord='G', rad=True) counts_b = hpy.GetCountsMap(b.RA, b.DEC, nside, coord='G', rad=True) # hp.write_map('fits/counts_'+zbin+'_sum.fits', counts_sum[zbin]) # hp.write_map('fits/counts_'+zbin+'_diff.fits', counts_diff[zbin]) print("\tNumber of sources in bin [%.2f,%.2f) is %d" % (args.zmin, args.zmax, np.sum((counts_a + counts_b) * mask))) print("...converting to overdensity maps...") delta_a = hpy.Counts2Delta(counts_a, mask=mask) delta_b = hpy.Counts2Delta(counts_b, mask=mask) delta_sum = 0.5 * (delta_a + delta_b) delta_diff = 0.5 * (delta_a - delta_b) # hp.write_map('fits/delta_'+zbin+'_sum.fits', delta_sum[zbin]) # hp.write_map('fits/delta_'+zbin+'_diff.fits', delta_diff[zbin]) cat_tmp2 = twompz2[(twompz2.ZPHOTO >= args.zmin) & (twompz2.ZPHOTO < args.zmax)] a, b = train_test_split(cat_tmp2, test_size=0.5) counts_a2 = hpy.GetCountsMap(a.RA, a.DEC, nside, coord='G', rad=True) counts_b2 = hpy.GetCountsMap(b.RA, b.DEC, nside, coord='G', rad=True) delta_a2 = hpy.Counts2Delta(counts_a2, mask=mask) delta_b2 = hpy.Counts2Delta(counts_b2, mask=mask) delta_sum2 = 0.5 * (delta_a2 + delta_b2) delta_diff2 = 0.5 * (delta_a2 - delta_b2) print("...done...") # embed() # exit() # XC estimator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ est_mask = cs.Master(mask, lmin=lmin, lmax=lmax, delta_ell=delta_ell, MASTER=0, pixwin=True) # est_mask2mpz = cs.Master(mask2mpz, lmin=lmin, lmax=lmax, delta_ell=delta_ell, MASTER=0, pixwin=True) print('...extracting gg spectra...') clGS, err_gg = est_mask.get_spectra(delta_sum, analytic_errors=True) clGD = est_mask.get_spectra(delta_diff) gg = clGS - clGD clGS_2mpz, err_gg_2mpz = est_mask.get_spectra(delta_sum2, analytic_errors=True) clGD_2mpz = est_mask.get_spectra(delta_diff2) gg_2mpz = clGS_2mpz - clGD_2mpz # clGS_2mpz, err_gg_2mpz = est_mask2mpz.get_spectra(delta_sum, analytic_errors=True) # clGD_2mpz = est_mask2mpz.get_spectra(delta_diff) # gg_2mpz = clGS_2mpz - clGD_2mpz print('...done...') # Initializing Cosmo class cosmo = Cosmo() cosmo_nl = Cosmo(nonlinear=True) nz, z, _ = hist(twompz.ZPHOTO, 'knuth', normed=1) z = 0.5 * (z[1:] + z[:-1]) plt.close() fig = plt.figure() #figsize=(10, 8)) ax = fig.add_subplot(1, 1, 1) plt.title(r'$%.2f < z < %.2f$' % (args.zmin, args.zmax)) # z, n_z = GetdNdzNorm(nz=1000) # clgg = GetAutoSpectrumMagLim( cosmo, 2.21, 0.053, 1.43, bias=1.24, alpha=1., lmax=1000) # clgg_ph = GetAutoSpectrumMagLim( cosmo_nl, 2.21, 0.053, 1.43, bias=1.24, alpha=1., lmax=1000, sigma_zph=0.03) # clgg_nl = GetAutoSpectrumMagLim( cosmo_nl, 2.21, 0.053, 1.43, bias=1.24, alpha=1., lmax=1000) clgg = GetAutoSpectrum(cosmo, z, nz, [args.zmin, args.zmax], b=1., alpha=1., lmax=500, sigma_zph=0.015, i=0) clgg_nl = GetAutoSpectrum(cosmo_nl, z, nz, [args.zmin, args.zmax], b=1., alpha=1., lmax=500, sigma_zph=0.015, i=0) # clgg = GetAutoSpectrum(cosmo, z, dndz, [0., 0.08, 0.5], b=1.24, alpha=1., lmax=500, sigma_zph=0.015, i=i) # clgg_nl = GetAutoSpectrum(cosmo_nl, z, dndz, [0., 0.08, 0.5], b=1.24, alpha=1., lmax=500, sigma_zph=0.015, i=i) # ax = fig.add_subplot(1,1,i+1) lab = r'2MPZ $%.1f < K_S < %.1f$' % (K_S_min, K_S_max) ax.plot(clgg, color='grey', label=r'$b=1$ $\sigma_z=0.015$') ax.plot(clgg_nl, color='darkgrey', ls='--', label=r'NL $b=1$ $\sigma_z=0.015$') ax.errorbar(est_mask.lb, gg, yerr=err_gg, fmt='o', capsize=0, ms=5, label=lab) ax.errorbar(est_mask.lb + 1, gg_2mpz, yerr=err_gg_2mpz, fmt='x', capsize=0, ms=5) #, label=lab) ax.set_ylabel(r'$C_{\ell}^{gg}$') ax.set_xlabel(r'Multipole $\ell$') ax.legend(loc='best') ax.axhline(ls='--', color='grey') ax.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) ax.set_xlim([2., 200]) ax.set_yscale('log') ax.set_ylim([1e-5, 1e-3]) plt.tight_layout() # plt.savefig('plots/2MPZ_clgg_dl'+str(args.delta_ell)+'_lmin_'+str(args.lmin)+'_lmax'+str(args.lmax)+'_KS_min_'+str(args.K_S_min)+'_KS_max_'+str(args.K_S_max)+'_nside'+str(args.nside)+'_zmin_'+str(args.zmin)+'_zmax'+str(args.zmax)+'_split.pdf', bbox_inches='tight') plt.show() # plt.close() embed()
# Params delta_ell = 10 lmin = 10 lmax = 250 K_S_mins = [0., 12., 13.] K_S_max = 13.9 zmin = 0.0 zmax = 0.24 bias = 1. nsims = 500 lbmax = 4 # Initializing Cosmo class cosmo = Cosmo(Giannantonio15Params, nonlinear=True) cosmo_lin = Cosmo(Giannantonio15Params) # To bin theoretical spectra binner = cs.Binner(lmin=lmin, lmax=lmax, delta_ell=delta_ell) DGs = [] err_DGs = [] DGs_lin = [] err_DGs_lin = [] for K_S_min in K_S_mins: # Load Cat print("...loading 2MPZ catalogue...") twoMPZ_cat = 'fits/results16_23_12_14_73.fits' twompz = Load2MPZ(twoMPZ_cat, K_S_min=K_S_min, K_S_max=K_S_max)
fname_kg = 'clkg_sims_dl' + str(delta_ell) + '_lmin_' + str( lmin) + '_lmax' + str(lmax) + '_KS_min_' + str( K_S_min) + '_KS_max_' + str(K_S_max) + '_nside256_zmin_' + str( zbin[0]) + '_zmax' + str( zbin[1]) + '_nsims' + str(nsims) + '.pkl.gz' clkg_sims[zbin] = pickle.load(gzip.open('spectra/sims/' + fname_kg, 'rb')) clgg_sims[zbin] = pickle.load(gzip.open('spectra/sims/' + fname_gg, 'rb')) # assert( clkg_sims[zbins[0]]['lb'] == lb ) # To bin theoretical spectra binner = cs.Binner(lmin=lmin, lmax=lmax, delta_ell=delta_ell) # Initializing Cosmo class # cosmo = Cosmo() cosmo_nl = Cosmo(Giannantonio15Params, nonlinear=True) # cosmo_w = Cosmo(params={'w':-0.5}) # 2MPZ dN/dz nz, z, _ = hist(twompz.ZPHOTO, 'knuth', normed=1, histtype='step') z = 0.5 * (z[1:] + z[:-1]) plt.close() # Get theoretical quantities clkg_slash = {} clgg_slash = {} clkg_slash_binned = {} clgg_slash_binned = {} for zbin in zbins: clkg_slash[zbin] = GetCrossSpectrum(cosmo_nl,
import numpy as np from scipy import interpolate import os import matplotlib.pyplot as plt from cosmojo.universe import Cosmo from matplotlib.pyplot import cm import matplotlib.colors as mcolors from rotation import * from lensing import * arcmin2rad = np.pi / 180. / 60. rad2arcmin = 1./arcmin2rad cosmo = Cosmo() cmbspec = cosmo.cmb_spectra(5000) cmbspec_r = Cosmo({'r':0.1}).cmb_spectra(3000, spec='tensor') nl0 = nl_cmb(9.8,1.3) nl1 = nl_cmb(3.4,30) nl2 = nl_cmb(11.8,3.5) nl3 = nl_cmb(4.5,1.1) l = np.arange(nl0.shape[0]) nl_tot =((1./(nl0))+(1./(nl2))+(1./(nl3)))**(-1) plt.loglog(l,nl0,label='ACTPol') plt.loglog(l,nl1,label='BICEP3') plt.loglog(l,nl2,label='SA')
def del_clbb(r): cmbspec_r = Cosmo({'r': r}).cmb_spectra(1999, spec='tensor')[:, 2] ell = np.arange(2000) denom_r = np.sqrt(2. / (2. * ell + 1.)) * (cmbspec_r + ClBBRot[0:2000]) frac_r = (cmbspec_r / denom_r)**2. return np.sum(frac_r[20:200]) - 6.
)[:, 0] vec = np.loadtxt( '/home/student.unimelb.edu.au/brycem1/MagCAMB/bryce/research12/r_test_vecCls.dat' )[:, 3] tens_vec = tens + vec cl_tens_vec = np.nan_to_num( (tens_vec * 2 * np.pi) / (ell_vec * (ell_vec + 1.))) arcmin2rad = np.pi / 180. / 60. rad2arcmin = 1. / arcmin2rad #Camb initialisation pars = camb.CAMBparams() data_camb = camb.get_background(pars) cosmo = Cosmo() cmbspec = cosmo.cmb_spectra(3000) #cmbspec_r = Cosmo({'r':0.1}).cmb_spectra(12000,spec='tensor')[:,2] clbb_r = Cosmo({'r': 1.}).cmb_spectra(3000, spec='tensor')[:, 2] clbb_r1 = Cosmo({'r': 0.0042}).cmb_spectra(3000, spec='tensor')[:, 2] clbb_r2 = Cosmo({'r': 0.01}).cmb_spectra(3000, spec='tensor')[:, 2] clbb_r3 = Cosmo({'r': 0.1}).cmb_spectra(3000, spec='tensor')[:, 2] #Set up a new set of parameters for CAMB pars = camb.CAMBparams() #This function sets up CosmoMC-like settings, with one massive neutrino and helium set using BBN consistency pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122, mnu=0.06, omk=0,
for zbin in zbins: file_clkg = 'spectra/2MPZ_Planck2015_clkg_dl'+str(delta_ell)+'_lmin_'+str(lmin)+'_lmax'+str(lmax)+'_KS_min_'+str(K_S_min)+'_KS_max_'+str(K_S_max)+'_nside'+str(nside)+'_zmin_'+str(zbin[0])+'_zmax'+str(zbin[1])+'_split.dat' file_clgg = 'spectra/2MPZ_clgg_dl'+str(delta_ell)+'_lmin_'+str(lmin)+'_lmax'+str(lmax)+'_KS_min_'+str(K_S_min)+'_KS_max_'+str(K_S_max)+'_nside'+str(nside)+'_zmin_'+str(zbin[0])+'_zmax'+str(zbin[1])+'_split.dat' lb, clgg[zbin], err_clgg[zbin] = np.loadtxt(file_clgg, unpack=1) lb, clkg[zbin], err_clkg[zbin] = np.loadtxt(file_clkg, unpack=1) # fname_gg = 'clgg_sims_dl'+str(delta_ell)+'_lmin_'+str(lmin)+'_lmax'+str(lmax)+'_KS_min_'+str(K_S_min)+'_KS_max_'+str(K_S_max)+'_nside'+str(nside)+'_zmin_'+str(zbins[0][0])+'_zmax'+str(zbins[0][1])+'_nsims'+str(nsims)+'.pkl.gz' # fname_kg = 'clkg_sims_dl'+str(delta_ell)+'_lmin_'+str(lmin)+'_lmax'+str(lmax)+'_KS_min_'+str(K_S_min)+'_KS_max_'+str(K_S_max)+'_nside'+str(nside)+'_zmin_'+str(zbins[0][0])+'_zmax'+str(zbins[0][1])+'_nsims'+str(nsims)+'.pkl.gz' # clkg_sims = pickle.load(gzip.open('spectra/sims/'+fname_kg,'rb'))#, protocol=2) # clgg_sims = pickle.load(gzip.open('spectra/sims/'+fname_gg,'rb'))#, protocol=2) bias_gg = np.loadtxt('bias_estimator_gg.dat')#clgg_sims['sims'].mean(0) # bias_kg = clkg_sims['sims'].mean(0) # Get theoretical quantities cosmo_nl = Cosmo(Giannantonio15Params, nonlinear=True) cosmo = Cosmo(Giannantonio15Params) # 2MPZ dN/dz # nz, z, _ = hist(twompz.ZSPEC[twompz.ZSPEC>0.],'knuth', normed=1, histtype='step') nz, z, _ = hist(twompz.ZPHOTO,'knuth', normed=1, histtype='step') z = 0.5 * (z[1:]+z[:-1]) plt.close() # embed() # exit() binner = cs.Binner(lmin=lmin, lmax=lmax, delta_ell=delta_ell) clkg_th = {} clgg_th = {}
def del_Cl_r(del_r, r0=0.1, lmax=3000): cmbspec_ru = Cosmo({'r': r0 + del_r}).cmb_spectra(lmax, spec='tensor') cmbspec_rl = Cosmo({'r': r0 - del_r}).cmb_spectra(lmax, spec='tensor') del_Clr = cmbspec_ru[:, 2] - cmbspec_rl[:, 2] return del_Clr
def main(args): SetPlotStyle() # Params 'n' stuff fits_planck_mask = '../Data/mask_convergence_planck_2015_512.fits' fits_planck_map = '../Data/convergence_planck_2015_512.fits' twoMPZ_mask = 'fits/2MPZ_mask_tot_256.fits' # N_side = 256 twoMPZ_cat = 'fits/results16_23_12_14_73.fits' nside = args.nside do_plots = False delta_ell = args.delta_ell lmin = args.lmin lmax = args.lmax K_S_min = args.K_S_min K_S_max = args.K_S_max # lbmin = 2 # lbmax = 10 # Load Cat and Mask print("...loading 2MPZ catalogue...") twompz = Load2MPZ(twoMPZ_cat, K_S_min=K_S_min, K_S_max=K_S_max) print("...done...") # Load Planck CMB lensing map 'n' mask print("...loading Planck map/mask...") planck_map, planck_mask = LoadPlanck(fits_planck_map, fits_planck_mask, nside, do_plots=0, filt_plank_lmin=0) print("...done...") print("...reading 2MPZ mask...") mask = hp.read_map(twoMPZ_mask, verbose=False) nside_mask = hp.npix2nside(mask.size) if nside_mask != nside: mask = hp.ud_grade(mask, nside) print("...done...") # Common Planck & WISExSCOS mask mask *= planck_mask # embed() # Counts n overdesnity map cat_tmp = twompz[(twompz.ZPHOTO >= args.zmin) & (twompz.ZPHOTO < args.zmax)] a, b = train_test_split(cat_tmp, test_size=0.5) counts_a = hpy.GetCountsMap(a.RA, a.DEC, nside, coord='G', rad=True) counts_b = hpy.GetCountsMap(b.RA, b.DEC, nside, coord='G', rad=True) # hp.write_map('fits/counts_'+zbin+'_sum.fits', counts_sum[zbin]) # hp.write_map('fits/counts_'+zbin+'_diff.fits', counts_diff[zbin]) print("\tNumber of sources in bin [%.2f,%.2f) is %d" % (args.zmin, args.zmax, np.sum((counts_a + counts_b) * mask))) print("...converting to overdensity maps...") delta_a = hpy.Counts2Delta(counts_a, mask=mask) delta_b = hpy.Counts2Delta(counts_b, mask=mask) delta_sum = 0.5 * (delta_a + delta_b) delta_diff = 0.5 * (delta_a - delta_b) # hp.write_map('fits/delta_'+zbin+'_sum.fits', delta_sum[zbin]) # hp.write_map('fits/delta_'+zbin+'_diff.fits', delta_diff[zbin]) print("...done...") # embed() # exit() # XC estimator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ est = cs.Master(mask, lmin=lmin, lmax=lmax, delta_ell=delta_ell, MASTER=1, pixwin=True) print('...extracting gg spectra...') clGS, err_gg = est.get_spectra(delta_sum, analytic_errors=True) clGD = est.get_spectra(delta_diff) gg = clGS - clGD counts_ = counts_a + counts_b delta_ = hpy.Counts2Delta(counts_, mask=mask) gg_, err_gg_ = est.get_spectra(delta_, nl=GetNlgg(counts_, mask=mask), pseudo=0, analytic_errors=True) print("\t=> Detection at rougly %.2f sigma ") % (np.sum( (gg[0:] / err_gg[0:])**2)**.5) print("\t=> Detection at rougly %.2f sigma ") % (np.sum( (gg_[0:] / err_gg_[0:])**2)**.5) print('...done...') # Initializing Cosmo class cosmo = Cosmo() cosmo_nl = Cosmo(nonlinear=True) nz, z, _ = hist(twompz.ZPHOTO, 'knuth', normed=1) z = 0.5 * (z[1:] + z[:-1]) plt.close() fig = plt.figure() #figsize=(10, 8)) ax = fig.add_subplot(1, 1, 1) plt.title(r'$%.2f < z < %.2f$' % (args.zmin, args.zmax)) # z, n_z = GetdNdzNorm(nz=1000) # clgg = GetAutoSpectrumMagLim( cosmo, 2.21, 0.053, 1.43, bias=1.24, alpha=1., lmax=1000) # clgg_ph = GetAutoSpectrumMagLim( cosmo_nl, 2.21, 0.053, 1.43, bias=1.24, alpha=1., lmax=1000, sigma_zph=0.03) # clgg_nl = GetAutoSpectrumMagLim( cosmo_nl, 2.21, 0.053, 1.43, bias=1.24, alpha=1., lmax=1000) clgg = GetAutoSpectrum(cosmo, z, nz, [args.zmin, args.zmax], b=1., alpha=1., lmax=500, sigma_zph=0.015, i=0) clgg_nl = GetAutoSpectrum(cosmo_nl, z, nz, [args.zmin, args.zmax], b=1., alpha=1., lmax=500, sigma_zph=0.015, i=0) # clgg = GetAutoSpectrum(cosmo, z, dndz, [0., 0.08, 0.5], b=1.24, alpha=1., lmax=500, sigma_zph=0.015, i=i) # clgg_nl = GetAutoSpectrum(cosmo_nl, z, dndz, [0., 0.08, 0.5], b=1.24, alpha=1., lmax=500, sigma_zph=0.015, i=i) # ax = fig.add_subplot(1,1,i+1) lab = r'2MPZ $%.1f < K_S < %.1f$' % (K_S_min, K_S_max) ax.plot(clgg, color='grey', label=r'$b=1$ $\sigma_z=0.015$') ax.plot(clgg_nl, color='darkgrey', ls='--', label=r'NL $b=1$ $\sigma_z=0.015$') ax.errorbar(est.lb, gg, yerr=err_gg, fmt='o', capsize=0, ms=5, label=lab) # ax.errorbar(est.lb+1, gg_[zbin], yerr=err_gg_[zbin], fmt='x', capsize=0, ms=5)#, label=lab) ax.set_ylabel(r'$C_{\ell}^{gg}$') ax.set_xlabel(r'Multipole $\ell$') ax.legend(loc='best') ax.axhline(ls='--', color='grey') ax.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) ax.set_xlim([2., 200]) ax.set_yscale('log') ax.set_ylim([1e-5, 1e-3]) plt.tight_layout() plt.savefig('plots/2MPZ_clgg_dl' + str(args.delta_ell) + '_lmin_' + str(args.lmin) + '_lmax' + str(args.lmax) + '_KS_min_' + str(args.K_S_min) + '_KS_max_' + str(args.K_S_max) + '_nside' + str(args.nside) + '_zmin_' + str(args.zmin) + '_zmax' + str(args.zmax) + '_split.pdf', bbox_inches='tight') # plt.show() # plt.close() # embed() np.savetxt( 'spectra/2MPZ_clgg_dl' + str(args.delta_ell) + '_lmin_' + str(args.lmin) + '_lmax' + str(args.lmax) + '_KS_min_' + str(args.K_S_min) + '_KS_max_' + str(args.K_S_max) + '_nside' + str(args.nside) + '_zmin_' + str(args.zmin) + '_zmax' + str(args.zmax) + '_split.dat', np.c_[est.lb, gg, err_gg])
from scipy import interpolate import os import matplotlib.pyplot as plt from cosmojo.universe import Cosmo from matplotlib.pyplot import cm import matplotlib.colors as mcolors import rotation as ro import lensing as le from IPython import embed arcmin2rad = np.pi / 180. / 60. rad2arcmin = 1. / arcmin2rad cosmo = Cosmo() cmbspec = cosmo.cmb_spectra(5000) smspec_r = cosmo.cmb_spectra(3000, 'tensor') #sigma(r=0) def sig_r0(fsky, BBpowerspectrum, NlBB, lmin=20, lmax=200): ell = np.arange(BBpowerspectrum.shape[0]) summand = ((2. * ell[lmin:lmax + 1] + 1) * fsky / 2.) * (BBpowerspectrum[lmin:lmax + 1] / NlBB[lmin:lmax + 1])**2. return 1.0 / (np.sqrt(np.sum(summand))) def del_Cl_r(del_r, r0=0.1, lmax=3000): cmbspec_ru = Cosmo({'r': r0 + del_r}).cmb_spectra(lmax, spec='tensor')
plt.close() nz_spec, z_spec, _ = hist(twompz.ZSPEC[twompz.ZSPEC>0.],'knuth', normed=1, histtype='step', label=r'Full spec') # _, _, _ = hist(twompz.ZSPEC[twompz.ZSPEC>0.],'knuth', normed=1, histtype='step', label=r'Full-$z_{\rm s}$') # _, _, _ = hist(twompz.ZPHOTO[twompz.ZSPEC>0.],'knuth', normed=1, histtype='step', label=r'Cross-$z_{\rm s}$') z_spec = 0.5 * (z_spec[1:]+z_spec[:-1]) plt.close() nz_overlap, z_overlap, _ = hist(twompz.ZPHOTO[twompz.ZSPEC>0.],'knuth', normed=1, histtype='step', label=r'overlap photo') # _, _, _ = hist(twompz.ZSPEC[twompz.ZSPEC>0.],'knuth', normed=1, histtype='step', label=r'Full-$z_{\rm s}$') # _, _, _ = hist(twompz.ZPHOTO[twompz.ZSPEC>0.],'knuth', normed=1, histtype='step', label=r'Cross-$z_{\rm s}$') z_overlap = 0.5 * (z_overlap[1:]+z_overlap[:-1]) plt.close() # CMB lens kernel lcmb = LensCMB(Cosmo()) # Plot dN/dz DNDZ = dNdzInterpolation(z, nz, bins=[0.,0.24], sigma_zph=0.015, z_min=0, z_max=1) DNDZ_spec = dNdzInterpolation(z_spec, nz_spec, bins=[0.,0.24], sigma_zph=0.015, z_min=0, z_max=1) # DNDZ_overlap = dNdzInterpolation(z_overlap, nz_overlap, bins=[0.,0.24], sigma_zph=0.015, z_min=0, z_max=1) plt.plot(z, DNDZ.raw_dndz_bin(z,0), label=r'2MPZ $z \le 0.24$', color='#083D77') nz_spec, z_spec, _ = hist(twompz.ZSPEC[twompz.ZSPEC>0.],'knuth', normed=1, histtype='step', label=r'Spec-z', color='#8C2F39') # plt.plot(z, DNDZ_spec.raw_dndz_bin(z,0), label=r'2MPZ $z \le 0.24$ spec') # plt.plot(z, DNDZ_overlap.raw_dndz_bin(z,0), label=r'2MPZ $z \le 0.24$ overlap') # plt.plot(z, DNDZ.raw_dndz_bin(z,0)/np.max(DNDZ.raw_dndz_bin(z,0)), label='Fiducial') # for i,zbin in enumerate(zbins): # DNDZ = dNdzInterpolation(z, nz, bins=[zbin[0],zbin[1]], sigma_zph=0.015, z_min=0, z_max=1) # # plt.plot(z, DNDZ.raw_dndz_bin(z,0)/np.max(DNDZ.raw_dndz_bin(z,0)), label='Bin-%d' %(i+1)) # plt.plot(z, DNDZ.raw_dndz_bin(z,0), label='Bin-%d' %(i+1)) # plt.plot(z, DNDZ.raw_dndz_bin(z,0), label=r'$%.2f < z < %.2f$' %(zbin[0],zbin[1]))
data = pickle.load(open("../transfer.pkl","rb")) ell_array = data['ell'] k_array = data['k'] Tl_m1k = data['Tl_m1k'] Tl_p1k = data['Tl_p1k'] T1lk = data['T1lk'] #Loads pre made transfer pickle files from transfer.py for ell>=1000 at del_l=100 data1 = pickle.load(open("../transfer100.pkl","rb")) ell_array1 = data1['ell'] k_array1 = data1['k'] Tl_m1k1 = data1['Tl_m1k'] Tl_p1k1 = data1['Tl_p1k'] T1lk1 = data1['T1lk'] cosmo = Cosmo() #cmbspec = cosmo.cmb_spectra(12000) cmbspec_r = Cosmo({'r':0.1}).cmb_spectra(12000,spec='tensor')[:,2] #Set up a new set of parameters for CAMB pars = camb.CAMBparams() #This function sets up CosmoMC-like settings, with one massive neutrino and helium set using BBN consistency pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122, mnu=0.06, omk=0, tau=0.06) pars.InitPower.set_params(ns=0.965, r=0) pars.set_for_lmax(12000, lens_potential_accuracy=0) #calculate results for these parameters results = camb.get_results(pars) #get dictionary of CAMB power spectra powers =results.get_cmb_power_spectra(pars, CMB_unit='muK')
return np.asarray( [GetDg(clkg_sims[i], clgg_sims[i], clkg_th, clgg_th, err_kg=err_kg, err_gg=err_gg, lbmin=lbmin, lbmax=lbmax) for i in xrange(clkg_sims.shape[0])] ) # Params delta_ell = 20 lmin = 10 lmax = 250 K_S_min = 0. #, 10., 12., 13.] K_S_max = 13.9 zmin = 0.0 zmax = 0.24 bias = 1. nsims = 200 lbmax = 4 # Initializing Cosmo class cosmo = Cosmo() cosmo_nl = Cosmo(nonlinear=True) # To bin theoretical spectra binner = cs.Binner(lmin=lmin, lmax=lmax, delta_ell=delta_ell) DGs = [] err_DGs = [] # Load Cat print("...loading 2MPZ catalogue...") twoMPZ_cat = 'fits/results16_23_12_14_73.fits' twompz = Load2MPZ(twoMPZ_cat, K_S_min=K_S_min, K_S_max=K_S_max) print("...done...") file_clkg = 'spectra/2MPZ_Planck2015_clkg_dl'+str(delta_ell)+'_lmin_'+str(lmin)+'_lmax'+str(lmax)+'_KS_min_'+str(K_S_min)+'_KS_max_'+str(K_S_max)+'_nside256_zmin_'+str(zmin)+'_zmax'+str(zmax)+'_split.dat'
def clbb2r(r): return Cosmo({'r': r}).cmb_spectra(220, spec='tensor')[:, 2][20:201]
def main(args): SetPlotStyle() # Params 'n' stuff fits_planck_mask = '../Data/mask_convergence_planck_2015_512.fits' fits_planck_map = '../Data/convergence_planck_2015_512.fits' twoMPZ_mask = 'fits/2MPZ_mask_tot_256.fits' # N_side = 256 twoMPZ_cat = 'fits/results16_23_12_14_73.fits' nside = args.nside do_plots = False delta_ell = args.delta_ell lmin = args.lmin lmax = args.lmax K_S_min = args.K_S_min K_S_max = args.K_S_max # Load Cat and Mask print("...loading 2MPZ catalogue...") twompz = Load2MPZ(twoMPZ_cat, K_S_min=K_S_min, K_S_max=K_S_max) print("...done...") # Load Planck CMB lensing map 'n' mask print("...loading Planck map/mask...") planck_map, planck_mask = LoadPlanck(fits_planck_map, fits_planck_mask, nside, do_plots=0, filt_plank_lmin=0) print("...done...") print("...reading 2MPZ mask...") mask = hp.read_map(twoMPZ_mask, verbose=False) nside_mask = hp.npix2nside(mask.size) if nside_mask != nside: mask = hp.ud_grade(mask, nside) print("...done...") # Common Planck & WISExSCOS mask mask *= planck_mask # Counts 'n' delta map cat_tmp = twompz[(twompz.ZSPEC >= args.zmin) & (twompz.ZSPEC < args.zmax)] counts = hpy.GetCountsMap(cat_tmp.RA, cat_tmp.DEC, nside, coord='G', rad=True) delta = hpy.Counts2Delta(counts, mask=mask) est = cs.Master(mask, lmin=lmin, lmax=lmax, delta_ell=delta_ell, MASTER=1, pixwin=True) print('...extracting kg spectra...') kg, err_kg = est.get_spectra(planck_map, map2=delta, analytic_errors=True) print("\t=> Detection at rougly %3.2f sigma ") % (np.sum( (kg[0:] / err_kg[0:])**2)**.5) # Initializing Cosmo class cosmo = Cosmo() cosmo_nl = Cosmo(nonlinear=True) nz, z, _ = hist(twompz.ZSPEC[twompz.ZSPEC > 0.], 'knuth', normed=1, histtype='step') z = 0.5 * (z[1:] + z[:-1]) plt.close() fig = plt.figure() #figsize=(10, 8)) ax = fig.add_subplot(1, 1, 1) plt.title(r'$%.2f < z < %.2f$' % (args.zmin, args.zmax)) clkg = GetCrossSpectrum(cosmo, z, nz, [args.zmin, args.zmax], b=1, alpha=1., lmax=500, sigma_zph=0.) clkg_nl = GetCrossSpectrum(cosmo_nl, z, nz, [args.zmin, args.zmax], b=1, alpha=1., lmax=500, sigma_zph=0.) # z, n_z = GetdNdzNorm(nz=1000) # clkg = GetCrossSpectrum(cosmo, z, n_z, [bins_edges[zbin][0],0.3], b=1.24, alpha=1., lmax=1000) # # clkg = GetCrossSpectrum(cosmo, z, n_z, [bins_edges[zbin][0],bins_edges[zbin][1]], b=1, alpha=1.24, lmax=1000) # clkg_nl = GetCrossSpectrum(cosmo_nl, z, n_z, [bins_edges[zbin][0],0.5], b=1.24, alpha=1., lmax=1000) # # clkg_nl = GetCrossSpectrum(cosmo_nl, z, n_z, [bins_edges[zbin][0],bins_edges[zbin][1]], b=1.24, alpha=1., lmax=1000) # # clgg_pherrz = GetAutoSpectrum(cosmo, z, dndz, [bins_edges[zbin][0],bins_edges[zbin][1]], b=1.24, alpha=1., lmax=1000, sigma_zph=0.03) lab = r'2MPZ $%.1f < K_S < %.1f$' % (K_S_min, K_S_max) ax.plot(clkg, color='grey', label=r'$b=1$') ax.plot(clkg_nl, color='darkgrey', ls='--', label=r'NL $b=1$') ax.errorbar(est.lb, kg, yerr=err_kg, fmt='o', capsize=0, ms=5, label=lab) ax.set_ylabel(r'$C_{\ell}^{\kappa g}$') ax.set_xlabel(r'Multipole $\ell$') ax.legend(loc='best') ax.axhline(ls='--', color='grey') ax.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) ax.set_xlim([2., 200]) ax.set_yscale('log') ax.set_ylim([1e-8, 1e-5]) plt.tight_layout() plt.savefig('plots/2MPZ_Planck_clkg_dl' + str(args.delta_ell) + '_lmin_' + str(args.lmin) + '_lmax' + str(args.lmax) + '_KS_min_' + str(args.K_S_min) + '_KS_max_' + str(args.K_S_max) + '_nside' + str(args.nside) + '_zmin_' + str(args.zmin) + '_zmax' + str(args.zmax) + '_split_spec.pdf', bbox_inches='tight') # plt.show() # plt.close() # embed() np.savetxt( 'spectra/2MPZ_Planck2015_clkg_dl' + str(args.delta_ell) + '_lmin_' + str(args.lmin) + '_lmax' + str(args.lmax) + '_KS_min_' + str(args.K_S_min) + '_KS_max_' + str(args.K_S_max) + '_nside' + str(args.nside) + '_zmin_' + str(args.zmin) + '_zmax' + str(args.zmax) + '_split_spec.dat', np.c_[est.lb, kg, err_kg])
mask = mask_planck_2015 * mask_2MPZ # Get the gal number density cat_tmp = twompz[(twompz.ZPHOTO >= zmin) & (twompz.ZPHOTO < zmax)] counts = hpy.GetCountsMap(cat_tmp.RA, cat_tmp.DEC, nside, coord='G', rad=True) counts = hp.ma(counts) counts.mask = np.logical_not(mask) ngal = counts.mean() ngal_sr = ngal / hp.nside2pixarea(nside) print ngal, ngal_sr # exit() # Initializing Cosmo class cosmo_nl = Cosmo(nonlinear=True) # 2MPZ dN/dz # z, n_z = GetdNdzNorm(nz=1000) nz, z, _ = hist(twompz.ZPHOTO, 'knuth', normed=1, histtype='step') z = 0.5 * (z[1:] + z[:-1]) # Get theoretical quantities # clkg_th = GetCrossSpectrumMagLim(cosmo_nl, 2.21, 0.053, 1.43, bias=1., alpha=1., lmax=2000) # clgg_th = GetAutoSpectrumMagLim( cosmo_nl, 2.21, 0.053, 1.43, bias=1., alpha=1., lmax=2000) clkg_th = GetCrossSpectrum(cosmo_nl, z, nz, [zmin, zmax], b=1.24, alpha=1., lmax=500,
fname_gg = 'clgg_sims_dl'+str(delta_ell)+'_lmin_'+str(lmin)+'_lmax'+str(lmax)+'_KS_min_'+str(K_S_min)+'_KS_max_'+str(K_S_max)+'_nside256_zmin_'+str(zbin[0])+'_zmax'+str(zbin[1])+'_nsims'+str(nsims)+'_fsky.pkl.gz' fname_kg = 'clkg_sims_dl'+str(delta_ell)+'_lmin_'+str(lmin)+'_lmax'+str(lmax)+'_KS_min_'+str(K_S_min)+'_KS_max_'+str(K_S_max)+'_nside256_zmin_'+str(zbin[0])+'_zmax'+str(zbin[1])+'_nsims'+str(nsims)+'_fsky.pkl.gz' else: fname_gg = 'clgg_sims_dl'+str(delta_ell)+'_lmin_'+str(lmin)+'_lmax'+str(lmax)+'_KS_min_'+str(K_S_min)+'_KS_max_'+str(K_S_max)+'_nside256_zmin_'+str(zbin[0])+'_zmax'+str(zbin[1])+'_nsims'+str(nsims)+'.pkl.gz' fname_kg = 'clkg_sims_dl'+str(delta_ell)+'_lmin_'+str(lmin)+'_lmax'+str(lmax)+'_KS_min_'+str(K_S_min)+'_KS_max_'+str(K_S_max)+'_nside256_zmin_'+str(zbin[0])+'_zmax'+str(zbin[1])+'_nsims'+str(nsims)+'.pkl.gz' clkg_sims[zbin] = pickle.load(gzip.open('spectra/sims/'+fname_kg,'rb')) clgg_sims[zbin] = pickle.load(gzip.open('spectra/sims/'+fname_gg,'rb')) # assert( clkg_sims[zbins[0]]['lb'] == lb ) # To bin theoretical spectra binner = cs.Binner(lmin=lmin, lmax=lmax, delta_ell=delta_ell) # Initializing Cosmo class # cosmo = Cosmo() cosmo_nl = Cosmo(Giannantonio15Params, nonlinear=True) # cosmo_w = Cosmo(params={'w':-0.5}) # 2MPZ dN/dz nz, z, _ = hist(twompz.ZPHOTO,'knuth', normed=1, histtype='step') z = 0.5 * (z[1:]+z[:-1]) plt.close() # Get theoretical quantities clkg_slash = {} clgg_slash = {} clkg_slash_binned = {} clgg_slash_binned = {} for zbin in zbins: clkg_slash[zbin] = GetCrossSpectrum(cosmo_nl, z, nz, [zbin[0],zbin[1]], b=bias, alpha=1., lmax=500, sigma_zph=0.015, compute_at_z0=True)
fname_kg = 'clkg_sims_dl' + str(delta_ell) + '_lmin_' + str( lmin) + '_lmax' + str(lmax) + '_KS_min_' + str( K_S_min) + '_KS_max_' + str(K_S_max) + '_nside256_zmin_' + str( zbin[0]) + '_zmax' + str( zbin[1]) + '_nsims' + str(nsims) + '.pkl.gz' clkg_sims[zbin] = pickle.load(gzip.open('spectra/sims/' + fname_kg, 'rb')) clgg_sims[zbin] = pickle.load(gzip.open('spectra/sims/' + fname_gg, 'rb')) # assert( clkg_sims[zbins[0]]['lb'] == lb ) # To bin theoretical spectra binner = cs.Binner(lmin=lmin, lmax=lmax, delta_ell=delta_ell) # Initializing Cosmo class # cosmo = Cosmo() cosmo_nl = Cosmo(Giannantonio15Params, nonlinear=True) # cosmo_w = Cosmo(params={'w':-0.5}) # 2MPZ dN/dz nz, z, _ = hist(twompz.ZPHOTO, 'knuth', normed=1, histtype='step') # nz, z, _ = hist(twompz.ZSPEC[twompz.ZSPEC>0.],'knuth', normed=1, histtype='step') z = 0.5 * (z[1:] + z[:-1]) plt.close() # Get theoretical quantities clkg_slash = {} clgg_slash = {} clkg_slash_binned = {} clgg_slash_binned = {} for zbin in zbins:
from scipy import interpolate import os import matplotlib.pyplot as plt from cosmojo.universe import Cosmo from matplotlib.pyplot import cm import matplotlib.colors as mcolors import rotation as ro import lensing as le import numba from scipy.stats import sem, t from scipy import mean from IPython import embed cosmo = Cosmo() cmbspec = cosmo.cmb_spectra(400) cmbspec_r = Cosmo({'r':1.}).cmb_spectra(400,spec='tensor')[:,2] #exps = [f_sky,noise,beam] test = [0.5,9.8,1.3] fsky= 0.5 noice = 9.8 fwhm = 1.3 def delclaa(Nlaa,fsky,dl,ell): return np.sqrt(2./((2.*ell+1.)*dl*fsky))*(Nlaa)
import os import matplotlib.pyplot as plt from cosmojo.universe import Cosmo from matplotlib.pyplot import cm import matplotlib.colors as mcolors import rotation as ro import lensing as le import numba from IPython import embed arcmin2rad = np.pi / 180. / 60. rad2arcmin = 1. / arcmin2rad cosmo = Cosmo() cmbspec = cosmo.cmb_spectra(5000) l_rot, ClBBRot = ro.GimmeClBBRot(cmbspec, dl=1, nwanted=3000) def del_clbb(r): cmbspec_r = Cosmo({'r': r}).cmb_spectra(1999, spec='tensor')[:, 2] ell = np.arange(2000) denom_r = np.sqrt(2. / (2. * ell + 1.)) * (cmbspec_r + ClBBRot[0:2000]) frac_r = (cmbspec_r / denom_r)**2. return np.sum(frac_r[20:200]) - 6. embed() from scipy.optimize import brentq