def load_alm_fg(self, set_idx, sim_idx, fgflux='sehgal09'): print("loading fg alm") alm_fg90_150 = None if fgflux == 'sehgal09': alm_file_postfix = '' if self.eulers == ( 0, 0, 0) else '_rot_{}_{}_{}'.format( self.eulers[0], self.eulers[1], self.eulers[2]) #fg_file_temp = os.path.join(self.signal_path, 'fullskyCOMBINED_NODUST_f{}_set%02d_%05d%s.fits' %(set_idx, 0, alm_file_postfix)) fg_file_temp = os.path.join( self.signal_path, 'fullskyCOMBINED_NODUST_f{}_set%02d_%05d%s.fits' % (set_idx, set_idx, alm_file_postfix)) print(fg_file_temp) alm_fg090 = np.complex128( hp.fitsfunc.read_alm(fg_file_temp.format('%03d' % 90), hdu=(1))) alm_fg150 = np.complex128( hp.fitsfunc.read_alm(fg_file_temp.format('%03d' % 148), hdu=(1))) alm_fg90_150 = np.stack([alm_fg090, alm_fg150]) elif fgflux == 'sehgal09_gauss': ## generate GRF FGs matching sehgal09 flux fg_file = os.path.join(actsim_root, '../data/Sehgal09FG_nodust_15mJycut.dat') seed = (set_idx, 0, 1, sim_idx, 0) fg_power = powspec.read_spectrum(fg_file, ncol=3, expand='row') alm_fg90_150 = curvedsky.rand_alm_healpy(fg_power, seed=seed) else: assert (False) return alm_fg90_150
def load_cmb_alm(self, set_idx, sim_idx, alm_file_postfix): ps = self.ps_unlen if self.cmb_type == 'UnlensedCMB' else self.ps_len print("generating cmb alm for %s" % self.cmb_type) return curvedsky.rand_alm_healpy(ps, lmax=self.lmax, seed=seedgen.get_cmb_seed( set_idx, sim_idx))
def test_b_sign(self): """ We generate a random IQU map with geometry such that cdelt[0]<0 We transform this to TEB with map2harm and map2alm followed by scalar harm2map and alm2map and use these as reference T,E,B maps. We flip the original map along the RA direction. We transform this to TEB with map2harm and map2alm followed by scalar harm2map and alm2map and use these as comparison T,E,B maps. We compare these maps. """ ells,cltt,clee,clbb,clte = np.loadtxt(DATA_PREFIX+"cosmo2017_10K_acc3_lensedCls.dat",unpack=True) ps_cmb = np.zeros((3,3,ells.size)) ps_cmb[0,0] = cltt ps_cmb[1,1] = clee ps_cmb[2,2] = clbb ps_cmb[1,0] = clte ps_cmb[0,1] = clte np.random.seed(100) # Curved-sky is fine lmax = 1000 alm = curvedsky.rand_alm_healpy(ps_cmb,lmax=lmax) shape,iwcs = enmap.fullsky_geometry(res=np.deg2rad(10./60.)) wcs = enmap.empty(shape,iwcs)[...,::-1].wcs shape = (3,) + shape imap = curvedsky.alm2map(alm,enmap.empty(shape,wcs)) oalm = curvedsky.map2alm(imap.copy(),lmax=lmax) rmap = curvedsky.alm2map(oalm,enmap.empty(shape,wcs),spin=0) imap2 = imap.copy()[...,::-1] oalm = curvedsky.map2alm(imap2.copy(),lmax=lmax) rmap2 = curvedsky.alm2map(oalm,enmap.empty(shape,wcs),spin=0) assert np.all(np.isclose(rmap[0],rmap2[0])) assert np.all(np.isclose(rmap[1],rmap2[1])) assert np.all(np.isclose(rmap[2],rmap2[2])) # Flat-sky px = 2.0 N = 300 shape,iwcs = enmap.geometry(pos=(0,0),res=np.deg2rad(px/60.),shape=(300,300)) shape = (3,) + shape a = enmap.zeros(shape,iwcs) a = a[...,::-1] wcs = a.wcs seed = 100 imap = enmap.rand_map(shape,wcs,ps_cmb,seed=seed) kmap = enmap.map2harm(imap.copy()) rmap = enmap.harm2map(kmap,spin=0) # reference map imap = imap[...,::-1] kmap = enmap.map2harm(imap.copy()) rmap2 = enmap.harm2map(kmap,spin=0)[...,::-1] # comparison map assert np.all(np.isclose(rmap[0],rmap2[0])) assert np.all(np.isclose(rmap[1],rmap2[1],atol=1e0)) assert np.all(np.isclose(rmap[2],rmap2[2],atol=1e0))
def get_map(self,seed=None): """Get correlated galaxy and kappa map """ from pixell import curvedsky alms = curvedsky.rand_alm_healpy(self.ps, lmax=int(self.lmax)+1, seed=seed) ncomp = 1 if len(self.shape)==2 else self.shape[0] omap = enmap.empty((ncomp,)+self.shape[-2:], self.wcs, dtype=np.float64) omap = curvedsky.alm2map(alms, omap, spin=0) return alms,omap
def test_rand_alm(self): def nalm(lmax): return (lmax + 1) * (lmax + 2) / 2 lmaxes = [50, 100, 150, 300] mypower = np.ones(50) for lmax in lmaxes: palm = curvedsky.rand_alm(mypower, lmax = lmax) halm = curvedsky.rand_alm_healpy( mypower, lmax = lmax) print("nalm(%i) = %i, curvedsky.rand_alm gives %s, curvedsky.rand_alm_healpy gives %s "\ % (lmax, \ nalm(lmax),\ palm.shape, \ halm.shape) ) assert np.all(np.isclose(np.asarray(palm.shape),np.asarray(halm.shape)))
def load_alm_fg(self, set_idx, sim_idx, fgflux): print("loading fg alm") seed = seedgen.get_fg_seed(set_idx, sim_idx, fgflux) if fgflux == "15mjy": print("loading FG with 15mJy fluxcut") fg_file = os.path.join(actsim_root, '../data/fg.dat') elif fgflux == "100mjy": print("loading FG with 100mJy fluxcut") fg_file = os.path.join(actsim_root, '../data/highflux_fg.dat') elif fgflux == "quick-srcfree": print("loading FG with srcfree fg") fg_file = os.path.join(actsim_root, '../data/quick_srcfree_combined_d56.dat') else: assert (False) ### :o fg_power = powspec.read_spectrum(fg_file, ncol=3, expand='row') alm_fg90_150 = curvedsky.rand_alm_healpy(fg_power, seed=seed) #, lmax=lmax_sg) return alm_fg90_150
def update_signal_index(self,sim_idx,set_idx=0,cmb_type='LensedUnabberatedCMB'): signal_path = sints.dconfig['actsims']['signal_path'] cmb_file = os.path.join(signal_path, 'fullsky%s_alm_set%02d_%05d.fits' %(cmb_type, set_idx, sim_idx)) self.alms['cmb'] = hp.fitsfunc.read_alm(cmb_file, hdu = (1,2,3)) comptony_seed = seed_tracker.get_fg_seed(set_idx, sim_idx, 'comptony') fgres_seed = seed_tracker.get_fg_seed(set_idx, sim_idx, 'srcfree') #self.alms['comptony'] = curvedsky.rand_alm_healpy(self.cyy, seed = comptony_seed) self.alms['comptony'] = curvedsky.rand_alm(self.cyy, lmax=self.ellmax, seed = comptony_seed) #!!!! #self.alms['comptony'] = curvedsky.rand_alm(self.cyy, lmax=self.ellmax, seed = 1) #!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if self.cfgres is not None: self.alms['fgres'] = curvedsky.rand_alm_healpy(self.cfgres, seed = fgres_seed) # SWITCHED BACK!!! #self.alms['fgres'] = curvedsky.rand_alm(self.cfgres, lmax=self.ellmax, seed = fgres_seed) # 1. convert to maximum ellmax lmax = max([hp.Alm.getlmax(self.alms[comp].shape[1]) for comp in self.alms.keys()]) for comp in self.alms.keys(): if hp.Alm.getlmax(self.alms[comp].shape[1])!=lmax: self.alms[comp] = maps.change_alm_lmax(self.alms[comp], lmax) self.lmax = lmax
from pixell import enmap, powspec, curvedsky import numpy as np import os, sys from mapsims import cmb import healpy as hp seed = 10 lmax = 150 iteration_num = 0 cmb_set = 0 lensed = False aberrated = False nside = 32 theory_filename = "mapsims/data/test_scalCls.dat" save_name = "mapsims/data/test_map.fits" output_directory = "mapsims/data" output_file = cmb._get_cmb_map_string(output_directory, iteration_num, cmb_set, lensed, aberrated) ps = powspec.read_spectrum(theory_filename) alms = curvedsky.rand_alm_healpy(ps, lmax=lmax, seed=seed, dtype=np.complex64) hp.write_alm(output_file, alms, overwrite=True) imap = cmb.get_cmb_sky( iteration_num=0, nside=nside, cmb_dir=output_directory, lensed=False, aberrated=False, ) hp.write_map(save_name, imap, overwrite=True)
ls, Als['TT'], Als['EE'], Als['EB'], Al_te_alt, Als['TB'], Als['mvpol'], Als[ 'mv'], Als['TE'] = np.loadtxt(args.norm_file, unpack=True) for task in my_tasks: # Load sims sindex = str(task).zfill(5) alm = maps.change_alm_lmax( hp.read_alm(sim_location + "fullskyLensedUnabberatedCMB_alm_set00_%s.fits" % sindex, hdu=(1, 2, 3)), mlmax).astype(dtype) # Add beam deconvolved noise alm = alm + np.nan_to_num( qe.almxfl( cs.rand_alm_healpy( ps_noise, lmax=mlmax, seed=(100, 200, task), dtype=dtype), 1. / lbeam)) ntt = maps.interp(ells, np.nan_to_num(ps_noise[0, 0] / lbeam**2.)) npp = maps.interp(ells, np.nan_to_num(ps_noise[1, 1] / lbeam**2.)) # Filter talm_y = qe.filter_alms(alm[0], lambda x: 1. / (theory.lCl('TT', x) + ntt(x)), args.lmint, args.lmaxt) ealm_y = qe.filter_alms(alm[1], lambda x: 1. / (theory.lCl('EE', x) + npp(x)), args.lminp, args.lmaxp) balm_y = qe.filter_alms(alm[2], lambda x: 1. / (theory.lCl('BB', x) + npp(x)), args.lminp, args.lmaxp)
pl.hline(y=1) pl.done("/scratch/r/rbond/msyriac/data/depot/tilec/plots/allfits.png") #sys.exit() #lsave = 400 #np.savetxt("/scratch/r/rbond/msyriac/data/for_sigurd/bad_matrix.txt",cfgres[:,:,lsave]) # sys.exit() fgres_seed = 1 print("done with txt") print(cfgres.dtype) alms2 = curvedsky.rand_alm(cfgres, lmax=lmax, seed=fgres_seed) alms1 = curvedsky.rand_alm_healpy(cfgres, seed=fgres_seed) print("done") for i in range(narrays): for j in range(i, narrays): fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.set_xlabel('l', fontsize=14) ax.set_ylabel('D', fontsize=14) ax.set_xscale('linear', nonposx='clip') ax.set_yscale('log', nonposy='clip') qid1 = qids[i] qid2 = qids[j] clth = cfgres[i, j]
dcomb = 'joint' if False: qids = "d56_01,d56_02,d56_03,d56_04,d56_05,d56_06,p01,p02,p03,p04,p05,p06,p07,p08".split(',') #qids = "d56_01,d56_02".split(',') pows = {} seeds = [12,11] for seed in seeds: sim_idx = seed set_idx = 0 fgres_seed = seed_tracker.get_fg_seed(set_idx, sim_idx, 'srcfree') jsim = pipeline.JointSim(qids,fg_res_version="fgfit_deep56",ellmax=8101,bandpassed=True,no_act_color_correction=False,ccor_exp=-1) alms = curvedsky.rand_alm_healpy(jsim.cfgres, seed = fgres_seed) narrays = alms.shape[0] for i in range(narrays): for j in range(i,narrays): qid1 = qids[i] qid2 = qids[j] cls = hp.alm2cl(alms[i],alms[j]) ls = np.arange(cls.size) pows[qid1+qid2+str(seed)] = cls.copy() for i in range(narrays): for j in range(i,narrays): qid1 = qids[i] qid2 = qids[j] pl = io.Plotter(xyscale='linlog',scalefn = lambda x: x**2./2./np.pi, xlabel='l',ylabel='D')