def to_pixel(self, Nside=None, Npix=None, dtype=None, out=None): """ :: >>> insh = harmonic_sphere_map(0, 0, 4) >>> insh.to_pixel(8) Pixel sphere map (ring-ordered, Nside=8, Npix=768) Convert a uniform map:: >>> shmap = harmonic_sphere_map([[23], [0, 0], [0, 0, 0]]) >>> pixmap = shmap.to_pixel(8); pixmap Pixel sphere map (ring-ordered, Nside=8, Npix=768) >>> np.allclose(pixmap, 23.0 / np.sqrt(4*np.pi)) True One can convert multiple maps at once:: >>> M = shmap >>> M = np.hstack((M[:,None], M[:,None], M[:,None], M[:,None])) >>> M = np.dstack((M, M)) >>> M = harmonic_sphere_map(M, 0, 2); M (4, 2)-stack of brief complex harmonic sphere maps with l=0..2 (6 coefficients) >>> x = M.to_pixel(4); x (4, 2)-stack of pixel sphere maps (ring-ordered, Nside=4, Npix=192) >>> np.allclose(x, 23.0 / np.sqrt(4*np.pi)) True """ self._check_not_pretending() if self.format is not COMPLEX_BRIEF: return self.to_complex().to_pixel(Nside, Npix, dtype, out) if Nside is None: if Npix is None: raise ValueError("Provide Nside or Npix") Nside = npix2nside(Npix) if Npix is None: Npix = nside2npix(Nside) if dtype is None: dtype = self.dtype dtype = to_real_dtype(dtype) # for now, only double... assert dtype == np.float64 size = self.shape[1:] if out is None: out = np.empty((Npix,) + size, dtype, order='F') # Todo: Optimize -- have lmin in complexpacked2complexmatrix if self.lmin == 0: source = self else: source = np.empty((l_to_lm(self.lmax + 1),) + size, complex_dtype, order='F') source[:l_to_lm(self.lmin)] = 0 source[l_to_lm(self.lmin):] = self for mapidx in np.ndindex(*size): idx = (slice(None),) + mapidx alm_matrix = mapdatautils.alm_complexpacked2complexmatrix(source[idx]) mapdatautils.alm2map(Nside, alm_matrix, out=out[idx]) return _PixelSphereMap(out, pixel_order='ring')
def get_Nside(self): self._check_not_pretending() return npix2nside(self.shape[0])
def set_properties(self, pixel_order): if pixel_order not in ('ring', 'nested'): raise ValueError('invalid pixel order') self.pixel_order = pixel_order if nside2npix(npix2nside(self.shape[0])) != self.shape[0]: raise ValueError('invalid shape (must be valid Npix)')