def alm2map_raw(alm, map, ainfo, minfo, spin=2, deriv=False, copy=False): """Direct wrapper of libsharp's alm2map. Requires ainfo and minfo to already be set up, and that the map and alm must be fully compatible with these.""" if copy: map = map.copy() alm_full = utils.to_Nd(alm, 2 if deriv else 3) map_full = utils.to_Nd(map, 4) map_flat = map_full.reshape(map_full.shape[:-2] + (-1, )) sht = sharp.sht(minfo, ainfo) # Perform the SHT if deriv: # We need alm_full[ntrans,nalm] -> map_flat[ntrans,2,npix] # or alm_full[nalm] -> map_flat[2,npix] map_flat[:] = sht.alm2map_der1(alm_full, map_flat) # sharp's theta is a zenith angle, but we want a declination. # Actually, we may need to take into account left-handed # coordinates too, though I'm not sure how to detect those in # general. map_flat[:, 0] = -map_flat[:, 0] else: map_flat[:, :1, :] = sht.alm2map(alm_full[:, :1, :], map_flat[:, :1, :]) if map_flat.shape[1] > 1: map_flat[:, 1:, :] = sht.alm2map(alm_full[:, 1:, :], map_flat[:, 1:, :], spin=spin) return map
def map2alm_raw(map, alm, minfo, ainfo, spin=2, copy=False): """Direct wrapper of libsharp's map2alm. Requires ainfo and minfo to already be set up, and that the map and alm must be fully compatible with these.""" if not (map.dtype == np.float32 or map.dtype == np.float64): raise TypeError("Only float32 or float64 dtype supported for shts") if copy: alm = alm.copy() alm_full = utils.to_Nd(alm, 3) map_full = utils.to_Nd(map, 4) map_flat = map_full.reshape(map_full.shape[:-2]+(-1,)) sht = sharp.sht(minfo, ainfo) alm_full[:,:1,:] = sht.map2alm(map_flat[:,:1,:],alm_full[:,:1,:]) if map_flat.shape[1] > 1: alm_full[:,1:,:] = sht.map2alm(map_flat[:,1:,:], alm_full[:,1:,:], spin=spin) return alm
def map2alm_raw(map, alm, minfo, ainfo, spin=2, copy=False): """Direct wrapper of libsharp's map2alm. Requires ainfo and minfo to already be set up, and that the map and alm must be fully compatible with these.""" if copy: alm = alm.copy() alm_full = utils.to_Nd(alm, 3) map_full = utils.to_Nd(map, 4) map_flat = map_full.reshape(map_full.shape[:-2] + (-1, )) sht = sharp.sht(minfo, ainfo) alm_full[:, :1, :] = sht.map2alm(map_flat[:, :1, :], alm_full[:, :1, :]) if map_flat.shape[1] > 1: alm_full[:, 1:, :] = sht.map2alm(map_flat[:, 1:, :], alm_full[:, 1:, :], spin=spin) return alm
with dprint("construct imap"): ires = np.array([1,1./np.sin(R)])*res/args.supersample shape, wi = enmap.geometry(pos=[[np.pi/2-R,-np.pi],[np.pi/2,np.pi]], res=ires, proj="car") imap = enmap.zeros((ncomp,)+shape, wi) # Define SHT for interpolation pixels with dprint("construct sht"): minfo = curvedsky.map2minfo(imap) lmax_ideal = np.pi/res ps = ps[:,:,:lmax_ideal] lmax = ps.shape[-1] # We do not need all ms when centered on the pole. To reach 1e-10 relative # error up to R, we need mmax approx 9560*R in radians mmax = args.mmax or int(R*9560) ainfo = sharp.alm_info(lmax, mmax) sht = sharp.sht(minfo, ainfo) with dprint("curvedsky tot"): with dprint("rand alm"): alm = curvedsky.rand_alm(ps, ainfo=ainfo, seed=1, m_major=False) with dprint("alm2map"): sht.alm2map(alm[:1], imap[:1].reshape(1,-1)) if ncomp == 3: sht.alm2map(alm[1:3], imap[1:3,:].reshape(2,-1), spin=2) del alm # Make a test map to see if we can project between these with dprint("project"): omap = enmap.project(imap, omap.shape, omap.wcs, mode="constant", cval=np.nan) del imap enmap.write_map(args.omap, omap)
[np.pi / 2, np.pi]], res=ires, proj="car") imap = enmap.zeros((ncomp, ) + shape, wi) # Define SHT for interpolation pixels with dprint("construct sht"): minfo = curvedsky.map2minfo(imap) lmax_ideal = np.pi / res ps = ps[:, :, :lmax_ideal] lmax = ps.shape[-1] # We do not need all ms when centered on the pole. To reach 1e-10 relative # error up to R, we need mmax approx 9560*R in radians mmax = args.mmax or int(R * 9560) ainfo = sharp.alm_info(lmax, mmax) sht = sharp.sht(minfo, ainfo) with dprint("curvedsky tot"): with dprint("rand alm"): alm = curvedsky.rand_alm(ps, ainfo=ainfo, seed=1, m_major=False) with dprint("alm2map"): sht.alm2map(alm[:1], imap[:1].reshape(1, -1)) if ncomp == 3: sht.alm2map(alm[1:3], imap[1:3, :].reshape(2, -1), spin=2) del alm # Make a test map to see if we can project between these with dprint("project"): omap = enmap.project(imap, omap.shape, omap.wcs, mode="constant",