def get_theory_dicts(nells=None, lmax=9000, grad=True): thloc = os.path.dirname( os.path.abspath(__file__)) + "/../data/" + config['theory_root'] ls = np.arange(lmax + 1) ucls = {} tcls = {} theory = cosmology.loadTheorySpectraFromCAMB(thloc, get_dimensionless=False) ells, gt, ge, gb, gte = np.loadtxt(f"{thloc}_camb_1.0.12_grads.dat", unpack=True, usecols=[0, 1, 2, 3, 4]) if nells is None: nells = {'TT': 0, 'EE': 0, 'BB': 0} ucls['TT'] = maps.interp(ells, gt)(ls) if grad else theory.lCl('TT', ls) ucls['TE'] = maps.interp(ells, gte)(ls) if grad else theory.lCl('TE', ls) ucls['EE'] = maps.interp(ells, ge)(ls) if grad else theory.lCl('EE', ls) ucls['BB'] = maps.interp(ells, gb)(ls) if grad else theory.lCl('BB', ls) ucls['kk'] = theory.gCl('kk', ls) tcls['TT'] = theory.lCl('TT', ls) + nells['TT'] tcls['TE'] = theory.lCl('TE', ls) tcls['EE'] = theory.lCl('EE', ls) + nells['EE'] tcls['BB'] = theory.lCl('BB', ls) + nells['BB'] return ucls, tcls
comm = mpi.MPI.COMM_WORLD rank = comm.Get_rank() numcores = comm.Get_size() # Paths PathConfig = io.load_path_config() pout_dir = PathConfig.get("paths","plots")+"qest_hdv_"+str(args.noise)+"_" io.mkdir(pout_dir,comm) # Theory theory_file_root = "../alhazen/data/Aug6_highAcc_CDM" cc = counts.ClusterCosmology(skipCls=True) theory = cosmology.loadTheorySpectraFromCAMB(theory_file_root,unlensedEqualsLensed=False, useTotal=False,TCMB = 2.7255e6,lpad=9000,get_dimensionless=False) # Geometry shape, wcs = maps.rect_geometry(width_arcmin=args.arc,px_res_arcmin=args.pix,pol=False) modlmap = enmap.modlmap(shape,wcs) modrmap = enmap.modrmap(shape,wcs) # Binning bin_edges = np.arange(0.,20.0,args.pix*2) binner = stats.bin2D(modrmap*60.*180./np.pi,bin_edges) # Noise model noise_uK_rad = args.noise*np.pi/180./60. normfact = np.sqrt(np.prod(enmap.pixsize(shape,wcs))) kbeam = maps.gauss_beam(args.beam,modlmap)
mlmax = lmax + 500 polcomb = 'TT' nside = 2048 # lmin = 300 # lmax = 1500 # mlmax = lmax + 500 # polcomb = 'TT' # nside = 1024 config = io.config_from_yaml( os.path.dirname(os.path.abspath(__file__)) + "/../input/config.yml") opath = config['data_path'] thloc = os.path.dirname( os.path.abspath(__file__)) + "/../data/" + config['theory_root'] theory = cosmology.loadTheorySpectraFromCAMB(thloc, get_dimensionless=False) def get_mv_kappa(polcomb, xalm, yalm): shape, wcs = enmap.fullsky_geometry(res=np.deg2rad(0.5 * 8192 / nside / 60.)) res = qe.qe_all(shape, wcs, lambda x, y: theory.lCl(x, y), mlmax, yalm[0], yalm[1], yalm[2], estimators=[polcomb], xfTalm=xalm[0], xfEalm=xalm[1],
comm = mpi.MPI.COMM_WORLD rank = comm.Get_rank() numcores = comm.Get_size() Njobs = Nsims num_each,each_tasks = mpi.mpi_distribute(Njobs,numcores) if rank==0: print ("At most ", max(num_each) , " tasks...") my_tasks = each_tasks[rank] mlmax = 4000 if not(pure_healpix) else None # lmax used for harmonic transforms # load theory camb_root = "data/cosmo2017_10K_acc3" theory = cosmology.loadTheorySpectraFromCAMB(camb_root,get_dimensionless=False) # ells corresponding to modes in the alms nside = 2048 ells = np.arange(0,3*nside+1,1) #lpls,lpal = np.loadtxt("data/nls_%d.txt" % lmax,unpack=True) lpfile = "/gpfs01/astro/workarea/msyriac/data/sims/msyriac/lenspix/cosmo2017_lmax_fix_lens_lmax_%d_qest_lmax_%d_AL.txt" % (lmax+2000,lmax) lpls,lpal = np.loadtxt(lpfile,unpack=True,usecols=[0,1]) lpal = lpal / (lpls) / (lpls+1.) dh_nls = np.nan_to_num(lpal*(lpls*(lpls+1.))**2./4.) dh_als = np.nan_to_num(dh_nls * 2. / lpls /(lpls+1)) Al = maps.interp(lpls,dh_als)(ells) sim_location = "/gpfs01/astro/workarea/msyriac/data/sims/msyriac/lenspix/"
beamPath = simRoot + "beam_0.txt" l,beamells = np.loadtxt(beamPath,unpack=True,usecols=[0,1]) cmbellmin = 100 cmbellmax = 3000 kellmin = 100 kellmax = 3000 #cambRoot = "/astro/u/msyriac/repos/cmb-lensing-projections/data/TheorySpectra/ell28k_highacc" cambRoot = "/gpfs01/astro/workarea/msyriac/data/sims/alex/non-linear" TCMB = 2.7255e6 #theory = loadTheorySpectraFromCAMB(cambRoot,unlensedEqualsLensed=False,useTotal=False,TCMB = TCMB,lpad=4000) # !!!!!!!!!!!!! N2 bias theory = loadTheorySpectraFromCAMB(cambRoot,unlensedEqualsLensed=True,useTotal=False,TCMB = TCMB,lpad=(cmbellmax + 500)) ellkk = np.arange(2,9000,1) Clkk = theory.gCl("kk",ellkk) N = int(sys.argv[1]) assert N%numcores==0 num_each = (N / numcores) startIndex = rank*num_each endIndex = startIndex + num_each myIs = list(range(N))[startIndex:endIndex] listCrossPower = {}
if nIter == 1: iterName = '_iterOff' else: iterName = '_iterOn' print "Run with testNlkk lensing or lensTT ", iterName outDir = 'output/' + saveName + '_' i = 0 #cambRoot = 'data/Aug6_highAcc_CDM' cambRoot = '../quicklens/quicklens/data/cl/planck_wp_highL/planck_lensing_wp_highL_bestFit_20130627' #cambRoot = '/home/hnnguyen/CAMB-0.1.6.1/base_plikHM_TT_lowTEB_minimum_fudgedtotaup06_lmax5000' theoryOverride = cosmo.loadTheorySpectraFromCAMB( cambRoot, unlensedEqualsLensed=False, useTotal=False, TCMB=TCMB, lpad=bigell) #,get_dimensionless=True) #theoryOverride = None tellmin, tellmax = list_from_config(Config, expName, 'tellrange') pellmin, pellmax = list_from_config(Config, expName, 'pellrange') px = np.round(180. / max(tellmax, pellmax) * 60. * 0.95, 2) ls, Nls, ellbb, dclbb, efficiency, cc = lensNoise( Config, expName, lensName, beamOverride=None, lkneeTOverride=None, lkneePOverride=None,
def __init__(self, full_sky_pix, wdeg, hdeg, yoffset, mpi_comm=None, nsims=1, lmax=7000, pix_intermediate=None, bin_lmax=3000): self.dtype = np.float32 self.bin_edges = np.arange(80, bin_lmax, 100) # define power bin edges # Create a full sky geometry self.fshape, self.fwcs = enmap.fullsky_geometry(res=full_sky_pix * np.pi / 180. / 60., proj="car") self.fshape = self.fshape[-2:] # Holders for geometries and window corrections for each of e,s,r self.shape = {} self.wcs = {} self.taper = {} self.w2 = {} self.w3 = {} self.w4 = {} # Intermediate pixelization for rotation self.pix_intermediate = full_sky_pix if ( pix_intermediate is None) else pix_intermediate self.wdeg = wdeg self.hdeg = hdeg degree = u.degree vwidth = hdeg / 2. hwidth = wdeg / 2. # Box locations to slice from self.pos_south = np.array([[-vwidth + yoffset, -hwidth], [vwidth + yoffset, hwidth]]) * degree self.pos_eq = np.array([[-vwidth, -hwidth], [vwidth, hwidth]]) * degree # Get MPI comm self.comm = mpi_comm try: self.rank = mpi_comm.Get_rank() self.numcores = mpi_comm.Get_size() except: self.rank = 0 self.numcores = 1 if self.rank == 0: self.logger = io.get_logger("rotrecon") # Distribute MPI tasks num_each, each_tasks = mpi_distribute(nsims, self.numcores) self.mpibox = MPIStats(self.comm, num_each, tag_start=333) if self.rank == 0: self.logger.info("At most " + str(max(num_each)) + " tasks...") self.tasks = each_tasks[self.rank] # Initialize theory power spectra theory_file_root = "data/Aug6_highAcc_CDM" powspec_file = "data/Aug6_highAcc_CDM_lenspotentialCls.dat" self.ps = powspec.read_camb_full_lens(powspec_file).astype(self.dtype) self.theory = cosmology.loadTheorySpectraFromCAMB( theory_file_root, unlensedEqualsLensed=False, useTotal=False, TCMB=2.7255e6, lpad=9000, get_dimensionless=False) self.lmax = lmax self.count = 0
def __init__(self, loc='./data/spectra/'): # with open(loc+'Planck_Planck.pickle', 'rb') as handle: # self.pdict = pickle.load(handle) # with open(loc+'ACT_ACT.pickle', 'rb') as handle: # self.adict = pickle.load(handle) # with open(loc+'ACT_planck.pickle', 'rb') as handle: # self.apdict = pickle.load(handle) self.pdict = {} self.apdict = {} self.adict = {} for patch in ['deep56', 'boss']: for i in range(len(pfreqs)): for j in range(i, len(pfreqs)): array1 = pfreqs[i] array2 = pfreqs[j] self.pdict[patch, array1, array2] = load_spec(patch, array1, array2) acts = { 'boss': { 's15': ['pa1_f150', 'pa2_f150', 'pa3_f090', 'pa3_f150'] }, 'deep56': { 's14': ['pa1_f150', 'pa2_f150'], 's15': ['pa1_f150', 'pa2_f150', 'pa3_f090', 'pa3_f150'] } } for patch in ['deep56', 'boss']: combs = [] for season in acts[patch].keys(): for array in acts[patch][season]: combs.append((season, array)) ncombs = len(combs) for i in range(ncombs): season1, array1 = combs[i] for k in range(len(pfreqs)): self.apdict[patch, pfreqs[k], season1, array1] = load_spec(patch, pfreqs[k], (season1, array1)) for j in range(i, ncombs): season2, array2 = combs[j] self.adict[patch, season1, array1, season2, array2] = load_spec(patch, (season1, array1), (season2, array2)) croot = "data/cosmo2017_10K_acc3" self.theory = cosmology.loadTheorySpectraFromCAMB( croot, get_dimensionless=False) import pandas as pd self.adf = pd.read_csv("./data/spectra/wnoise.csv") # 545 and 857 are wrong self.planck_rms = { '030': 195, '044': 226, '070': 199, '100': 77, '143': 33, '217': 47, '353': 153, '545': 1000, '857': 1000 }
def comp_cltt(alex): if alex: lmax = 5000 res = 1.0 camb_root = "/gpfs01/astro/workarea/msyriac/data/act/theory/cosmo2017_10K_acc3" sim_name = "fullskyLensedMapUnaberrated_T_00002.fits" #sim_name = "fullskyLensedMap_T_00000.fits" ksim_name = "kappaMap_00002.fits" sim_location = "/gpfs01/astro/workarea/msyriac/data/sims/dw/" else: lmax = 3000 res = 1.5 camb_root = "/astro/u/msyriac/repos/quicklens/quicklens/data/cl/planck_wp_highL/planck_lensing_wp_highL_bestFit_20130627" sim_name = "lensed_map_seed_1.fits" ksim_name = "kappa_map_seed_1.fits" sim_location = "/gpfs01/astro/workarea/msyriac/data/depot/falafel/" theory = cosmology.loadTheorySpectraFromCAMB(camb_root, get_dimensionless=False) Xmap = enmap.read_map(sim_location + sim_name) ikappa = enmap.read_map(sim_location + ksim_name) if alex: shape, wcs = enmap.fullsky_geometry(res=np.deg2rad(res / 60.), proj="car") Xmap.wcs = wcs ikappa.wcs = wcs calm = cs.map2alm(Xmap, lmax=lmax).astype(np.complex128) kalm = cs.map2alm(ikappa, lmax=lmax).astype(np.complex128) cls = hp.alm2cl(calm) clskk = hp.alm2cl(kalm) lsc = np.arange(0, len(cls), 1) print(cls[:5]) print(clskk[:5]) cls[lsc < 2] = np.nan clskk[lsc < 2] = np.nan bin_edges = np.logspace(np.log10(2), np.log10(lmax), 40) binner = stats.bin1D(bin_edges) ls = np.arange(0, lmax, 1) cltt = theory.lCl('TT', ls) clkk = theory.gCl('kk', ls) cents, btt = binner.binned(ls, cltt) cents, bcc = binner.binned(lsc, cls) cents, bttkk = binner.binned(ls, clkk) cents, bcckk = binner.binned(lsc, clskk) # plot pl = io.Plotter(yscale='log', xscale='log', xlabel='$\\ell$', ylabel='$C_{\\ell}$') pl.add(ls, ls**2. * theory.lCl('TT', ls), lw=3, color='k') pl.add(cents, cents**2. * btt, ls="none", marker="x") pl.add(cents, cents**2. * bcc, ls="none", marker="o") pl.done(io.dout_dir + "fullsky_sim_test_cmb_alex_" + str(alex) + ".png") pl = io.Plotter(yscale='log', xscale='log', xlabel='$L$', ylabel='$C_L$') pl.add(ls, theory.gCl('kk', ls), lw=3, color='k') pl.add(cents, bttkk, ls="none", marker="x") pl.add(cents, bcckk, ls="none", marker="o") pl.done(io.dout_dir + "fullsky_sim_test_kk_alex_" + str(alex) + ".png") pl = io.Plotter(xscale='log', xlabel='$L$', ylabel='$\\delta C_L / C_L$') pl.add(cents, (bcc - btt) / btt, ls="-", marker="o", label="cmb") pl.add(cents, (bcckk - bttkk) / bttkk, ls="-", marker="o", label="kk") pl.hline() pl._ax.set_ylim(-0.2, 0.2) pl.done(io.dout_dir + "fullsky_sim_test_alex_diff_" + str(alex) + "_2.png")