예제 #1
0
def _return_covariance(kind, grid, **kwargs):
    """
    Internal helper function to return gaussian covariance 
    """
    kmin = kwargs['kmin']; kmax = kwargs['kmax']
    power = kwargs['power']
    
    if kind == 'pole':
        transfer = PolesTransfer(grid, kwargs['ells'], kmin=kmin, kmax=kmax, power=power)
    elif kind == 'pkmu':
        transfer = PkmuTransfer(grid, kwargs['mu_bounds'], kmin=kmin, kmax=kmax, power=power)
    else:
        raise ValueError("`kind` must be `pole` or `pkmu`")
    
    coords = transfer.coords_flat
    return transfer.to_covariance(components=kwargs['components']), coords
예제 #2
0
def cutsky_pole_gausscov(pkmu, ells, cosmo, zbins, nbar_spline, P0, fsky, kmin=-np.inf, kmax=np.inf):
    """
    Compute the gaussian covariance for a set of cutsky multipole measurements,
    from the measured P(k,mu) simulation boxes
    
    Parameters
    ----------
    pkmu : nbodykit.PkmuResult
        the mean P(k,mu) periodic measurement, on the finely-binned grid
    ells : array_like, (Nell,)
        the desired multipole numbers
    cosmo : pygcl.Cosmology
        the cosmology instance used in the volume calculation
    zbins : array_like
        bins in redshift, used in the volume calculation
    nbar_spline : callable
        a function returning n(z)
    P0 : float
        the value of P0 used in the FKP weight
    fsky : float
        the fraction of the sky area covered
    kmin : {float, array_like}, optional
        minimum wavenumber to trim by (inclusively), in h/Mpc
    kmax : {float, array_like}, optional
        maximum wavenumber to trim by (inclusively), in h/Mpc
        
    Returns
    -------
    cov : (N, N)
        the covariance matrix for the multipole measurements
    coords : list
        list of the flat coordinates corresponding to the the cov

    """    
    # initialize the grid transfer
    data = pkmu.data.copy()
    grid = PkmuGrid.from_structured([pkmu.coords['k_cen'], pkmu.coords['mu_cen']], data)
    
    # return the Gaussian covariance components
    power = data['power'] - tools.get_Pshot(pkmu)    
    transfer = PolesTransfer(grid, ells, kmin=kmin, kmax=kmax, power=power)

    coords = transfer.coords_flat
    C = transfer.to_cutsky_covariance(cosmo, zbins, nbar_spline, P0, fsky)
    return C, coords
예제 #3
0
def gal_power_discrete(model):

    # set up fake 1D k, mu bins
    k_1d = numpy.arange(0.01, 0.4, 0.005)
    mu_1d = numpy.linspace(0, 1.0, 100)

    # convert to a 2D grid
    # shape is (78, 100)
    k, mu = numpy.meshgrid(k_1d, mu_1d, indexing='ij')

    # assign random weights for each bin for illustration purposes
    modes = numpy.random.random(size=k.shape)

    # simulate missing data
    missing = numpy.random.randint(0, numpy.prod(modes.shape), size=10)
    modes.flat[missing] = numpy.nan

    # initialize the grid
    grid = PkmuGrid([k_1d, mu_1d], k, mu, modes)

    # edges of the mu bins
    mu_bounds = [(0., 0.2), (0.2, 0.4), (0.4, 0.6), (0.6, 0.8), (0.8, 1.0)]

    # the transfer function, with specified valid k range
    transfer = PkmuTransfer(grid, mu_bounds, kmin=0.01, kmax=0.4)

    # evaluate the model with this transfer function
    Pkmu_binned = model.from_transfer(transfer)

    # get the coordinate arrays from the grid
    k, mu = transfer.coords  # this has shape of (Nk, Nmu)

    for i in range(mu.shape[1]):
        plt.loglog(k[:, i],
                   Pkmu_binned[:, i],
                   label=r"$\mu = %.1f$" % mu[:, i].mean())

    plt.legend(loc=0)
    plt.xlabel(r"$k$ $[h \mathrm{Mpc}^{-1}]$", fontsize=10)
    plt.ylabel(r"$P$ $[h^{-3} \mathrm{Mpc}^3]$", fontsize=10)
    savefig("pkmu_binned_plot.png")

    # the multipoles to compute
    ells = [0, 2, 4]

    # the transfer function, with specified valid k range
    transfer = PolesTransfer(grid, ells, kmin=0.01, kmax=0.4)

    # evaluate the model with this transfer function
    poles_binned = model.from_transfer(transfer)  # shape is (78, 3)

    # get the coordinate arrays from the grid
    k, mu = transfer.coords  # this has shape of (Nk, Nmu)

    for i, iell in enumerate(ells):
        plt.loglog(k[:, i], poles_binned[:, i], label=r"$\ell = %d$" % iell)

    plt.legend(loc=0)
    plt.xlabel(r"$k$ $[h \mathrm{Mpc}^{-1}]$", fontsize=10)
    plt.ylabel(r"$P_\ell$ $[h^{-3} \mathrm{Mpc}^3]$", fontsize=10)
    savefig("poles_binned_plot.png")