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()
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()
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()
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()
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)
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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))
def rho_einasto_at_r(r, M, rs, alpha, Omega_m, delta=200, rhos=-1.): """Einasto halo density profile. Distances are Mpc/h comoving. Args: r (float or array like): 3d distances from halo center. M (float): Mass in Msun/h; not used if rhos is specified. rhos (float): Scale density in Msun h^2/Mpc^3 comoving; optional. rs (float): Scale radius. alpha (float): Profile exponent. Omega_m (float): Omega_matter, matter fraction of the density. delta (int): Overdensity, default is 200. Returns: float or array like: Einasto halo density profile in Msun h^2/Mpc^3 comoving. """ r = _ArrayWrapper(r, 'r') rho = _ArrayWrapper.zeros_like(r) cluster_toolkit._lib.calc_rho_einasto(r.cast(), len(r), M, rhos, rs, alpha, delta, Omega_m, rho.cast()) return rho.finish()
def xi_einasto_at_r(r, M, conc, alpha, om, delta=200, rhos=-1.): """Einasto halo profile. Args: r (float or array like): 3d distances from halo center in Mpc/h comoving M (float): Mass in Msun/h; not used if rhos is specified conc (float): Concentration alpha (float): Profile exponent om (float): Omega_matter, matter fraction of the density delta (int): Overdensity, default is 200 rhos (float): Scale density in Msun h^2/Mpc^3 comoving; optional Returns: float or array like: Einasto halo profile. """ r = _ArrayWrapper(r, 'r') xi = _ArrayWrapper.zeros_like(r) cluster_toolkit._lib.calc_xi_einasto(r.cast(), len(r), M, rhos, conc, alpha, delta, om, xi.cast()) return xi.finish()
def drho_nfw_dr_at_R(Radii, Mass, conc, Omega_m, delta=200): """Derivative of the NFW halo density profile. Args: Radii (float or array like): 3d distances from halo center in Mpc/h comoving Mass (float): Mass in Msun/h conc (float): Concentration Omega_m (float): Matter fraction of the density delta (int; optional): Overdensity, default is 200 Returns: float or array like: derivative of the NFW profile. """ Radii = _ArrayWrapper(Radii, allow_multidim=True) if isinstance(Radii, list) or isinstance(Radii, np.ndarray): drhodr = _ArrayWrapper.zeros_like(Radii) ct._lib.drho_nfw_dr_at_R_arr(Radii.cast(), len(Radii), Mass, conc, delta, Omega_m, drhodr.cast()) return drhodr.finish() else: return ct._lib.drho_nfw_dr_at_R(Radii, Mass, conc, delta, Omega_m)
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()
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()
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))
def G_at_sigma(sigma, d=1.97, e=1.0, f=0.51, g=1.228): """Tinker et al. 2008 appendix C multiplicity funciton G(sigma) as a function of sigma. 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: sigma (float or array like): RMS variance of the matter density field. 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 G(sigma). """ sigma = _ArrayWrapper(sigma, 'sigma') G = _ArrayWrapper.zeros_like(sigma) cluster_toolkit._lib.G_at_sigma_arr(sigma.cast(), len(sigma), d, e, f, g, G.cast()) return G.finish()
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()
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)