예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
파일: skysim.py 프로젝트: HaMetBacon/cora
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, maxl+1), dtype=np.complex128)
        for i in range(numz):
            alm_freq[i] = hputil.unpack_alm(gaussvars[:, i], maxl)
        
        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
예제 #4
0
파일: psmc.py 프로젝트: nolta/driftscan
def block_root(clzz):
    """Calculate the 'square root' of an angular powerspectrum matrix (with
    nulls).
    """

    trans = np.zeros_like(clzz)

    for i in range(trans.shape[0]):
        trans[i] = nputil.matrix_root_manynull(clzz[i], truncate=False)

    return trans
예제 #5
0
def block_root(clzz):
    """Calculate the 'square root' of an angular powerspectrum matrix (with
    nulls).
    """

    trans = np.zeros_like(clzz)

    for i in range(trans.shape[0]):
        trans[i] = nputil.matrix_root_manynull(clzz[i], truncate=False)

    return trans
예제 #6
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.")

    alm_array = np.zeros((numz, 1, maxl + 1, maxl + 1), dtype=np.complex128)

    # Generate gaussian deviates and transform to have correct correlation
    # structure
    for l in range(maxl + 1):
        # Add in a small diagonal to try and ensure positive definiteness
        cmax = corr[l].diagonal().max() * 1e-14
        corrm = corr[l] + np.identity(numz) * cmax

        trans = nputil.matrix_root_manynull(corrm, truncate=False)
        gaussvars = nputil.complex_std_normal((numz, l + 1))
        alm_array[:, 0, l, :(l + 1)] = np.dot(trans, gaussvars)

    if alms:
        return alm_array

    # Perform the spherical harmonic transform for each z
    sky = hputil.sphtrans_inv_sky(alm_array, nside)
    sky = sky[:, 0]

    return sky
예제 #7
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.")

    alm_array = np.zeros((numz, 1, maxl + 1, maxl + 1), dtype=np.complex128)

    # Generate gaussian deviates and transform to have correct correlation
    # structure
    for l in range(maxl + 1):
        # Add in a small diagonal to try and ensure positive definiteness
        cmax = corr[l].diagonal().max() * 1e-14
        corrm = corr[l] + np.identity(numz) * cmax

        trans = nputil.matrix_root_manynull(corrm, truncate=False)
        gaussvars = nputil.complex_std_normal((numz, l + 1))
        alm_array[:, 0, l, :(l + 1)] = np.dot(trans, gaussvars)

    if alms:
        return alm_array

    # Perform the spherical harmonic transform for each z
    sky = hputil.sphtrans_inv_sky(alm_array, nside)
    sky = sky[:, 0]

    return sky