コード例 #1
0
ファイル: peak_height.py プロジェクト: jhod0/cluster_toolkit
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)
コード例 #2
0
ファイル: massfunction.py プロジェクト: jhod0/cluster_toolkit
def G_at_M(M, k, P, Omega_m, d=1.97, e=1.0, f=0.51, g=1.228):
    """Tinker et al. 2008 appendix C multiplicity funciton G(M) as
    a function of mass. Default behavior is for :math:`M_{200m}` mass
    definition.

    Args:
        M (float or array like): Mass in Msun/h.
        k (array like): Wavenumbers of the matter power spectrum in h/Mpc comoving.
        P_lin (array like): Linear matter power spectrum in (Mpc/h)^3 comoving.
        Omega_m (float): Matter density fraction.
        d (float; optional): First Tinker parameter. Default is 1.97.
        e (float; optional): Second Tinker parameter. Default is 1.
        f (float; optional): Third Tinker parameter. Default is 0.51.
        g (float; optional): Fourth Tinker parameter. Default is 1.228.

    Returns:
        float or array like: Halo multiplicity :math:`G(M)`.
    """
    M = _ArrayWrapper(M, 'M')
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)

    G = _ArrayWrapper.zeros_like(M)
    cluster_toolkit._lib.G_at_M_arr(M.cast(), len(M), k.cast(), P.cast(),
                                    len(k), Omega_m, d, e, f, g, G.cast())
    return G.finish()
コード例 #3
0
def xi_hm(xi_1halo, xi_2halo, combination="max"):
    """Halo-matter correlation function

    Note: at the moment you can combine the 1-halo and 2-halo terms by either taking the max of the two or the sum of the two. The 'combination' field must be set to either 'max' (default) or 'sum'.

    Args:
        xi_1halo (float or array like): 1-halo term
        xi_2halo (float or array like, same size as xi_1halo): 2-halo term
        combination (string; optional): specifies how the 1-halo and 2-halo terms are combined, default is 'max' which takes the max of the two

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

    """
    if combination == "max":
        switch = 0
    elif combination == 'sum':
        switch = 1
    else:
        raise Exception("Combinations other than maximum not implemented yet")

    xi_1halo = _ArrayWrapper(xi_1halo, allow_multidim=True)
    xi_2halo = _ArrayWrapper(xi_2halo, allow_multidim=True)
    xi = _ArrayWrapper.zeros_like(xi_1halo)
    cluster_toolkit._lib.calc_xi_hm(len(xi_1halo), xi_1halo.cast(),
                                    xi_2halo.cast(), xi.cast(), switch)
    return xi.finish()
コード例 #4
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()
コード例 #5
0
def xi_DK_appendix2(r, M, conc, be, se, k, P, om, bias, xi_mm, delta=200, rhos=-1., alpha=-1., beta=-1., gamma=-1.):
    """Diemer-Kravtsov 2014 profile, second form from the appendix, eq. A4.

    Args:
        r (float or array like): radii in Mpc/h comoving
        M (float): mass in Msun/h
        conc (float): Einasto concentration
        be (float): DK transition parameter
        se (float): DK transition parameter
        k (array like): wavenumbers in h/Mpc
        P (array like): matter power spectrum in [Mpc/h]^3
        Omega_m (float): matter density fraction
        bias (float): halo bias
        xi_mm (float or array like): matter correlation function at r
        delta (float): overdensity of matter. Optional, default is 200
        rhos (float): Einasto density. Optional, default is compute from the mass
        alpha (float): Einasto parameter. Optional, default is computed from peak height
        beta (float): DK 2-halo parameter. Optional, default is 4
        gamma (float): DK 2-halo parameter. Optional, default is 8

    Returns:
        float or array like: DK profile evaluated at the input radii
    """
    r = _ArrayWrapper(r, 'r')
    k = _ArrayWrapper(k)
    P = _ArrayWrapper(P)
    xi_mm = _ArrayWrapper(xi_mm)

    xi = _ArrayWrapper.zeros_like(r)
    cluster_toolkit._lib.calc_xi_DK_app2(r.cast(), len(r), M, rhos, conc, be,
                                         se, alpha, beta, gamma, delta,
                                         k.cast(), P.cast(), len(k), om, bias,
                                         xi_mm.cast(), xi.cast())
    return xi.finish()
コード例 #6
0
def DeltaSigma_mis_at_R(R, Rsigma, Sigma_mis):
    """Miscentered excess surface mass density profile at R. Units are Msun h/pc^2 comoving.

    Args:
        R (float or array like): Projected radii to evaluate profile.
        Rsigma (array like): Projected radii of miscentered Sigma profile.
        Sigma_mis (array like): Miscentered Sigma profile.

    Returns:
        float array like: Miscentered excess surface mass density profile.

    """
    R = _ArrayWrapper(R, 'R')
    if np.min(R.arr) < np.min(Rsigma):
        raise Exception("Minimum R must be >= min(R_Sigma)")
    if np.max(R.arr) > np.max(Rsigma):
        raise Exception("Maximum R must be <= max(R_Sigma)")

    Rsigma = _ArrayWrapper(Rsigma, allow_multidim=True)
    Sigma_mis = _ArrayWrapper(Sigma_mis, allow_multidim=True)

    if Rsigma.shape != Sigma_mis.shape:
        raise ValueError('Rsigma and Sigma must have the same shape')

    DeltaSigma_mis = _ArrayWrapper.zeros_like(R)
    cluster_toolkit._lib.DeltaSigma_mis_at_R_arr(R.cast(),
                                                 len(R), Rsigma.cast(),
                                                 Sigma_mis.cast(), len(Rsigma),
                                                 DeltaSigma_mis.cast())
    return DeltaSigma_mis.finish()
コード例 #7
0
ファイル: massfunction.py プロジェクト: jhod0/cluster_toolkit
def dndM_at_M(M, k, P, Omega_m, d=1.97, e=1.0, f=0.51, g=1.228):
    """Tinker et al. 2008 appendix C mass function at a given mass.
    Default behavior is for :math:`M_{200m}` mass definition.

    NOTE: by default, this function is only valid at :math:`z=0`. For use
    at higher redshifts either recompute the parameters yourself, or
    wait for this behavior to be patched.

    Args:
        M (float or array like): Mass in Msun/h.
        k (array like): Wavenumbers of the matter power spectrum in h/Mpc comoving.
        P_lin (array like): Linear matter power spectrum in (Mpc/h)^3 comoving.
        Omega_m (float): Matter density fraction.
        d (float; optional): First Tinker parameter. Default is 1.97.
        e (float; optional): Second Tinker parameter. Default is 1.
        f (float; optional): Third Tinker parameter. Default is 0.51.
        g (float; optional): Fourth Tinker parameter. Default is 1.228.

    Returns:
        float or array like: Mass function :math:`dn/dM`.

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

    dndM = _ArrayWrapper.zeros_like(M)
    cluster_toolkit._lib.dndM_at_M_arr(M.cast(), len(M), k.cast(), P.cast(),
                                       len(k), Omega_m, d, e, f, g,
                                       dndM.cast())
    return dndM.finish()
コード例 #8
0
ファイル: peak_height.py プロジェクト: jhod0/cluster_toolkit
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)
コード例 #9
0
ファイル: peak_height.py プロジェクト: jhod0/cluster_toolkit
def _calc_sigma2_at_R(R, k, P, s2):
    """Direct call to vectorized version of RMS variance in top hat
    sphere of radius R [Mpc/h comoving] of linear power spectrum.

    """
    R = _ArrayWrapper(R, allow_multidim=True)
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)
    s2 = _ArrayWrapper(s2, allow_multidim=True)
    cluster_toolkit._lib.sigma2_at_R_arr(R.cast(), len(R), k.cast(), P.cast(),
                                         len(k), s2.cast())
コード例 #10
0
ファイル: peak_height.py プロジェクト: jhod0/cluster_toolkit
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)
コード例 #11
0
def Sigma_mis_at_R(R,
                   Rsigma,
                   Sigma,
                   M,
                   conc,
                   Omega_m,
                   Rmis,
                   delta=200,
                   kernel="rayleigh"):
    """Miscentered surface mass density [Msun h/pc^2 comoving]
    convolved with a distribution for Rmis. Units are Msun h/pc^2 comoving.

    Args:
        R (float or array like): Projected radii Mpc/h comoving.
        Rsigma (array like): Projected radii of the centered surface mass density profile.
        Sigma (float or array like): Surface mass density Msun h/pc^2 comoving.
        M (float): Halo mass Msun/h.
        conc (float): concentration.
        Omega_m (float): Matter density fraction.
        Rmis (float): Miscentered distance in Mpc/h comoving.
        delta (int; optional): Overdensity, default is 200.
        kernel (string; optional): Kernal for convolution. Options: rayleigh or gamma.

    Returns:
        float or array like: Miscentered projected surface mass density.

    """
    R = _ArrayWrapper(R, 'R')

    # Exception checking
    if np.min(R.arr) < np.min(Rsigma):
        raise Exception("Minimum R must be >= min(R_Sigma)")
    if np.max(R.arr) > np.max(Rsigma):
        raise Exception("Maximum R must be <= max(R_Sigma)")
    if kernel == "rayleigh":
        integrand_switch = 0
    elif kernel == "gamma":
        integrand_switch = 1
    else:
        raise Exception("Miscentering kernel must be either " +
                        "'rayleigh' or 'gamma'")

    Rsigma = _ArrayWrapper(Rsigma, allow_multidim=True)
    Sigma = _ArrayWrapper(Sigma, allow_multidim=True)

    if Rsigma.shape != Sigma.shape:
        raise ValueError('Rsigma and Sigma must have the same shape')

    Sigma_mis = _ArrayWrapper.zeros_like(R)
    cluster_toolkit._lib.Sigma_mis_at_R_arr(R.cast(), len(R), Rsigma.cast(),
                                            Sigma.cast(), len(Rsigma), M, conc,
                                            delta, Omega_m, Rmis,
                                            integrand_switch, Sigma_mis.cast())
    return Sigma_mis.finish()
コード例 #12
0
ファイル: peak_height.py プロジェクト: jhod0/cluster_toolkit
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)
コード例 #13
0
def concentration_at_M(Mass,
                       k,
                       P,
                       n_s,
                       Omega_b,
                       Omega_m,
                       h,
                       T_CMB=2.7255,
                       delta=200,
                       Mass_type="crit"):
    """Concentration of the NFW profile at mass M [Msun/h].
    Only implemented relation at the moment is Diemer & Kravtsov (2015).

    Note: only single concentrations at a time are allowed at the moment.

    Args:
        Mass (float): Mass in Msun/h.
        k (array like): Wavenumbers of power spectrum in h/Mpc comoving.
        P (array like): Linear matter power spectrum in (Mpc/h)^3 comoving.
        n_s (float): Power spectrum tilt.
        Omega_b (float): Baryonic matter density fraction.
        Omega_m (float): Matter density fraction.
        h (float): Reduced Hubble constant.
        T_CMB (float): CMB temperature in Kelvin, default is 2.7.
        delta (int; optional): Overdensity, default is 200.
        Mass_type(string; optional); Defines either Mcrit or Mmean. Default is mean. Choose "crit" for Mcrit. Other values will raise an exception.

    Returns:
        float: NFW concentration.

    """
    if delta != 200:
        raise Exception(
            "ConcentrationError: delta=%d. Currently only delta=200 supported"
            % delta)

    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)

    if Mass_type is "mean":
        return cluster_toolkit._lib.DK15_concentration_at_Mmean(
            Mass, k.cast(), P.cast(), len(k), delta, n_s, Omega_b, Omega_m, h,
            T_CMB)
    elif Mass_type is "crit":
        return cluster_toolkit._lib.DK15_concentration_at_Mcrit(
            Mass, k.cast(), P.cast(), len(k), delta, n_s, Omega_b, Omega_m, h,
            T_CMB)
    else:
        raise Exception(
            "ConcentrationError: must choose either 'mean' or 'crit', %s is not supported"
            % Mass_type)
コード例 #14
0
ファイル: massfunction.py プロジェクト: jhod0/cluster_toolkit
def _dndM_sigma2_precomputed(M,
                             sigma2,
                             dsigma2dM,
                             Omega_m,
                             d=1.97,
                             e=1.0,
                             f=0.51,
                             g=1.228):
    M = _ArrayWrapper(M, allow_multidim=True)
    sigma2 = _ArrayWrapper(sigma2, allow_multidim=True)
    dsigma2dM = _ArrayWrapper(dsigma2dM, allow_multidim=True)
    dndM = _ArrayWrapper.zeros_like(M)
    cluster_toolkit._lib.dndM_sigma2_precomputed(M.cast(), sigma2.cast(),
                                                 dsigma2dM.cast(), len(M),
                                                 Omega_m, d, e, f, g,
                                                 dndM.cast())
    return dndM.finish()
コード例 #15
0
ファイル: bias.py プロジェクト: jhod0/cluster_toolkit
def _bias_at_nu_FREEPARAMS(nu, A, a, B, b, C, c, delta=200):
    """A special function used only for quickly computing best fit parameters
    for the halo bias models.
    """
    nu = _ArrayWrapper(nu, allow_multidim=True)
    bias = _ArrayWrapper.zeros_like(nu)
    cluster_toolkit._lib.bias_at_nu_arr_FREEPARAMS(nu.cast(), len(nu),
                                                   delta, A, a, B, b, C, c,
                                                   bias.cast())
    return bias.finish()
コード例 #16
0
ファイル: massfunction.py プロジェクト: jhod0/cluster_toolkit
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()
コード例 #17
0
ファイル: bias.py プロジェクト: jhod0/cluster_toolkit
def bias_at_R(R, k, P, delta=200):
    """Tinker 2010 bais at mass M [Msun/h] corresponding to radius R [Mpc/h comoving].

    Args:
        R (float or array like): Lagrangian 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.
        delta (int; optional): Overdensity, default is 200.

    Returns:
        float or array like: Halo bias.

    """
    R = _ArrayWrapper(R, 'R')
    k = _ArrayWrapper(k)
    P = _ArrayWrapper(P)

    bias = _ArrayWrapper.zeros_like(R)
    cluster_toolkit._lib.bias_at_R_arr(R.cast(), len(R), delta, k.cast(),
                                       P.cast(), len(k), bias.cast())
    return bias.finish()
コード例 #18
0
ファイル: peak_height.py プロジェクト: jhod0/cluster_toolkit
def nu_at_R(R, k, P):
    """Peak height of 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: Peak height.

    """
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)
    if isinstance(R, list) or isinstance(R, np.ndarray):
        R = _ArrayWrapper(R)
        nu = _ArrayWrapper.zeros_like(R)
        cluster_toolkit._lib.nu_at_R_arr(R.cast(), len(R), k.cast(), P.cast(),
                                         len(k), nu.cast())
        return nu.finish()
    else:
        return cluster_toolkit._lib.nu_at_R(R, k.cast(), P.cast(), len(k))
コード例 #19
0
def Sigma_mis_single_at_R(R, Rsigma, Sigma, M, conc, Omega_m, Rmis, delta=200):
    """Miscentered surface mass density [Msun h/pc^2 comoving] of a profile miscentered by an
    amount Rmis Mpc/h comoving. Units are Msun h/pc^2 comoving.

    Args:
        R (float or array like): Projected radii Mpc/h comoving.
        Rsigma (array like): Projected radii of the centered surface mass density profile.
        Sigma (float or array like): Surface mass density Msun h/pc^2 comoving.
        M (float): Halo mass Msun/h.
        conc (float): concentration.
        Omega_m (float): Matter density fraction.
        Rmis (float): Miscentered distance in Mpc/h comoving.
        delta (int; optional): Overdensity, default is 200.

    Returns:
        float or array like: Miscentered projected surface mass density.

    """
    R = _ArrayWrapper(R, 'R')

    if np.min(R.arr) < np.min(Rsigma):
        raise Exception("Minimum R must be >= min(R_Sigma)")
    if np.max(R.arr) > np.max(Rsigma):
        raise Exception("Maximum R must be <= max(R_Sigma)")

    Rsigma = _ArrayWrapper(Rsigma, allow_multidim=True)
    Sigma = _ArrayWrapper(Sigma, allow_multidim=True)

    if Rsigma.shape != Sigma.shape:
        raise ValueError('Rsigma and Sigma must have the same shape')

    Sigma_mis = _ArrayWrapper.zeros_like(R)
    cluster_toolkit._lib.Sigma_mis_single_at_R_arr(R.cast(), len(R),
                                                   Rsigma.cast(), Sigma.cast(),
                                                   len(Rsigma), M, conc, delta,
                                                   Omega_m, Rmis,
                                                   Sigma_mis.cast())
    return Sigma_mis.finish()
コード例 #20
0
ファイル: peak_height.py プロジェクト: jhod0/cluster_toolkit
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))
コード例 #21
0
ファイル: bias.py プロジェクト: jhod0/cluster_toolkit
def dbiasdM_at_M(M, k, P, Omega_m, delta=200):
    """d/dM of Tinker et al. 2010 bais at mass M [Msun/h].

    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): Matter density fraction.
        delta (int; optional): Overdensity, default is 200.

    Returns:
        float or array like: Derivative of the halo bias.

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

    deriv = _ArrayWrapper.zeros_like(M)
    cluster_toolkit._lib.dbiasdM_at_M_arr(M.cast(), len(M), delta, k.cast(),
                                          P.cast(), len(k), Omega_m,
                                          deriv.cast())
    return deriv.finish()
コード例 #22
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()
コード例 #23
0
def Sigma_REC_from_DeltaSigma(R, DeltaSigma):
    """Reconstructed Sigma(R) profile, also known as 'Y'
    in the same units as DeltaSigma.

    Note: R and DeltaSigma must have the same shape,
    and have more than 1 element. The returned array
    has one fewer elements.

    Note: R must have constant logarithmic spacing.

    Args:
        R (array like): Projected radii.
        DeltaSigma (array like): Differential surface mass density.

    Returns:
        Reconstructed surface mass density.
    """
    R = _ArrayWrapper(R, allow_multidim=True)
    DeltaSigma = _ArrayWrapper(DeltaSigma, allow_multidim=True)
    if R.shape != DeltaSigma.shape:
        raise Exception("R and DeltaSigma must have the same shape.")

    lnR = np.log(R)
    for i in range(len(lnR) - 2):
        dlnR0 = lnR[i] - lnR[i + 1]
        dlnR1 = lnR[i + 1] - lnR[i + 2]
        if not (np.fabs(dlnR0 - dlnR1) < 1e-6):
            raise Exception("R must have constant logarithmic spacing.")
        continue

    #Note the order here, we integrate DOWNWARD
    dlnR = lnR[0] - lnR[1]

    Sigma = _ArrayWrapper.zeros(len(R) - 1)
    cluster_toolkit._lib.Sigma_REC_from_DeltaSigma(dlnR, DeltaSigma.cast(),
                                                   len(R), Sigma.cast())
    return Sigma.finish()
コード例 #24
0
ファイル: bias.py プロジェクト: jhod0/cluster_toolkit
def bias_at_M(M, k, P, Omega_m, delta=200):
    """Tinker et al. 2010 bais at mass M [Msun/h].

    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): Matter density fraction.
        delta (int; optional): Overdensity, default is 200.

    Returns:
        float or array like: Halo bias.

    """
    M = _ArrayWrapper(M, 'M')
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)
    if k.shape != P.shape:
        raise ValueError('k and P must have the same shape')

    bias = _ArrayWrapper.zeros_like(M)
    cluster_toolkit._lib.bias_at_M_arr(M.cast(), len(M), delta, k.cast(),
                                       P.cast(), len(k), Omega_m, bias.cast())
    return bias.finish()
コード例 #25
0
ファイル: peak_height.py プロジェクト: jhod0/cluster_toolkit
def nu_at_M(M, k, P, Omega_m):
    """Peak height of 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:
        nu (float or array like): Peak height.

    """
    k = _ArrayWrapper(k, allow_multidim=True)
    P = _ArrayWrapper(P, allow_multidim=True)
    if isinstance(M, list) or isinstance(M, np.ndarray):
        M = _ArrayWrapper(M)
        nu = _ArrayWrapper.zeros_like(M)
        cluster_toolkit._lib.nu_at_M_arr(M.cast(), len(M), k.cast(), P.cast(),
                                         len(k), Omega_m, nu.cast())
        return nu.finish()
    else:
        return cluster_toolkit._lib.nu_at_M(M, k.cast(), P.cast(), len(k),
                                            Omega_m)
コード例 #26
0
def xi_2halo(bias, xi_mm):
    """2-halo term in halo-matter correlation function

    Args:
        bias (float): Halo bias
        xi_mm (float or array like): Matter-matter correlation function

    Returns:
        float or array like: 2-halo term in halo-matter correlation function

    """
    xi_mm = _ArrayWrapper(xi_mm, allow_multidim=True)
    xi = _ArrayWrapper.zeros_like(xi_mm)
    cluster_toolkit._lib.calc_xi_2halo(len(xi_mm), bias, xi_mm.cast(),
                                       xi.cast())
    return xi.finish()
コード例 #27
0
ファイル: bias.py プロジェクト: jhod0/cluster_toolkit
def bias_at_nu(nu, delta=200):
    """Tinker 2010 bais at peak height nu.

    Args:
        nu (float or array like): Peak height.
        delta (int; optional): Overdensity, default is 200.

    Returns:
        float or array like: Halo bias.

    """
    nu = _ArrayWrapper(nu, 'nu')

    bias = _ArrayWrapper.zeros_like(nu)
    cluster_toolkit._lib.bias_at_nu_arr(nu.cast(), len(nu), delta, bias.cast())
    return bias.finish()
コード例 #28
0
def boost_nfw_at_R(R, B0, R_scale):
    """NFW boost factor model.

    Args:
        R (float or array like): Distances on the sky in the same units as R_scale. Mpc/h comoving suggested for consistency with other modules.
        B0 (float): NFW profile amplitude.
        R_scale (float): NFW profile scale radius.

    Returns:
        float or array like: NFW boost factor profile; B = (1-fcl)^-1.

    """
    R = _ArrayWrapper(R, 'R')

    boost = _ArrayWrapper.zeros_like(R)
    cluster_toolkit._lib.boost_nfw_at_R_arr(R.cast(), len(R), B0, R_scale,
                                            boost.cast())
    return boost.finish()
コード例 #29
0
def xi_nfw_at_r(r, M, c, Omega_m, delta=200):
    """NFW halo profile correlation function.

    Args:
        r (float or array like): 3d distances from halo center in Mpc/h comoving
        M (float): Mass in Msun/h
        c (float): Concentration
        Omega_m (float): Omega_matter, matter fraction of the density
        delta (int; optional): Overdensity, default is 200

    Returns:
        float or array like: NFW halo profile.

    """
    r = _ArrayWrapper(r, 'r')

    xi = _ArrayWrapper.zeros_like(r)
    cluster_toolkit._lib.calc_xi_nfw(r.cast(), len(r), M, c, delta,
                                     Omega_m, xi.cast())
    return xi.finish()
コード例 #30
0
def rho_nfw_at_r(r, M, c, Omega_m, delta=200):
    """NFW halo density profile.

    Args:
        r (float or array like): 3d distances from halo center in Mpc/h comoving.
        M (float): Mass in Msun/h.
        c (float): Concentration.
        Omega_m (float): Omega_matter, matter fraction of the density.
        delta (int; optional): Overdensity, default is 200.

    Returns:
        float or array like: NFW halo density profile in Msun h^2/Mpc^3 comoving.

    """
    r = _ArrayWrapper(r, 'r')

    rho = _ArrayWrapper.zeros_like(r)
    cluster_toolkit._lib.calc_rho_nfw(r.cast(), len(r), M, c, delta, Omega_m,
                                      rho.cast())
    return rho.finish()