Ejemplo n.º 1
0
    def to_real(self):
        """
        >>> C = harmonic_sphere_map([[12], [1, 3-1j], [3, 4-2j, 5-1j]]); C
        Brief complex harmonic sphere map with l=0..2 (6 coefficients)
        >>> R = C.to_real(); R
        Real harmonic sphere map with l=0..2 (9 coefficients)
        >>> x = R.to_array(); x[[0, 2, 6]] *= np.sqrt(2); x /= np.sqrt(2); x
        array([ 12.,  -1.,   1.,   3.,  -1.,  -2.,   3.,   4.,   5.])

        Many maps::

            >>> M = C
            >>> 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)
            >>> M.to_real()
            (4, 2)-stack of real harmonic sphere maps with l=0..2 (9 coefficients)
        """
        self._check_not_pretending()
        if self.format is REAL_FULL:
            return self
        elif self.format is COMPLEX_FULL:
            raise ValueError('Cannot convert full complex format to brief')            
        else:
            size = self.shape[1:]
            Nlm = lm_count_full(self.lmin, self.lmax)
            out = np.empty((Nlm,) + size, real_dtype, order='F')
            for mapidx in np.ndindex(*size):
                idx = (slice(None),) + mapidx
                mapdatautils.alm_complex2real(self.lmin, self.lmax, self[idx], out[idx])
            return _HarmonicSphereMap(out, self.lmin, self.lmax, REAL_FULL)
Ejemplo n.º 2
0
def random_real_harmonic_sphere_map(lmin, lmax, size=(), state=np.random):
    if np.isscalar(size):
        size = (size,)
    Nlm = lm_count_full(lmin, lmax)
    return _HarmonicSphereMap(state.standard_normal((Nlm,) + size).astype(real_dtype),
                              lmin, lmax,
                              format=REAL_FULL)
Ejemplo n.º 3
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")
Ejemplo n.º 4
0
    def to_full_complex(self):
        """
        ::

            >>> C = harmonic_sphere_map([[12], [2,3 - 1j], [3, 4 -1j, 5 +2j]]); C
            Brief complex harmonic sphere map with l=0..2 (6 coefficients)
            >>> F = C.to_full_complex(); F
            Full complex harmonic sphere map with l=0..2 (9 coefficients)
            >>> F.to_list()
            [(12+0j), (-3-1j), (2+0j), (3-1j), (5-2j), (-4-1j), (3+0j), (4-1j), (5+2j)]
            >>> F.to_full_complex() is F
            True

        Many maps::

            >>> M = C
            >>> 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)
            >>> M.to_full_complex()
            (4, 2)-stack of full complex harmonic sphere maps with l=0..2 (9 coefficients)

        """
        if self.format is COMPLEX_FULL:
            return self
        elif self.format is REAL_FULL:
            return self.to_complex().to_full_complex()
        else:
            size = self.shape[1:]
            Nlm = lm_count_full(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_complex_brief2full(self.lmin, self.lmax, self[idx], out[idx])
            return _HarmonicSphereMap(out, self.lmin, self.lmax, COMPLEX_FULL)