def generate_weight(self, regen = False):
        r"""Pregenerate the k weights array.

        Parameters
        ==========
        regen : boolean, optional
            If True, force regeneration of the weights, to be used if
            parameters have been changed,
        """
        
        if self._weight_gen and not regen:
            return
        
        f1, f2 = np.meshgrid(self.nu_pixels, self.nu_pixels)

        ch = self.frequency_covariance(f1, f2)

        self._freq_weight, self._num_corr_freq = nputil.matrix_root_manynull(ch)

        rf = gaussianfield.RandomFieldA2.like_map(self)

        ## Construct a lambda function to evalutate the array of
        ## k-vectors.
        rf.powerspectrum = lambda karray: self.angular_ps((karray**2).sum(axis=2)**0.5)

        self._ang_field = rf
        self._weight_gen = True
Beispiel #2
0
def mkfullsky(corr, nside, alms = False):
    """Construct a set of correlated Healpix maps.
    
    Make a set of full sky gaussian random fields, given the correlation
    structure. Useful for constructing a set of different redshift slices.

    Parameters
    ----------
    corr : np.ndarray (lmax+1, numz, numz)
        The correlation matrix :math:`C_l(z, z')`.
    nside : integer
        The resolution of the Healpix maps.
    alms : boolean, optional
        If True return the alms instead of the sky maps.

    Returns
    -------
    hpmaps : np.ndarray (numz, npix)
        The Healpix maps. hpmaps[i] is the i'th map.
    """

    numz = corr.shape[1]
    maxl = corr.shape[0]-1

    if corr.shape[2] != numz:
        raise Exception("Correlation matrix is incorrect shape.")

    trans = np.zeros_like(corr)

    for i in range(maxl+1):
        trans[i] = nputil.matrix_root_manynull(corr[i], truncate=False)

    
    la, ma = healpy.Alm.getlm(maxl)

    matshape = la.shape + (numz,)

    # Construct complex gaussian random variables of unit variance
    gaussvars = (np.random.standard_normal(matshape)
                 + 1.0J * np.random.standard_normal(matshape)) / 2.0**0.5

    # Transform variables to have correct correlation structure
    for i, l in enumerate(la):
        gaussvars[i] = np.dot(trans[l], gaussvars[i])

    if alms:
        alm_freq = np.zeros((numz, maxl+1, 2*maxl+1), dtype=np.complex128)
        for i in range(numz):
            alm_freq[i] = hputil.unpack_alm(gaussvars[:, i], maxl, fullm=True)
        
        return alm_freq

    hpmaps = np.empty((numz, healpy.nside2npix(nside)))

    # Perform the spherical harmonic transform for each z
    for i in range(numz):
        hpmaps[i] = healpy.alm2map(gaussvars[:,i].copy(), nside)
        
    return hpmaps
Beispiel #3
0
def mkfullsky(corr, nside, alms=False):
    """Construct a set of correlated Healpix maps.
    
    Make a set of full sky gaussian random fields, given the correlation
    structure. Useful for constructing a set of different redshift slices.

    Parameters
    ----------
    corr : np.ndarray (lmax+1, numz, numz)
        The correlation matrix :math:`C_l(z, z')`.
    nside : integer
        The resolution of the Healpix maps.
    alms : boolean, optional
        If True return the alms instead of the sky maps.

    Returns
    -------
    hpmaps : np.ndarray (numz, npix)
        The Healpix maps. hpmaps[i] is the i'th map.
    """

    numz = corr.shape[1]
    maxl = corr.shape[0] - 1

    if corr.shape[2] != numz:
        raise Exception("Correlation matrix is incorrect shape.")

    trans = np.zeros_like(corr)

    for i in range(maxl + 1):
        trans[i] = nputil.matrix_root_manynull(corr[i], truncate=False)

    la, ma = healpy.Alm.getlm(maxl)

    matshape = la.shape + (numz, )

    # Construct complex gaussian random variables of unit variance
    gaussvars = (np.random.standard_normal(matshape) +
                 1.0J * np.random.standard_normal(matshape)) / 2.0**0.5

    # Transform variables to have correct correlation structure
    for i, l in enumerate(la):
        gaussvars[i] = np.dot(trans[l], gaussvars[i])

    if alms:
        alm_freq = np.zeros((numz, maxl + 1, 2 * maxl + 1),
                            dtype=np.complex128)
        for i in range(numz):
            alm_freq[i] = hputil.unpack_alm(gaussvars[:, i], maxl, fullm=True)

        return alm_freq

    hpmaps = np.empty((numz, healpy.nside2npix(nside)))

    # Perform the spherical harmonic transform for each z
    for i in range(numz):
        hpmaps[i] = healpy.alm2map(gaussvars[:, i].copy(), nside)

    return hpmaps