Exemple #1
0
 def set_properties(self, lmin, lmax, format):
     self.lmin = lmin
     self.lmax = lmax
     self.format = format
     if format not in (COMPLEX_FULL, COMPLEX_BRIEF, REAL_FULL):
         raise ValueError()
     num_coefs = lm_count_brief(lmin, lmax) if format.is_brief else lm_count_full(lmin, lmax)
     if num_coefs != self.shape[0]:
         raise ValueError("Wrong number of coefficients for lmin/lmax given")
Exemple #2
0
    def to_complex(self):
        """
        ::
        
            >>> R = harmonic_sphere_map([[12], [-1, 1, 3], [-1, -2, 3, 4, 5]]); R
            Real harmonic sphere map with l=0..2 (9 coefficients)
            >>> C = R.to_complex(); C
            Brief complex harmonic sphere map with l=0..2 (6 coefficients)
            >>> x = C.to_array(); x[[0, 1, 3]] /= np.sqrt(2); x *= np.sqrt(2); x
            array([ 12.+0.j,   1.+0.j,   3.-1.j,   3.+0.j,   4.-2.j,   5.-1.j])

        Many maps::

            >>> M = R
            >>> M = np.hstack((M[:,None], M[:,None], M[:,None], M[:,None]))
            >>> M = np.dstack((M, M))
            >>> M = harmonic_sphere_map(M, 0, 2, is_complex=False); M
            (4, 2)-stack of real harmonic sphere maps with l=0..2 (9 coefficients)
            >>> M.to_complex()
            (4, 2)-stack of brief complex harmonic sphere maps with l=0..2 (6 coefficients)
        
        """
        self._check_not_pretending()
        if self.format is COMPLEX_BRIEF:
            return self
        elif self.format is COMPLEX_FULL:
            raise ValueError('Cannot convert full complex format to brief')
        elif self.format is REAL_FULL:
            size = self.shape[1:]
            Nlm = lm_count_brief(self.lmin, self.lmax)
            out = np.empty((Nlm,) + size, complex_dtype, order='F')
            for mapidx in np.ndindex(*size):
                idx = (slice(None),) + mapidx
                mapdatautils.alm_real2complex(self.lmin, self.lmax, self[idx], out[idx])
            return _HarmonicSphereMap(out, self.lmin, self.lmax, COMPLEX_BRIEF)
        else:
            raise AssertionError()