Esempio n. 1
0
def sigma2_at_M(M, k, P, Omega_m):
    """RMS variance in top hat sphere of lagrangian radius R [Mpc/h comoving] corresponding to a mass M [Msun/h] of linear power spectrum.

    Args:
        M (float or array like): Mass in Msun/h.
        k (array like): Wavenumbers of power spectrum in h/Mpc comoving.
        P (array like): Power spectrum in (Mpc/h)^3 comoving.
        Omega_m (float): Omega_matter, matter density fraction.

    Returns:
        float or array like: RMS variance of top hat sphere.

    """
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)
    if isinstance(M, list) or isinstance(M, np.ndarray):
        M = _ArrayWrapper(M, allow_multidim=True)
        s2 = _ArrayWrapper.zeros_like(M)
        rc = cluster_toolkit._lib.sigma2_at_M_arr(M.cast(), len(M), k.cast(),
                                                  P.cast(), len(k), Omega_m,
                                                  s2.cast())
        _handle_gsl_error(rc, sigma2_at_M)
        return s2.finish()
    else:
        return cluster_toolkit._lib.sigma2_at_M(M, k.cast(), P.cast(), len(k),
                                                Omega_m)
Esempio n. 2
0
def xi_mm_at_r(r, k, P, N=500, step=0.005, exact=False):
    """Matter-matter correlation function.

    Args:
        r (float or array like): 3d distances from halo center in Mpc/h comoving
        k (array like): Wavenumbers of power spectrum in h/Mpc comoving
        P (array like): Matter power spectrum in (Mpc/h)^3 comoving
        N (int; optional): Quadrature step count, default is 500
        step (float; optional): Quadrature step size, default is 5e-3
        exact (boolean): Use the slow, exact calculation; default is False

    Returns:
        float or array like: Matter-matter correlation function

    """
    r = _ArrayWrapper(r, 'r')
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)

    xi = _ArrayWrapper.zeros_like(r)
    if not exact:
        rc = cluster_toolkit._lib.calc_xi_mm(r.cast(), len(r), k.cast(),
                                             P.cast(), len(k), xi.cast(),
                                             N, step)
        _handle_gsl_error(rc, xi_mm_at_r)
    else:
        if r.arr.max() > 1e3:
            raise Exception("max(r) cannot be >1e3 for numerical stability.")
        rc = cluster_toolkit._lib.calc_xi_mm_exact(r.cast(), len(r),
                                                   k.cast(), P.cast(),
                                                   len(k), xi.cast())
        _handle_gsl_error(rc, xi_mm_at_r)

    return xi.finish()
Esempio n. 3
0
def theta_at_r(radii, rt, beta):
    """Truncation function.

    Args:
        radii (float or array-like): Radii of the profile in Mpc/h
        rt (float): truncation radius in Mpc/h
        beta (float): width of the truncation distribution (erfc) in Mpc/h

    Returns:
        float or array-like: Truncation function

    """
    radii = np.asarray(radii)
    scalar_input = False
    if radii.ndim == 0:
        radii = radii[None] #makes r 1D
        scalar_input = True
    if radii.ndim > 1:
        raise Exception("radii cannot be a >1D array.")

    theta = np.zeros_like(radii)
    rc = cluster_toolkit._lib.theta_erfc_at_r_arr(dc(radii), len(radii),
                                                  rt, beta, dc(theta))
    _handle_gsl_error(rc)
    if scalar_input:
        return np.squeeze(theta)
    return theta
Esempio n. 4
0
def _calc_nu_at_M(M, k, P, Omega_m, nu):
    """Direct call to vectorized version of peak height of M.

    """
    M = _ArrayWrapper(M, allow_multidim=True)
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)
    nu = _ArrayWrapper(nu, allow_multidim=True)
    rc = cluster_toolkit._lib.nu_at_M_arr(M.cast(), len(M), k.cast(), P.cast(),
                                          len(k), Omega_m, nu.cast())
    _handle_gsl_error(rc, _calc_nu_at_M)
Esempio n. 5
0
def _calc_nu_at_R(R, k, P, nu):
    """Direct call to vectorized version of peak height of R.

    """
    R = _ArrayWrapper(R, allow_multidim=True)
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)
    nu = _ArrayWrapper(nu, allow_multidim=True)
    rc = cluster_toolkit._lib.nu_at_R_arr(R.cast(), len(R), k.cast(), P.cast(),
                                          len(k), nu.cast())
    _handle_gsl_error(rc, _calc_nu_at_R)
Esempio n. 6
0
def _calc_sigma2_at_M(M, k, P, Omega_m, s2):
    """Direct call to vectorized version of RMS variance in top hat sphere of lagrangian radius R [Mpc/h comoving] corresponding to a mass M [Msun/h] of linear power spectrum.

    """
    M = _ArrayWrapper(M, allow_multidim=True)
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)
    s2 = _ArrayWrapper(s2, allow_multidim=True)
    rc = cluster_toolkit._lib.sigma2_at_M_arr(M.cast(), len(M), k.cast(),
                                              P.cast(), len(k), Omega_m,
                                              s2.cast())
    _handle_gsl_error(rc, _calc_sigma2_at_M)
Esempio n. 7
0
def n_in_bins(edges, Marr, dndM):
    """Tinker et al. 2008 appendix C binned mass function.

    Args:
        edges (array like): Edges of the mass bins.
        Marr (array like): Array of locations that dndM has been evaluated at.
        dndM (array like): Array of dndM.

    Returns:
       numpy.ndarray: number density of halos in the mass bins. Length is :code:`len(edges)-1`.

    """
    edges = _ArrayWrapper(edges, 'edges')

    n = _ArrayWrapper.zeros(len(edges) - 1)
    Marr = _ArrayWrapper(Marr, 'Marr')
    dndM = _ArrayWrapper(dndM, 'dndM')
    rc = cluster_toolkit._lib.n_in_bins(edges.cast(), len(edges), Marr.cast(),
                                        dndM.cast(), len(Marr), n.cast())
    _handle_gsl_error(rc, n_in_bins)
    return n.finish()
Esempio n. 8
0
def sigma2_at_R(R, k, P):
    """RMS variance in top hat sphere of radius R [Mpc/h comoving] of linear power spectrum.

    Args:
        R (float or array like): Radius in Mpc/h comoving.
        k (array like): Wavenumbers of power spectrum in h/Mpc comoving.
        P (array like): Power spectrum in (Mpc/h)^3 comoving.

    Returns:
        float or array like: RMS variance of a top hat sphere.

    """
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)
    if isinstance(R, list) or isinstance(R, np.ndarray):
        R = _ArrayWrapper(R)
        s2 = _ArrayWrapper.zeros_like(R)
        rc = cluster_toolkit._lib.sigma2_at_R_arr(R.cast(), len(R), k.cast(),
                                                  P.cast(), len(k), s2.cast())
        _handle_gsl_error(rc, sigma2_at_R)
        return s2.finish()
    else:
        return cluster_toolkit._lib.sigma2_at_R(R, k.cast(), P.cast(), len(k))
Esempio n. 9
0
def average_profile_in_bins(Redges, R, prof):
    """Average profile in bins.

    Calculates the average of some projected profile in a
    radial bins in Mpc/h comoving.

    Args:
        Redges (array like): Array of radial bin edges.
        R (array like): Radii of the profile.
        prof (array like): Projected profile.

    Returns:
        numpy.array: Average profile in bins between the edges provided.

    """
    Redges = _ArrayWrapper(Redges)
    R = _ArrayWrapper(R)
    prof = _ArrayWrapper(prof)

    if Redges.ndim == 0:
        raise Exception("Must supply a left and right edge.")
    if Redges.ndim > 1:
        raise Exception("Redges cannot be a >1D array.")
    if np.min(Redges.arr) < np.min(R.arr):
        raise Exception("Minimum edge must be >= minimum R")
    if np.max(Redges.arr) > np.max(R.arr):
        raise Exception("Maximum edge must be <= maximum R")

    ave_prof = _ArrayWrapper(np.zeros(len(Redges) - 1))
    r = cluster_toolkit._lib.average_profile_in_bins(Redges.cast(),
                                                     len(Redges), R.cast(),
                                                     len(R), prof.cast(),
                                                     ave_prof.cast())

    _handle_gsl_error(r, average_profile_in_bins)

    return ave_prof.finish()