def load_alms(self, i, iset): key = (i, iset) if len(self.keys) > self.maxcache: key0 = self.keys[0] del self.cache[key0] self.keys.pop(0) alms = maps.change_alm_lmax(solenspipe.get_cmb_alm(i, iset), self.mlmax) self.cache[key] = alms return alms
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
def get_websky_sim(qid,shape,wcs,ra_pix_shift=None,components=['cmb','cib','tsz','ksz','ksz_patchy'], bandpassed=True,no_act_color_correction=False,cmb_set=0): # load cmb + ksz + tsz + isw alm # get cfreq # add nearest cib scaled to cfreq gmix = lambda x: gen_mix(qid,x,bandpassed=bandpassed,bandpass_shifts=None,no_act_color_correction=no_act_color_correction) owcs = wcs.copy() if shift is not None: owcs.wcs.crpix -= np.asarray([ra_pix_shift,0]) lmax = 8192*3 asize = hp.Alm.getsize(lmax) oalms = np.zeros((3,asize)) rpath = sints.dconfig['actsims']['websky_path'] + "/" if 'cmb' in components: ialm = hp.read_alm(rpath + "lensed_alm_seed%d.fits" % cmb_set,hdu=(1,2,3)) for i in range(3): oalms[i] = oalms[i] + maps.change_alm_lmax(ialm[i], lmax) if 'tsz' in components: tconversion = gmix('tSZ') # !!! ialm = hp.read_alm(rpath + "alms/tsz_8192_alm.fits" ) oalms[0] = oalms[0] + ialm * tconversion
# norm dict Als = {} with bench.show("norm"): ls,Als['TT'],Als['EE'],Als['EB'], \ Als['TE'],Als['TB'],al_mv_pol, \ al_mv,Al_te_hdv = solenspipe.initialize_generic_norm(lmin,lmax, \ tag='noiseless') Als['mv'] = al_mv Als['mvpol'] = al_mv_pol al_mv = Als[polcomb] with bench.show("load alm"): alm = solenspipe.get_cmb_alm(i=0, iset=0) alm = maps.change_alm_lmax(alm, mlmax) ikalm = maps.change_alm_lmax( solenspipe.get_kappa_alm(i=0).astype(np.complex128), mlmax) with bench.show("recon"): rkalm = qfunc(polcomb, alm, alm) nls = al_mv * ls**2. / 4. xcls = hp.alm2cl(rkalm, ikalm) rcls = hp.alm2cl(rkalm, rkalm) icls = hp.alm2cl(ikalm, ikalm) ells = np.arange(len(icls)) clkk = theory.gCl('kk', ells)
# Theory thloc = sim_location + "cosmo2017_10K_acc3" theory = cosmology.loadTheorySpectraFromCAMB(thloc, get_dimensionless=False) # Norm Als = {} 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)
seed = (0,0,0) t_alm,e_alm,b_alm = solint.get_kmap(ch,seed,lmin,lmax,filtered=True) # Reconstruction with bench.show("recon"): rkalm = qe.filter_alms(solint.get_mv_kappa(polcomb,t_alm,e_alm,b_alm),maps.interp(ls,Als[polcomb])) hp.write_map(config['data_path']+"mbs_sim_v0.1.0_mv_lensing_map.fits",hp.alm2map(rkalm,nside),overwrite=True) hp.write_map(config['data_path']+"mbs_sim_v0.1.0_mv_lensing_mask.fits",mask,overwrite=True) # Filtered reconstruction fkalm = hp.almxfl(rkalm,wfilt) frmap = hp.alm2map(fkalm,nside=256) rmap=hp.alm2map(rkalm,nside=256) # Input kappa # TODO: Does this really need to be masked? ikalm = maps.change_alm_lmax(hp.map2alm(hp.alm2map(get_kappa_alm(0).astype(np.complex128),nside=solint.nside)*solint.mask),2*solint.nside) # Verify input x cross w4=np.mean(solint.mask**4) w3 = np.mean(solint.mask**3) # Mask factors w2 = np.mean(solint.mask**2) xcls = hp.alm2cl(rkalm,ikalm)/w3 icls = hp.alm2cl(ikalm,ikalm)/w2 rcls=hp.alm2cl(rkalm,rkalm)/w4 #reconstruction auto ells = np.arange(len(icls)) clkk = theory.gCl('kk',ells) pl = io.Plotter(xyscale='loglog',xlabel='$L$',ylabel='$C_L$') pl.add(ells,clkk,ls="-",lw=3,label='theory input') pl.add(ells,xcls,alpha=0.4,label='input x recon') pl.add(ells,icls,alpha=0.4,label='input x input')
def get_cls(alms): calm = maps.change_alm_lmax(alms, lmax) cls = hp.alm2cl(calm) ls = np.arange(len(cls)) return ls, cls