def test_pospix(self): # Posmap separable and non-separable on CAR for res in [6,12,24]: shape,wcs = enmap.fullsky_geometry(res=np.deg2rad(res/60.),proj='car') posmap1 = enmap.posmap(shape,wcs) posmap2 = enmap.posmap(shape,wcs,separable=True) assert np.all(np.isclose(posmap1,posmap2)) # Pixmap plain pres = 0.5 shape,wcs = enmap.geometry(pos=(0,0),shape=(30,30),res=pres*u.degree,proj='plain') yp,xp = enmap.pixshapemap(shape,wcs) assert np.all(np.isclose(yp,pres*u.degree)) assert np.all(np.isclose(xp,pres*u.degree)) yp,xp = enmap.pixshape(shape,wcs) parea = enmap.pixsize(shape,wcs) assert np.isclose(parea,(pres*u.degree)**2) assert np.isclose(yp,pres*u.degree) assert np.isclose(xp,pres*u.degree) pmap = enmap.pixsizemap(shape,wcs) assert np.all(np.isclose(pmap,(pres*u.degree)**2)) # Pixmap CAR pres = 0.1 dec_cut = 89.5 # pixsizemap is not accurate near the poles currently shape,wcs = enmap.band_geometry(dec_cut=dec_cut*u.degree,res=pres*u.degree,proj='car') # Current slow and general but inaccurate near the poles implementation pmap = enmap.pixsizemap(shape,wcs) # Fast CAR-specific pixsizemap implementation dra, ddec = wcs.wcs.cdelt*u.degree dec = enmap.posmap([shape[-2],1],wcs)[0,:,0] area = np.abs(dra*(np.sin(np.minimum(np.pi/2.,dec+ddec/2))-np.sin(np.maximum(-np.pi/2.,dec-ddec/2)))) Nx = shape[-1] pmap2 = enmap.ndmap(area[...,None].repeat(Nx,axis=-1),wcs) assert np.all(np.isclose(pmap,pmap2))
config = io.config_from_yaml( os.path.dirname(os.path.abspath(__file__)) + "/../input/config.yml") opath = config['data_path'] mask = hp.read_map(opath + config['mask_name']) io.mollview(mask, 'hp_carmask.png') print(mask.max(), mask.min()) nside = hp.nside2npix(mask.size) lmax = 3000 # CAR resolution is decided based on lmax res = np.deg2rad(2.0 * (3000 / lmax) / 60.) # Make the full sky geometry shape, wcs = enmap.band_geometry(np.deg2rad((-70, 30)), res=res) #shape,wcs = enmap.fullsky_geometry(res=res) # nside = 256 # nmask = north_galactic_mask(shape,wcs,nside) # io.plot_img(nmask,'low_north_gal.png') # nside = 256 # smask = south_galactic_mask(shape,wcs,nside) # io.plot_img(smask,'low_south_gal.png') #sys.exit() imap = reproject.ivar_hp_to_cyl(mask, shape, wcs,
def test_thumbnails(self): print("Testing thumbnails...") # Make a geometry far away from the equator dec_min = 70 * u.degree dec_max = 80 * u.degree res = 0.5 * u.arcmin shape, wcs = enmap.band_geometry((dec_min, dec_max), res=res) # Create a set of point source positions separated by # 2 degrees but with 1 column wrapping around the RA # direction width = 120 * u.arcmin Ny = int((dec_max - dec_min) / (width)) Nx = int((2 * np.pi / (width))) pys = np.linspace(0, shape[0], Ny)[1:-1] pxs = np.linspace(0, shape[1], Nx)[:-1] Ny = len(pys) Nx = len(pxs) xx, yy = np.meshgrid(pxs, pys) xx = xx.reshape(-1) yy = yy.reshape(-1) ps = np.vstack((yy, xx)) decs, ras = enmap.pix2sky(shape, wcs, ps) # Simulate these sources with unit peak value and 2.5 arcmin FWHM N = ps.shape[1] srcs = np.zeros((N, 3)) srcs[:, 0] = decs srcs[:, 1] = ras srcs[:, 2] = ras * 0 + 1 sigma = 2.5 * u.fwhm * u.arcmin omap = pointsrcs.sim_srcs(shape, wcs, srcs, beam=sigma) # Reproject thumbnails centered on the sources # with gnomonic/tangent projection proj = "tan" r = 10 * u.arcmin ret = reproject.thumbnails(omap, srcs[:, :2], r=r, res=res, proj=proj, apod=2 * u.arcmin, order=3, oversample=2, pixwin=False) # Create a reference source at the equator to compare this against ishape, iwcs = enmap.geometry(shape=ret.shape, res=res, pos=(0, 0), proj=proj) imodrmap = enmap.modrmap(ishape, iwcs) model = np.exp(-imodrmap**2. / 2. / sigma**2.) # Make sure all thumbnails agree with the reference at the # sub-percent level for i in range(ret.shape[0]): diff = ret[i] - model assert np.all(np.isclose(diff, 0, atol=1e-3))
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')
def get_geometry(res_arcmin, bounds_deg): return enmap.band_geometry(np.deg2rad(bounds_deg), res=np.deg2rad(res_arcmin / 60.0), proj="car")