import healpy as hp from pixell import enmap, curvedsky from orphics import maps,io from soapack import interfaces as sints from tilec.pipeline import JointSim qids = ['d56_03','p05'] jsim = JointSim(qids,None) jsim.update_signal_index(0) mask = sints.get_act_mr3_crosslinked_mask('deep6') imap = jsim.compute_map(mask.shape,mask.wcs,'p05',include_cmb=True,include_tsz=True,include_fgres=True) io.hplot(imap,'planck') imap = jsim.compute_map(mask.shape,mask.wcs,'d56_03',include_cmb=True,include_tsz=True,include_fgres=True) io.hplot(imap,'act')
ystack = ystack / i * 1e6 sstack = sstack / i cstack = cstack / i # Approximate geometry of stack _, nwcs = enmap.geometry(pos=(0, 0), shape=istack.shape, res=np.deg2rad(0.5 / 60.)) # Plot images if do_images: io.hplot(enmap.enmap(istack, nwcs), "istack", ticks=5, tick_unit='arcmin', grid=True, colorbar=True, color='gray', upgrade=4, min=-5, max=25) io.hplot(enmap.enmap(ystack, nwcs), "ystack", ticks=5, tick_unit='arcmin', grid=True, colorbar=True, color='gray', upgrade=4, min=-5, max=25)
kmask = maps.mask_kspace(shape,wcs,lmin=Lmin,lmax=Lmax) feed_dict['uC_T_T'] = cov feed_dict['tC_T_T'] = cov + (wnoise*np.pi/180/60)**2 / kbeam**2 qe = symlens.QE(shape,wcs,feed_dict,'hu_ok','TT',xmask=xmask,ymask=ymask,kmask=kmask) s = stats.Stats() for task in my_tasks: cmb = maps.filter_map(mgen.get_map(seed=(1,task))[0],kbeam) nseed = (2,task) nmap = maps.white_noise(shape,wcs,noise_muK_arcmin=None,seed=nseed,ipsizemap=pmap,div=ivar) obs = cmb + nmap kobs = enmap.fft(obs,normalize='phys')/kbeam kobs[~np.isfinite(kobs)] = 0 feed_dict['X'] = kobs feed_dict['Y'] = kobs krecon = qe.reconstruct(feed_dict) print(cmb.shape,nmap.shape,krecon.shape) s.add_to_stack('kreal',krecon.real) s.add_to_stack('kimag',krecon.imag) s.get_stacks() mf = enmap.ifft(s.stacks['kreal'] + 1j*s.stacks['kimag'],normalize='phys') io.hplot(mf,'mf.png')
""" Loads a catalog Maps it Smooths it Thresholds it Projects it onto ACT This gives a mask of 1s and 0s from which a random catalog can be made """ paths = cutils.paths #cat_type = "wise_panstarrs" #cat_type = "madcows_photz" cat_type = args.sys[1] meanfield = False # cat_type = "sdss_redmapper" # meanfield = True shape,wcs = enmap.fullsky_geometry(res=1 * utils.degree) ras,decs,_ = cutils.catalog_interface(cat_type,is_meanfield=meanfield) cmapper = catalogs.CatMapper(ras,decs,shape=shape,wcs=wcs) cmap = maps.binary_mask(enmap.smooth_gauss(cmapper.counts,2 * utils.degree),1e-3) io.hplot(cmap,'counts') shape,wcs = enmap.read_map_geometry(paths.coadd_data + f"act_planck_s08_s18_cmb_f150_daynight_srcfree_map.fits") omap = enmap.project(cmap,shape,wcs,order=0) io.plot_img(omap,'pcounts') enmap.write_map(f'{paths.scratch}{cat_type}_mask.fits',omap)
imap = enmap.rand_map(shape, wcs, np.ones((1, 1, shape[0], shape[1]))) ta = tiling.TiledAnalysis(shape, wcs, comm) ta.initialize_output("out") for ext, ins in ta.tiles(): emap = ext(imap) emap = filter_map(emap) ta.update_output("out", emap, ins) outmap = ta.get_final_output("out") # print(comm.rank) # io.plot_img(outmap,"rank_%d" % comm.rank) if comm.rank == 0: fcmap = filter_map(imap) io.hplot(enmap.downgrade(imap, 8)) io.hplot(enmap.downgrade(outmap, 8)) io.hplot(enmap.downgrade(fcmap, 8)) io.plot_img(enmap.downgrade(outmap - fcmap, 8), lim=1) # brmap = enmap.zeros(observed.shape[-2:],observed.wcs) # bwrmap = enmap.zeros(observed.shape[-2:],observed.wcs) # shape,wcs = observed.shape,observed.wcs # epboxes = get_pixboxes(shape,wcs,width_deg,pad_deg) # pboxes = get_pixboxes(shape,wcs,width_deg,pad_deg-2.*rtap_deg) # for i in range(pboxes.shape[0]): # for j in range(pboxes.shape[1]): # omap = observed.copy() # #print(npix(pboxes[i,j])) # emap = enmap.extract_pixbox(omap,epboxes[i,j],wrap=shape[-2:]) # print("Min ell: ", maps.minimum_ell(emap.shape,emap.wcs))
mgen = maps.MapGen(shape,wcs,ps_signal[None,None]) ngen = maps.MapGen(shape,wcs,ps_noise[None,None]*nsplits) cmb = mgen.get_map(seed=(1,0)) observed = [] for i in range(nsplits): nreal = ngen.get_map(seed=(2,i)) observed.append(cmb+nreal) kmaps = [] fc = maps.FourierCalc(shape,wcs) for i in range(nsplits): kmaps.append(fc.power2d(observed[i])[1]) io.hplot(maps.ftrans(ps_noise),"noise_orig",grid=False) io.hplot(maps.ftrans(ps_signal),"signal_orig",grid=False) io.hplot(maps.ftrans(ps_noise+ps_signal),"total_orig",grid=False) scov,ncov,_ = tutils.ncalc(np.array(kmaps)[None],0,0,fc) io.hplot(maps.ftrans(ncov),"noise_real",grid=False) io.hplot(maps.ftrans(scov),"signal_real",grid=False) dscov = covtools.signal_average(scov,bin_width=80,kind=0) dncov0 = covtools.signal_average(ncov,bin_width=80,kind=0) dncov = covtools.noise_average(ncov,dfact=(16,16),lmin=300,lmax=8000,wnoise_annulus=500,bin_annulus=20, lknee_guess=3000,alpha_guess=-4,nparams=None,modlmap=None, verbose=False,method="fft",radial_fit=True, oshape=None,upsample=True)[0]
# print(ksol[px[0],px[1]]) # print(ksol[px[0]-11,px[1]]) # print(optile[px[0],px[1]]) # print(optile[px[0]-1,px[1]]) # print(modlmap[px[0],px[1]]) # print(modlmap[px[0]-1,px[1]]) # # pftile = ptile # # pftile[modlmap>300] = 0 # # print(np.sort(pftile[pftile>0])) # # print(modlmap[np.isclose(ptile,1.52256073e+02)]) # # io.plot_img(np.log10(np.fft.fftshift(ptile)),os.environ['WORK']+"/tiling/ptile_%d_smap" % i) # # io.hplot(enmap.enmap(np.log10(np.fft.fftshift(ptile)),ewcs),os.environ['WORK']+"/tiling/phtile_%d_smap" % i) smap = enmap.ifft(kbeam * enmap.enmap(ksol, ewcs), normalize='phys').real if solution == 'CMB': io.hplot(smap, os.environ['WORK'] + "/tiling/tile_%d_smap" % i) io.power_crop(np.real(ksol * ksol.conj()), 100, os.environ['WORK'] + "/tiling/ptile_%d.png" % i) # sys.exit() ta.update_output(solution, smap, inserter) #ta.update_output("processed",c*civar,inserter) #ta.update_output("processed_ivar",civar,inserter) #pmap = ilc.do_ilc #ta.update_output("processed",pmap,inserter) print("Rank %d done" % comm.rank) for solution in solutions: pmap = ta.get_final_output(solution) if comm.rank == 0: io.hplot(pmap, os.environ['WORK'] + "/tiling/map_%s" % solution) mask = sints.get_act_mr3_crosslinked_mask("deep56") io.hplot(
""" Given the mask saved from mapcat.py, generate and save a random catalog. """ paths = cutils.paths #cat_type = "wise_panstarrs" #cat_type = "madcows_photz" cat_type = args.sys[1] Nx = int(args.sys[2]) ras,decs,_,_,_ = cutils.catalog_interface(cat_type,is_meanfield=False) N = Nx * len(ras) mask = enmap.read_map(f'{paths.scratch}{cat_type}_mask.fits') shape,wcs = mask.shape,mask.wcs Npix = mask[mask>0].size inds = np.random.choice(Npix,size=N,replace=False) pixs = enmap.pixmap(shape,wcs) print(pixs.shape) coords = mask.pix2sky(pixs[:,mask>0][:,inds]) / utils.degree io.save_cols(paths.data+f"{cat_type}_randoms.txt",(coords[1],coords[0])) print(coords.shape) cmapper = catalogs.CatMapper(coords[1],coords[0],shape=shape,wcs=wcs) io.hplot(enmap.downgrade(cmapper.counts,16),'randcounts',mask=0)
def pshow(cov,fname=None): io.hplot(np.log10(enmap.downgrade(enmap.enmap(np.fft.fftshift(cov),cov.wcs),2)),fname) """
# rot="gal,equ", first=0, is_alm=True, return_alm=False, f_ell=None) # io.hplot(nmap[sels[region]],'fig_full_nmap_%s' % region,color='gray',grid=True,colorbar=True, # annotate=annot,min=-1.25e-5,max=3.0e-5,ticks=t[region],mask=0,downgrade=down,mask_tol=1e-14) # io.hplot(pmap[sels[region]],'fig_full_pmap_%s' % region,color='planck',grid=True,colorbar=True, # ticks=t[region],downgrade=down) # io.hplot(ymap[sels[region]],'fig_full_ymap_%s' % region,color='gray',grid=True,colorbar=True, # annotate=annot,min=-1.25e-5,max=3.0e-5,ticks=t[region],mask=0,downgrade=down,mask_tol=1e-14,font_size=fontsize) io.hplot(ymap[sels[region]], 'fig_full_ymap_%s' % region, color='gray', grid=True, colorbar=True, annotate=annot, min=-0.7e-5, max=2.0e-5, ticks=t[region], mask=0, downgrade=down, mask_tol=1e-14, font_size=fontsize) io.hplot(smap[sels[region]], 'fig_full_smap_%s' % region, color='planck', grid=True, colorbar=True, range=300, ticks=t[region], mask=0, downgrade=down,
from orphics import maps,io,cosmology,catalogs from pixell import enmap,reproject import numpy as np import os,sys,shutil from soapack import interfaces as sints import healpy as hp box = np.deg2rad([ [11,-173.5], [13.5,-171] ]) rosat = enmap.read_map("/scratch/r/rbond/msyriac/data/for_sigurd/rosat_r7_boss.fits").submap(box) print(rosat.shape,maps.resolution(rosat.shape,rosat.wcs) * 180.*60./np.pi) version = "map_v1.0.0_rc_joint" cversion = "v1.0.0_rc" region = 'boss' yname = "/scratch/r/rbond/msyriac/data/depot/tilec/v1.0.0_rc_20190919/%s_%s/tilec_single_tile_%s_comptony_%s.fits" % (version,region,region,version) ymap = enmap.read_map(yname).submap(box) print(ymap.center()*180./np.pi) rosat = enmap.project(rosat,ymap.shape,ymap.wcs) io.hplot(np.log10(rosat),'fig_virgo_rosat') #io.hplot(enmap.smooth_gauss(ymap,np.deg2rad(3./60.)),'fig_virgo_act',color='gray') #,min=-1.25e-5,max=3.0e-5 io.hplot(ymap,'fig_virgo_act',color='gray') #,min=-1.25e-5,max=3.0e-5
fg = "tsz" #ppath = "/scratch/r/rbond/msyriac/data/depot/tilec/map_rad_src_test_v1.0.0_rc_deep56/" ppath = "/scratch/r/rbond/msyriac/data/depot/tilec/map_%s_src_test_v1.0.0_rc_deep56/" % fg dec = 0 ra = 10 #imap = enmap.read_map(ppath + "tilec_single_tile_deep56_comptony_map_rad_src_test_v1.0.0_rc.fits") imap = enmap.read_map( ppath + "tilec_single_tile_deep56_comptony_map_%s_src_test_v1.0.0_rc.fits" % fg) cut = reproject.cutout(imap, ra=np.deg2rad(ra), dec=np.deg2rad(dec), npix=80) #* 1e6 _, nwcs = enmap.geometry(pos=(0, 0), shape=cut.shape, res=np.deg2rad(0.5 / 60.)) print(cut.shape) io.hplot(enmap.enmap(cut, nwcs), "%scut" % fg, color='gray', colorbar=True, ticks=5, tick_unit='arcmin', font_size=12, upgrade=4, quantile=1e-3)
ystack = s.stacks['ystack'] cstack = s.stacks['cstack'] c150 = s.stacks['c150'] c1502 = s.stacks['c1502'] c1503 = s.stacks['c1503'] c1504 = s.stacks['c1504'] c1505 = s.stacks['c1505'] c090 = s.stacks['c090'] _, nwcs = enmap.geometry(pos=(0, 0), shape=ystack.shape, res=np.deg2rad(0.5 / 60.)) io.hplot(enmap.enmap(ystack, nwcs), "fig_qso_ystack_%s_%s" % (cversion, region), ticks=5, tick_unit='arcmin', grid=True, colorbar=True, color='gray', upgrade=4, quantile=1e-3) io.hplot(enmap.enmap(cstack, nwcs), "fig_qso_cstack_%s_%s" % (cversion, region), ticks=5, tick_unit='arcmin', grid=True, colorbar=True, color='gray', upgrade=4, quantile=1e-3) io.hplot(enmap.enmap(c150, nwcs), "fig_qso_c150_%s_%s" % (cversion, region),
from __future__ import print_function from orphics import maps,io,cosmology,stats from pixell import enmap import numpy as np import os,sys from tilec import utils as tutils,covtools,ilc c = tutils.Config() for ai in range(c.narrays): coadd = c.load_coadd_real(ai) io.hplot(coadd*c.mask,"fcoadd_%d" % ai)
cents, ac1d = binner.bin(c.fc.f2power(kcmap, kcmap)) pl = io.Plotter(yscale='log', scalefn=lambda x: x**2. / np.pi) pl.add(cents, as1d, ls="-") pl.add(cents, ac1d, ls="-") pl.add(cents, s1d, ls="--") pl.add(cents, c1d, ls="--") pl.done("snoise_data.png") smap = enmap.enmap(c.fc.ifft(ksmap).real, wcs) cmap = enmap.enmap(c.fc.ifft(kcmap).real, wcs) ysmap = enmap.enmap(c.fc.ifft(yksmap).real, wcs) ycmap = enmap.enmap(c.fc.ifft(ykcmap).real, wcs) ycmap_d = enmap.enmap(c.fc.ifft(ykcmap_d).real, wcs) # ycmap_dc = enmap.enmap(c.fc.ifft(ykcmap_dc).real,wcs) io.hplot(smap, "usmap") io.hplot(cmap, "ucmap") io.plot_img(smap, "umsmap.png", lim=300) io.plot_img(cmap, "umcmap.png", lim=300) #sbeam = 1.4 #cbeam = 2.2 skbeam = c.get_beam(modlmap, 's15_pa3_150') ckbeam = c.get_beam(modlmap, 's15_pa3_90') # Uncomment this back # smap = maps.filter_map(enmap.enmap(smap,wcs),skbeam) # cmap = maps.filter_map(enmap.enmap(cmap,wcs),ckbeam) # ysmap = maps.filter_map(enmap.enmap(ysmap,wcs),skbeam) # ycmap = maps.filter_map(enmap.enmap(ycmap,wcs),ckbeam) # ycmap_d = maps.filter_map(enmap.enmap(ycmap_d,wcs),ckbeam)
mask = enmap.read_map("%s/tilec_mask.fits" % savedir) dm = sints.ACTmr3(region=mask) fbeam = lambda x: dm.get_beam( x, "s15", "deep56", "pa3_f090", kind='normalized') name_map = {'CMB': 'cmb', 'tSZ': 'comptony', 'CIB': 'cib'} comps = "tilec_single_tile_" + args.region + "_" + name_map[ args.solution] + "_" + args.version lmin = args.lmin lmax = args.lmax w2 = np.mean(mask**2.) imap = enmap.read_map("%s/%s.fits" % (savedir, comps)) color = 'planck' if args.solution == 'CMB' else 'gray' io.hplot(imap, "map_%s_%s" % (args.solution, args.region), color='planck', grid=True) imap1 = dm.get_coadd(season="s15", patch=args.region, array="pa3_f090", srcfree=True, ncomp=1) imap2 = dm.get_coadd(season="s15", patch=args.region, array="pa3_f150", srcfree=True, ncomp=1) #io.hplot(imap2,"cmb_map_%s_s15_pa3_f150" % (args.region),color="planck",grid=True) #io.hplot(imap1,"cmb_map_%s_s15_pa3_f090" % (args.region),color="planck",grid=True) nmap = enmap.read_map("%s/%s_noise.fits" % (savedir, comps))
def process(dm, patch, array_id, mask, skip_splits=False, splits_fname=None, inpaint=True, fn_beam=None, cache_inpaint_geometries=True, verbose=True, plot_inpaint_path=None, do_pol=False, split_set=None): """ Return (nsplits,Ny,Nx) fourier transform Return (Ny,Nx) fourier transform of coadd This function applies no corrections for masks. split_set : None by default means it returns all splits. Otherwise, can be 0 or 1, which determines which half of the splits to use. E.g. for ACT with 4 splits, 0 will return split 0,1 and 1 will return split 2,3. """ qid = array_id if dm.name == 'act_mr3': season, array1, array2 = sints.arrays(qid, 'season'), sints.arrays( qid, 'array'), sints.arrays(qid, 'freq') array = '_'.join([array1, array2]) pixwin = True elif dm.name == 'planck_hybrid': season, patch, array = None, None, sints.arrays(qid, 'freq') pixwin = False wins = dm.get_splits_ivar(season=season, patch=patch, arrays=[array], ncomp=None)[0, :, 0, :, :] if splits_fname is None: splits = dm.get_splits(season=season, patch=patch, arrays=[array], ncomp=3, srcfree=True)[0, :, :, :, :] else: splits = enmap.read_map(splits_fname) if split_set is not None: fsplits = splits.shape[0] assert fsplits == 2 or fsplits == 4 hsplits = fsplits // 2 assert split_set in [0, 1] if split_set == 0: wins = wins[:hsplits] splits = splits[:hsplits] elif split_set == 1: wins = wins[hsplits:] splits = splits[hsplits:] assert splits.ndim == 4 nsplits = splits.shape[0] if split_set is None: assert nsplits == 2 or nsplits == 4 else: assert nsplits == 1 or nsplits == 2 assert nsplits == wins.shape[0] # Inpaint if inpaint and dm.name == 'act_mr3': rsplits = [] for i in range(nsplits): result = inpainting.inpaint_map_white( splits[i], wins[i], fn_beam, union_sources_version=None, plots=False, cache_name="qid_%s_splitnum_%d" % (qid, i) if cache_inpaint_geometries else None, verbose=verbose) rsplits.append(result[0, :, :].copy()) if plot_inpaint_path is not None: io.hplot(splits[i][0, :, :], "%s/uninpainted_qid_%s_splitnum_%d" % (plot_inpaint_path, qid, i), grid=True, color='planck') io.hplot(result[0, :, :], "%s/inpainted_qid_%s_splitnum_%d" % (plot_inpaint_path, qid, i), grid=True, color='planck') # if do_pol: # for i in range(1,3): # io.hplot(splits[i][0,:,:],"%s/uninpainted_qid_%s_splitnum_%d" % (plot_inpaint_path,qid,i),grid=True,color='planck') # io.hplot(result[0,:,:],"%s/inpainted_qid_%s_splitnum_%d" % (plot_inpaint_path,qid,i),grid=True,color='planck') rsplits = enmap.enmap(np.stack(rsplits), splits.wcs) else: rsplits = splits[:, 0, :, :] kdiffs, kcoadd = process_splits(rsplits, wins, mask, skip_splits=skip_splits, do_fft_splits=False, pixwin=pixwin) return kdiffs, kcoadd, wins
import os, sys from pixell import enmap from orphics import io tdir = '/scratch/r/rbond/msyriac/data/depot/tilec/v1.0.0_rc_20190919' def get_tsz_map(): pass for region in ['deep56', 'boss']: for dcomb in ['joint', 'act', 'planck']: for solution in ['cmb', 'tsz']: for deproj in [None, 'cib'] + [{ 'cmb': 'tsz', 'tsz': 'cmb' }[solution]]: fname = tutils.get_generic_fname(tdir, region, solution, deproj, dcomb) imap = enmap.downgrade(enmap.read_map(fname), 4) bname = 'plot_' + os.path.basename(fname).replace('.fits', '') io.hplot(imap, bname, grid=True, color={ 'cmb': 'planck', 'tsz': 'gray' }[solution]) #print(os.path.basename(fname))
from __future__ import print_function from orphics import maps, io, cosmology from pixell import enmap import numpy as np import os, sys from soapack import interfaces as sints mask = sints.get_act_mr3_crosslinked_mask("boss", version='padded_v1') shape, wcs = mask.shape, mask.wcs print(np.rad2deg(enmap.pix2sky(shape, wcs, (shape[-2], shape[-1])))) sys.exit() io.hplot(mask, "mask.png") print(mask.shape) dm = sints.PlanckHybrid(region=mask) ivars = dm.get_splits_ivar(['100'], ncomp=1) splits = dm.get_splits(['100'], ncomp=1) # print(ivars.shape) # print(ivars[ivars<=0].size/ivars.size*100.) # print(ivars[ivars<=0].size) # print(splits[ivars<=0]) # print(splits[ivars<=0].max()) # splits[ivars>0] = np.nan # splits[ivars<=0] = 1 io.hplot(splits[0, 1, 0], "boss.png")
ymap = reconvolve(ymap, ybname, fwhm=2.2) cmap = reconvolve(cmap, cbname, fwhm=2.2) smap = reconvolve(smap, sbname, fwhm=2.2) box = np.deg2rad(np.array([[-2, 12], [2, 18]])) enmap.write_map("ymap_%s.fits" % region, ymap) enmap.write_map("smap_%s.fits" % region, smap) enmap.write_map("ycutout.fits", ymap.submap(box)) io.hplot(ymap.submap(box), 'fig_region_ymap', color='gray', grid=True, colorbar=True, annotate='paper/public_clusters.csv', min=-1.25e-5, max=3.0e-5) io.hplot(cmap.submap(box), 'fig_region_cmap', color='planck', grid=True, colorbar=True, range=300, annotate='paper/public_clusters.csv') io.hplot(smap.submap(box), 'fig_region_smap', color='planck', grid=True, colorbar=True,
pl.add(ls,nls,ls="--",label='theory noise per mode') pl._ax.set_xlim(20,4000) pl.done(config['data_path']+"xcls_%s.png" % polcomb) # Filtered input fikalm = hp.almxfl(ikalm,wfilt) fimap = hp.alm2map(fikalm,nside=256) # Resampled mask dmask = hp.ud_grade(mask,nside_out=256) dmask[dmask<0] = 0 # Mollview plots io.mollview(frmap*dmask,config['data_path']+"wrmap1.png",xsize=1600,lim=8e-6) io.mollview(fimap*dmask,config['data_path']+"wimap1.png",xsize=1600,lim=8e-6) # CAR plots shape,wcs = enmap.band_geometry(np.deg2rad((-70,30)),res=np.deg2rad(0.5*8192/512/60.)) omask = reproject.enmap_from_healpix(dmask, shape, wcs,rot=None) omap = cs.alm2map(fkalm, enmap.empty(shape,wcs)) io.hplot(omap*omask,config['data_path']+"cwrmap1",grid=True,ticks=20,color='gray') omap = cs.alm2map(fikalm, enmap.empty(shape,wcs)) io.hplot(omap*omask,config['data_path']+"cwimap1",grid=True,ticks=20,color='gray')
p18 = enmap.downgrade( enmap.read_map(fname, box=box, sel=np.s_[0, ...]), 4) ip18 = enmap.downgrade(enmap.read_map(ifname, box=box, sel=np.s_[0, ...]), 4, op=np.sum) print(p18.shape, ip18.shape) return p18 #%% p18 = load_map('v20') io.hplot(p18, colorbar=True, range=40000) # %% p20 = load_map() io.hplot(p20, colorbar=True, range=40000) # %% taper, _ = maps.get_taper_deg(p18.shape, p18.wcs) bin_edges = np.arange(100, 3000, 80) cents, c18 = maps.binned_power(p18, bin_edges=bin_edges, mask=taper) cents, c20 = maps.binned_power(p20, bin_edges=bin_edges, mask=taper) # %% pl = io.Plotter('Dell') pl.add(cents, c18, label='Planck 2018') pl.add(cents, c20, label='Planck 2020') pl.done() # %%
_, nwcs = enmap.geometry(pos=(0, 0), shape=ystack.shape, res=np.deg2rad(0.5 / 60.)) return rank, enmap.enmap( ystack, nwcs), enmap.enmap(cstack, nwcs), enmap.enmap( dstack, nwcs), N, cents, y1ds, c1ds, d1ds, ry1d, rc1d, rd1d else: return rank, None, None, None, None, None, None, None, None, None, None, None hplot = lambda x, y: io.hplot(x, os.environ['WORK'] + "/" + y, ticks=5, tick_unit='arcmin', grid=True, colorbar=True, color='gray', upgrade=4, quantile=1e-3) print("Starting deep56") rank, ystack1, cstack1, dstack1, i1, cents, y1ds1, c1ds1, d1ds1, ry1d1, rc1d1, rd1d1 = do( ymap1, cmap1, dmap1, mask1, ras1, decs1, wt1) if rank == 0: print(i1) hplot(ystack1, "fig_all_cmass_ystack_%s_%s" % (cversion, 'deep56')) hplot(cstack1, "fig_all_cmass_cstack_%s_%s" % (cversion, 'deep56')) hplot(dstack1, "fig_all_cmass_dstack_%s_%s" % (cversion, 'deep56')) print("Starting boss")
random = True cversion = 'joint' region = 'deep56' fname = os.environ['WORK'] + "/data/boss/eboss_dr14/data_DR14_QSO_S.fits" cols = catalogs.load_fits(fname, ['RA', 'DEC']) ras = cols['RA'] decs = cols['DEC'] sns = np.array(ras) * 0 + 6 tdir = '/scratch/r/rbond/msyriac/data/depot/tilec/v1.0.0_rc_20190919' mask = sints.get_act_mr3_crosslinked_mask(region) bmask = mask.copy() bmask[bmask < 0.99] = 0 io.hplot(enmap.downgrade(bmask, 4), "fig_qso_bmask") solution = 'tsz' bfile = tutils.get_generic_fname(tdir, region, 'cmb', None, 'act', beam=True) yfile = tutils.get_generic_fname(tdir, region, 'cmb', None, 'act') bfile2 = tutils.get_generic_fname(tdir, region, 'cmb', None, 'planck', beam=True) yfile2 = tutils.get_generic_fname(tdir, region, 'cmb', None, 'planck') cmap = enmap.read_map(yfile2)
box = np.deg2rad([[-1, -1], [10, 10]]) #shape,wcs = enmap.fullsky_geometry(res=np.deg2rad(res/60.)) # shape,wcs = enmap.geometry(pos=box,res=np.deg2rad(res/60.)) hmap = hp.read_map(hfile) ofunc = lambda shape, wcs: reproject.enmap_from_healpix_interp( hmap, shape, wcs, rot=None, interpolate=False) cmap = populate(shape, wcs, ofunc, maxpixy=2000, maxpixx=2000) #enmap.downgrade(populate(shape,wcs,ofunc),2) # enmap.write_map("cmap.fits",cmap) # io.plot_img(cmap,"fmap.png") cmap = cmap.submap(box) io.hplot(cmap, "cmap", grid=False) sys.exit() pcls = hp.alm2cl(curvedsky.map2alm(cmap, lmax=6000)) hcls = hp.anafast(hmap, lmax=6000) pells = range(len(pcls)) hells = range(len(hcls)) pl = io.Plotter() pl.add(pells, (pcls - hcls) / pcls, label='car') #pl.add(pells,pcls*pells,label='car') #pl.add(hells,hcls*hells,label='healpix') pl._ax.set_xlim(200, 4000) pl._ax.set_ylim(-0.2, 0.1) pl.done("cls.png")
try: splits = dm.get_splits(season=season, patch=apatch, arrays=[array], ncomp=3, srcfree=False)[0, :, :, ...] cmap = dm.get_coadd(season=season, patch=apatch, array=array, ncomp=3, srcfree=False) except: continue io.hplot(splits, os.environ['WORK'] + "/new_mr3f/splits_%s" % fname, min=-300, max=600, grid=True) # ivars = dm.get_splits_ivar(season=season,patch=apatch,arrays=[array],ncomp=None)[0,:,0,...] # cmap,_ = noise.get_coadd(splits,ivars,axis=0) rmap = maps.filter_map(cmap * mask, mfilter) io.hplot(rmap, os.environ['WORK'] + "/new_mr3f/coadd_filtered_%s" % fname, grid=True) rmap = maps.filter_map(splits * mask, mfilter) io.hplot(rmap, os.environ['WORK'] + "/new_mr3f/splits_filtered_%s" % fname, grid=True)
dtype=dm.dtype) ndown, nfitted, nparams = covtools.noise_average(npower[0, 0], dfact=(16, 16), lmin=300, lmax=8000, wnoise_annulus=500, bin_annulus=20, lknee_guess=3000, alpha_guess=-4, method="fft", radial_fit=True) #io.plot_img(np.fft.fftshift(np.log10(ndown)),"ndown.png",aspect='auto',lim=[-6,3]) #io.hplot(np.fft.fftshift(np.log10(ndown)),"hndown") io.hplot(np.fft.fftshift((ndown)), "hndown") io.plot_img(np.fft.fftshift(ndown / nfitted), "nunred.png", aspect='auto') nmod = ndown / nfitted enmap.write_map("anisotropy_template.fits", enmap.samewcs(nmod, npower)) shape, wcs = maps.rect_geometry(width_deg=50., height_deg=30, px_res_arcmin=0.5) rms = 10.0 lknee = 3000 alpha = -3 n2d = covtools.get_anisotropic_noise(shape, wcs, rms, lknee, alpha) modlmap = enmap.modlmap(shape, wcs) bin_edges = np.arange(100, 8000, 100) binner = stats.bin2D(modlmap, bin_edges)
arrays.s16_01.rms = 40. arrays.s16_02.freq = 148 arrays.s16_02.fwhm = 1.4 arrays.s16_02.rms = 60. arrays.s16_03.freq = 93 arrays.s16_03.fwhm = 1.4 * (148. / 93.) arrays.s16_03.rms = 60. np.random.seed((1, seed)) ras, decs = catalogs.random_catalog(shape, wcs, Nclusters, edge_avoid_deg=0.) for qind, qid in enumerate(arrays.keys()): fwhm = arrays[qid].fwhm freq = arrays[qid].freq rms = arrays[qid].rms amps = get_amps(freq) srcs = np.stack((decs * putils.degree, ras * putils.degree, amps)).T szmap = sim_srcs(shape, wcs, srcs, beam=fwhm * putils.arcmin) kbeam = maps.gauss_beam(modlmap, fwhm) signal = maps.filter_map(cmb, kbeam) + szmap # io.hplot(signal,os.environ['WORK'] + '/tiling/signal_%s' % qid) for i in range(nsplits): noise = maps.white_noise(shape, wcs, rms, seed=(2, qind, seed, i)) omap = signal + noise fname = os.environ['WORK'] + '/sim_tiling/%s_split_%d.fits' % (qid, i) enmap.write_map(fname, omap) io.hplot(omap, os.environ['WORK'] + '/tiling/total_%s_%d' % (qid, i))
# If debugging, get unfiltered maps and plot Cls if task==0 and debug_cmb: t_alm,e_alm,b_alm = solint.get_kmap(channel,seed,lmin,lmax,filtered=False) tcl = hp.alm2cl(t_alm) ls = np.arange(tcl.size) pl = io.Plotter('Cell') pl.add(ls,tcl/w2) ls2,nells,nells_P = solint.get_noise_power(channel,beam_deconv=True) theory = cosmology.default_theory() pl.add(ls,theory.lCl('TT',ls) + maps.interp(ls2,nells)(ls),color='k') pl._ax.set_xlim(1,6000) pl._ax.set_ylim(1e-6,1e3) pl.done(f'{solenspipe.opath}/tcl.png') imap = enmap.downgrade(solint.alm2map(np.asarray([t_alm,e_alm,b_alm]),ncomp=3) * maps.binary_mask(mask),2) for i in range(3): io.hplot(imap[i],f'{solenspipe.opath}/imap_{i}',mask=0) with bench.show("sim"): # Get simulated, prepared filtered T, E, B maps, i.e. (1/(C+N) * teb_alm) t_alm,e_alm,b_alm = solint.get_kmap(channel,seed,lmin,lmax,filtered=True) # Get the reconstructed kappa map alms and filter it with the normalization recon_alms = qe.filter_alms(solint.get_mv_kappa(polcomb,t_alm,e_alm,b_alm),maps.interp(Als['L'],Als[polcomb])) # Subtract a meanfield if necessary recon_alms = recon_alms - mf_alm if task==0 and debug_cmb: rmap = solint.alm2map(recon_alms,ncomp=1)[0] * maps.binary_mask(mask) io.hplot(rmap,f'{solenspipe.opath}/rmap',mask=0,color='gray') falms = recon_alms.copy()
mask = sints.get_act_mr3_crosslinked_mask( mpatch, version=in_versions[survey], kind='binary_apod', season="s16" if survey == 'advact' else None, array=None, pad=pad) print(survey, patch) # FFT friendliness Ny, Nx = mask.shape[-2:] dNy = fft.fft_len(Ny, "above") dNx = fft.fft_len(Nx, "above") pny = dNy - Ny pnx = dNx - Nx pady1 = pny // 2 pady2 = pny - pady1 padx1 = pnx // 2 padx2 = pnx - padx1 mask = enmap.pad(mask, ((pady1, padx1), (pady2, padx2))) assert mask.shape[-2] == dNy assert mask.shape[-1] == dNx enmap.write_map(out_path + "%s.fits" % patch, mask) io.hplot(enmap.downgrade(mask, 8), out_path + "%s" % patch) sN = get_smooth_N(patch) smoothed = mask_smoothing(mask, sN) enmap.write_map(out_path + "%s_smoothed.fits" % patch, smoothed) io.hplot(enmap.downgrade(smoothed, 8), out_path + "%s_smoothed" % patch)