def __init__(self, shape, wcs): pos = enmap.posmap(shape, wcs) self.y = pos[0, :, :] self.x = pos[1, :, :] self.modrmap = enmap.modrmap(shape, wcs) self.shape = shape self.wcs = wcs
def get_geometry_shapes(shape, wcs, hole_arcminutes): modrmap = enmap.modrmap(shape, wcs) m1 = np.where( modrmap.reshape(-1) < hole_arcminutes * np.pi / 180. / 60.)[0] m2 = np.where( modrmap.reshape(-1) >= hole_arcminutes * np.pi / 180. / 60.)[0] return m1.size, m2.size
def mask_map(imap, iys, ixs, hole_arc, hole_frac=0.6): shape, wcs = imap.shape, imap.wcs Ny, Nx = shape[-2:] px = maps.resolution(shape, wcs) * 60. * 180. / np.pi hole_n = int(round(hole_arc / px)) hole_ny = hole_nx = hole_n oshape, owcs = enmap.geometry(pos=(0., 0.), shape=(2 * hole_n, 2 * hole_n), res=px * np.pi / 180. / 60.) modrmap = enmap.modrmap(oshape, owcs) mask = enmap.ones(shape, wcs) for iy, ix in zip(iys, ixs): if iy <= hole_n or ix <= hole_n or iy >= (Ny - hole_n) or ix >= ( Nx - hole_n): continue vslice = imap[np.int(iy - hole_ny):np.int(iy + hole_ny), np.int(ix - hole_nx):np.int(ix + hole_nx)] vslice[modrmap < (hole_frac * hole_arc) * np.pi / 180. / 60.] = np.nan # !!!! could cause a bias mask[np.int(iy - hole_ny):np.int(iy + hole_ny), np.int(ix - hole_nx):np.int(ix + hole_nx)][modrmap < hole_arc * np.pi / 180. / 60.] = 0 return mask
def get_geometry_regions(ncomp, n, res, hole_radius): tshape, twcs = enmap.geometry(pos=(0, 0), shape=(n, n), res=res, proj='car') modrmap = enmap.modrmap(tshape, twcs) # Select the hole (m1) and context(m2) across all components amodrmap = np.repeat(modrmap.reshape((1, n, n)), ncomp, 0) m1 = np.where(amodrmap.reshape(-1) < hole_radius)[0] m2 = np.where(amodrmap.reshape(-1) >= hole_radius)[0] return m1, m2
def __init__(self, shape, wcs, dimensionless=False, TCMB=2.7255e6, cc=None, theory=None, lmax=None, skip_real=False, orphics_is_dimensionless=True): self.shape = shape self.wcs = wcs if not (skip_real): self.modrmap = enmap.modrmap(shape, wcs) self.lxmap, self.lymap, self.modlmap, self.angmap, self.lx, self.ly = get_ft_attributes_enmap( shape, wcs) self.pix_ells = np.arange(0., self.modlmap.max(), 1.) self.posmap = enmap.posmap(self.shape, self.wcs) self.dimensionless = dimensionless self.TCMB = TCMB if (theory is not None) or (cc is not None): self.add_theory(cc, theory, lmax, orphics_is_dimensionless)
from __future__ import print_function from orphics import maps,io,cosmology,stats from enlib import enmap import numpy as np import os,sys from scipy import signal cc = cosmology.Cosmology(lmax=6000,pickling=True) deg = 15. shape,wcs = maps.rect_geometry(width_deg=deg,px_res_arcmin=1.0) modlmap = enmap.modlmap(shape,wcs) modrmap = enmap.modrmap(shape,wcs) lmax = modlmap.max() ells = np.arange(0,lmax,1) ps = cc.theory.lCl('TT',ells).reshape((1,1,ells.size)) mgen = maps.MapGen(shape,wcs,ps) fwhm = 5. kbeam = maps.gauss_beam(modlmap,fwhm) imap = mgen.get_map() bmap2 = maps.convolve_gaussian(imap.copy(),fwhm=fwhm,nsigma=5.0) print(bmap2.shape) bmap = maps.filter_map(imap.copy(),kbeam)
noise_T_uK_arcmin = 0.01 noise_P_uK_arcmin = 0.01 # beam_arcmin = 0. # noise_T_uK_arcmin = 0. # noise_P_uK_arcmin = 0. pol_list = ['TT', 'EB'] #,'EE','ET','TE','TB'] pol = False if pol_list == ['TT'] else True shape_sim, wcs_sim = enmap.get_enmap_patch(patch_width_arcmin, sim_pixel_scale, proj="car", pol=pol) modr_sim = enmap.modrmap(shape_sim, wcs_sim) * 180. * 60. / np.pi # === COSMOLOGY === cc = ClusterCosmology(lmax=lmax, pickling=True) #,fill_zero=False) TCMB = 2.7255e6 theory = cc.theory # === EXPERIMENT === lxmap_sim, lymap_sim, modlmap_sim, angmap_sim, lx_sim, ly_sim = fmaps.get_ft_attributes_enmap( shape_sim, wcs_sim) pix_ells = np.arange(0, modlmap_sim.max(), 1) ntfunc = lambda x: modlmap_dat * 0. + (np.pi / (180. * 60) )**2. * noise_T_uK_arcmin**2. / TCMB**2. npfunc = lambda x: modlmap_dat * 0. + (np.pi / (180. * 60) )**2. * noise_P_uK_arcmin**2. / TCMB**2.
# Paths PathConfig = io.load_path_config() GridName = PathConfig.get("paths","output_data")+args.GridName with open(GridName+"/attribs.json",'r') as f: attribs = json.loads(f.read()) barc = attribs['arc'] ; bpix = attribs['pix'] ; bbeam = attribs['beam'] pout_dir = PathConfig.get("paths","plots")+args.GridName+"/joint_bayesian_hdv_plots_"+io.join_nums((barc,bpix,bbeam,args.noise))+"_" io.mkdir(pout_dir,comm) # Tiny Geometry bshape, bwcs = maps.rect_geometry(width_arcmin=barc,px_res_arcmin=bpix,pol=False) bmodlmap = enmap.modlmap(bshape,bwcs) bmodrmap = enmap.modrmap(bshape,bwcs) # Noise model noise_uK_rad = args.noise*np.pi/180./60. normfact = np.sqrt(np.prod(enmap.pixsize(bshape,bwcs))) noise_uK_pixel = noise_uK_rad/normfact Ncov = np.diag([(noise_uK_pixel)**2.]*np.prod(bshape)) kbeam = maps.gauss_beam(bbeam,bmodlmap)
from orphics import maps,io,cosmology,catalogs from enlib import enmap,bench import numpy as np shape,wcs = maps.rect_geometry(width_deg=20.,px_res_arcmin=0.5) bigmap = enmap.zeros(shape,wcs) Nobj = 1000 ras,decs = catalogs.random_catalog(shape,wcs,Nobj,edge_avoid_deg=1.) arcmin_width = 30. res = np.min(bigmap.extent()/bigmap.shape[-2:])*180./np.pi*60. Npix = int(arcmin_width/res)*1. if Npix%2==0: Npix += 1 cshape,cwcs = enmap.geometry(pos=(0.,0.),res=res/(180./np.pi*60.),shape=(Npix,Npix)) cmodrmap = enmap.modrmap(cshape,cwcs) sigmas = [] for ra,dec in zip(ras,decs): iy,ix = enmap.sky2pix(shape,wcs,(dec*np.pi/180.,ra*np.pi/180.)) sigma = np.random.normal(3.0,1.0)*np.pi/180./60. paste_in = np.exp(-cmodrmap**2./2./sigma**2.) bigmap[int(iy-Npix/2):int(iy+Npix/2),int(ix-Npix/2):int(ix+Npix/2)] += paste_in sigmas.append(sigma) io.plot_img(bigmap,"cat.png",high_res=True) print("done")
lens_func = lambda x: lensing.nfw_kappa(mass, x, cc, zL=0.7, concentration=3.2, overdensity=200., critical=True, atClusterZ=True) #sigma = 1.0 * np.pi/180./60. #lens_func = lambda x: 0.2 * np.exp(-x**2./sigma**2./2.) rshape, rwcs = maps.rect_geometry(width_arcmin=5., px_res_arcmin=0.001) fshape, fwcs = maps.rect_geometry(width_arcmin=20., px_res_arcmin=0.1) cshape, cwcs = maps.rect_geometry(width_arcmin=20., px_res_arcmin=0.5) rmodrmap = enmap.modrmap(rshape, rwcs) fmodrmap = enmap.modrmap(fshape, fwcs) cmodrmap = enmap.modrmap(cshape, cwcs) rmodlmap = enmap.modlmap(rshape, rwcs) fmodlmap = enmap.modlmap(fshape, fwcs) cmodlmap = enmap.modlmap(cshape, cwcs) print(fshape, cshape) mass = 2.e14 fkappa = lens_func(fmodrmap) phi, _ = lensing.kappa_to_phi(fkappa, fmodlmap, return_fphi=True) grad_phi = enmap.grad(phi) pos = enmap.posmap(fshape, fwcs) + grad_phi alpha_pix = enmap.sky2pix(fshape, fwcs, pos, safe=False) lmax = cmodlmap.max()
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) bshape, bwcs = maps.rect_geometry(width_arcmin=args.arc * args.buffer_factor, px_res_arcmin=args.pix, pol=False) bmodlmap = enmap.modlmap(bshape, bwcs) bmodrmap = enmap.modrmap(bshape, bwcs) #gshape, gwcs = maps.rect_geometry(width_arcmin=args.arc,px_res_arcmin=0.1953125,pol=False) gshape, gwcs = maps.rect_geometry(width_arcmin=100., px_res_arcmin=args.pix, pol=False) gshape, gwcs = bshape, bwcs gmodlmap = enmap.modlmap(gshape, gwcs) gmodrmap = enmap.modrmap(gshape, gwcs) print(shape, bshape)
# === COSMOLOGY === cc = ClusterCosmology(lmax=lmax, pickling=True) TCMB = 2.7255e6 theory = cc.theory ps = cmb.enmap_power_from_orphics_theory(theory, lmax, lensed=False) patch_width_arcmin = 40. sim_pixel_scale = 0.1 pol = False shape_sim, wcs_sim = enmap.get_enmap_patch(patch_width_arcmin, sim_pixel_scale, proj="car", pol=pol) modr_sim = enmap.modrmap(shape_sim, wcs_sim) * 180. * 60. / np.pi lxmap_sim, lymap_sim, modlmap_sim, angmap_sim, lx_sim, ly_sim = fmaps.get_ft_attributes_enmap( shape_sim, wcs_sim) pix_ells = np.arange(0, modlmap_sim.max(), 1) # === EXPERIMENT === ntfunc = cmb.get_noise_func(beam_arcmin, noise_T_uK_arcmin, ellmin=tellmin, ellmax=tellmax, TCMB=2.7255e6) npfunc = cmb.get_noise_func(beam_arcmin, noise_P_uK_arcmin, ellmin=pellmin, ellmax=pellmax,
attribs = json.loads(f.read()) barc = attribs['arc'] bpix = attribs['pix'] bbeam = attribs['beam'] pout_dir = PathConfig.get( "paths", "plots") + args.GridName + "/joint_bayesian_hdv_plots_" + io.join_nums( (barc, bpix, args.beam, args.noise)) + "_" io.mkdir(pout_dir, comm) # Tiny Geometry bshape, bwcs = maps.rect_geometry(width_arcmin=barc, px_res_arcmin=bpix, pol=False) bmodlmap = enmap.modlmap(bshape, bwcs) bmodrmap = enmap.modrmap(bshape, bwcs) # Big 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) oshape, owcs = enmap.scale_geometry(shape, wcs, args.pix / bpix) omodlmap = enmap.modlmap(oshape, owcs) omodrmap = enmap.modrmap(oshape, owcs) if rank == 0: print(bshape, bwcs) print(shape, wcs) print(oshape, owcs)
def make_circular_geometry(shape, wcs, context_arcmin, hole_arcmin, power2d, buffer_factor=2, verbose=False): '''Makes the circular geometry matrices that need to be pre-calculated for later inpainting. Arguments --------- input2DPower - ndarray containing 2D power spectrum of a map. It need not already have been downsampled to the shape of the stamp cutout inputLy inputLx - the fourier wavenumbers corresponding to the y and x axes of the stamp cutout stampArc - the width in arcminutes of the stamp cut out stampPxX - the pixel width in arcminutes of the stamp cut out in the x direction stampPxY - the pixel width in arcminutes of the stamp cut out in the y direction holeArc - the radius of the circular hole in arcminutes bufferFactor - the pixel covariance matrix will be calculated on a periodic stamp larger by this factor verbose - True if you want more commentary Returns ------- meanMul - a matrix that has shape (nh,nc) where nh is the number of pixels in the hole and nc is the number of pixels outside (in the "context"). It should be multiplied by a vector (nc) containing pixels outside to get a vector (nh) for the mean value of the pixels inside covRoot - a (nh,nh) sqrt(covariance matrix) that can be used to generate a random realization in the hole. This can be generated by multiplying the sqrt of cov by a vector (nh) of standard normal variables. The generated vector should be added to the mean value obtained using meanMul pcov - the pixel-pixel covariance matrix used in intermediate steps, if you want to re-use it targetTemplate - a liteMap template of the stamp cutout m1 - a boolean array that can be used to select the hole region m2 - a boolean array that can be used to select the context region ''' arc = context_arcmin res = maps.resolution(shape, wcs) * 60. * 180. / np.pi bshape, bwcs = maps.rect_geometry(width_arcmin=arc * buffer_factor, px_res_arcmin=res) tshape, twcs = maps.rect_geometry(width_arcmin=arc, px_res_arcmin=res) sny, snx = tshape bmodlmap = enmap.modlmap(bshape, bwcs) modlmap = enmap.modlmap(shape, wcs) if verbose: print("Downsampling...") Niy, Nix = shape[-2:] Noy, Nox = bshape[-2:] # print(bshape,tshape,power2d.shape) # io.plot_img(np.fft.fftshift(np.log10(power2d))) #out_power = resample.resample_fft(power2d,bshape[-2:],axes=[-2,-1]) #out_power = np.fft.ifftshift(resample.resample_fft(np.fft.fftshift(power2d),bshape[-2:],axes=[-2,-1])) out_power = resample.resample_bin( power2d, factors=[float(Noy) / Niy, float(Nox) / Nix], axes=[-2, -1]) # io.plot_img(np.fft.fftshift(np.log10(out_power))) # print(out_power.shape) if verbose: print("Starting slow part...") d = maps.diagonal_cov(out_power) with bench.show("pixcov"): pcov = maps.pixcov(bshape, bwcs, d)[0, 0, :sny, :snx, :sny, :snx] modrmap = enmap.modrmap(tshape, twcs) m1 = np.where(modrmap.reshape(-1) < hole_arcmin * np.pi / 180. / 60.)[0] m2 = np.where(modrmap.reshape(-1) >= hole_arcmin * np.pi / 180. / 60.)[0] with bench.show("geom"): meanMul, cov = get_geometry(pcov.reshape(sny * snx, sny * snx), m1, m2) covRoot = stats.eig_pow(cov, 0.5) return meanMul, covRoot, pcov, tshape, twcs, m1, m2