コード例 #1
0
ファイル: background.py プロジェクト: minaskar/jax_cosmo
def _growth_factor_gamma(cosmo, a, log10_amin=-3, steps=128):
    r""" Computes growth factor by integrating the growth rate provided by the
    \gamma parametrization. Normalized such that D( a=1) =1

    Parameters
    ----------
    a: array_like
      Scale factor

    amin: float
      Mininum scale factor, default 1e-3

    Returns
    -------
    D:  ndarray, or float if input scalar
        Growth factor computed at requested scale factor

    """
    # Check if growth has already been computed, if not, compute it
    if not "background.growth_factor" in cosmo._workspace.keys():
        # Compute tabulated array
        atab = np.logspace(log10_amin, 0.0, steps)

        def integrand(y, loga):
            xa = np.exp(loga)
            return _growth_rate_gamma(cosmo, xa)

        gtab = np.exp(odeint(integrand, np.log(atab[0]), np.log(atab)))
        gtab = gtab / gtab[-1]  # Normalize to a=1.
        cache = {"a": atab, "g": gtab}
        cosmo._workspace["background.growth_factor"] = cache
    else:
        cache = cosmo._workspace["background.growth_factor"]
    return np.clip(interp(a, cache["a"], cache["g"]), 0.0, 1.0)
コード例 #2
0
    def R_nl(a):
        def int_sigma(logk):
            k = np.exp(logk)
            y = np.outer(k, r)
            pk = linear_matter_power(cosmo, k, transfer_fn=transfer_fn)
            g = bkgrd.growth_factor(cosmo, np.atleast_1d(a))
            return (
                np.expand_dims(pk * k ** 3, axis=1)
                * np.exp(-(y ** 2))
                / (2.0 * np.pi ** 2)
                * g ** 2
            )

        sigma = simps(int_sigma, np.log(1e-4), np.log(1e4), 256)
        root = interp(np.atleast_1d(1.0), sigma, r)
        return root
コード例 #3
0
ファイル: background.py プロジェクト: minaskar/jax_cosmo
def radial_comoving_distance(cosmo, a, log10_amin=-3, steps=256):
    r"""Radial comoving distance in [Mpc/h] for a given scale factor.

    Parameters
    ----------
    a : array_like
        Scale factor

    Returns
    -------
    chi : ndarray, or float if input scalar
        Radial comoving distance corresponding to the specified scale
        factor.

    Notes
    -----
    The radial comoving distance is computed by performing the following
    integration:

    .. math::

        \chi(a) =  R_H \int_a^1 \frac{da^\prime}{{a^\prime}^2 E(a^\prime)}
    """
    # Check if distances have already been computed
    if not "background.radial_comoving_distance" in cosmo._workspace.keys():
        # Compute tabulated array
        atab = np.logspace(log10_amin, 0.0, steps)

        def dchioverdlna(y, x):
            xa = np.exp(x)
            return dchioverda(cosmo, xa) * xa

        chitab = odeint(dchioverdlna, 0.0, np.log(atab))
        # np.clip(- 3000*np.log(atab), 0, 10000)#odeint(dchioverdlna, 0., np.log(atab), cosmo)
        chitab = chitab[-1] - chitab

        cache = {"a": atab, "chi": chitab}
        cosmo._workspace["background.radial_comoving_distance"] = cache
    else:
        cache = cosmo._workspace["background.radial_comoving_distance"]

    a = np.atleast_1d(a)
    # Return the results as an interpolation of the table
    return np.clip(interp(a, cache["a"], cache["chi"]), 0.0)
コード例 #4
0
def growth_factor(cosmo, a, log10_amin=-3, steps=100, eps=1e-4):
    """ Compute Growth factor at a given scale factor, normalised such
  that G(a=1) = 1.

  Parameters
  ----------
  a: array_like
    Scale factor

  amin: float
    Mininum scale factor, default 1e-3

  Returns
  -------
  G:  ndarray, or float if input scalar
      Growth factor computed at requested scale factor
  """
    # Check if growth has already been computed
    if not 'background.growth_factor' in cosmo._workspace.keys():
        # Compute tabulated array
        atab = np.logspace(log10_amin, 0., steps)

        def D_derivs(y, x, cosmo):
            q = (2.0 - 0.5 *
                 (Omega_m_a(cosmo, x) +
                  (1.0 + 3.0 * w(cosmo, x)) * Omega_de_a(cosmo, x))) / x
            r = 1.5 * Omega_m_a(cosmo, x) / x / x
            return [y[1], -q * y[1] + r * y[0]]

        y0 = [atab[0], 1.0]
        y1, y2 = odeint(D_derivs, y0, atab, cosmo)

        gtab = y1 / y1[-1]

        cache = {'a': atab, 'g': gtab}
        cosmo._workspace['background.growth_factor'] = cache
    else:
        cache = cosmo._workspace['background.growth_factor']

    a = np.clip(np.atleast_1d(a), 10.**log10_amin, 1.0 - eps)
    return np.clip(interp(a, cache['a'], cache['g']), 0., 1.0)
コード例 #5
0
ファイル: background.py プロジェクト: minaskar/jax_cosmo
def _growth_factor_ODE(cosmo, a, log10_amin=-3, steps=128, eps=1e-4):
    """ Compute linear growth factor D(a) at a given scale factor,
    normalised such that D(a=1) = 1.

    Parameters
    ----------
    a: array_like
      Scale factor

    amin: float
      Mininum scale factor, default 1e-3

    Returns
    -------
    D:  ndarray, or float if input scalar
        Growth factor computed at requested scale factor
    """
    # Check if growth has already been computed
    if not "background.growth_factor" in cosmo._workspace.keys():
        # Compute tabulated array
        atab = np.logspace(log10_amin, 0.0, steps)

        def D_derivs(y, x):
            q = (2.0 - 0.5 *
                 (Omega_m_a(cosmo, x) +
                  (1.0 + 3.0 * w(cosmo, x)) * Omega_de_a(cosmo, x))) / x
            r = 1.5 * Omega_m_a(cosmo, x) / x / x
            return np.array([y[1], -q * y[1] + r * y[0]])

        y0 = np.array([atab[0], 1.0])
        y = odeint(D_derivs, y0, atab)
        y1 = y[:, 0]
        gtab = y1 / y1[-1]
        # To transform from dD/da to dlnD/dlna: dlnD/dlna = a / D dD/da
        ftab = y[:, 1] / y1[-1] * atab / gtab

        cache = {"a": atab, "g": gtab, "f": ftab}
        cosmo._workspace["background.growth_factor"] = cache
    else:
        cache = cosmo._workspace["background.growth_factor"]
    return np.clip(interp(a, cache["a"], cache["g"]), 0.0, 1.0)
コード例 #6
0
ファイル: background.py プロジェクト: minaskar/jax_cosmo
def _growth_rate_ODE(cosmo, a):
    """ Compute growth rate dD/dlna at a given scale factor by solving the linear
    growth ODE.

    Parameters
    ----------
    cosmo: `Cosmology`
      Cosmology object

    a: array_like
      Scale factor

    Returns
    -------
    f:  ndarray, or float if input scalar
        Growth rate computed at requested scale factor
    """
    # Check if growth has already been computed, if not, compute it
    if not "background.growth_factor" in cosmo._workspace.keys():
        _growth_factor_ODE(cosmo, np.atleast_1d(1.0))
    cache = cosmo._workspace["background.growth_factor"]
    return interp(a, cache["a"], cache["f"])
コード例 #7
0
def a_of_chi(cosmo, chi):
    r""" Computes the scale factor for corresponding (array) of radial comoving
  distance by reverse linear interpolation.

  Parameters:
  -----------
  cosmo: Cosmology
    Cosmological parameters

  chi: array-like
    radial comoving distance to query.

  Returns:
  --------
  a : array-like
    Scale factors corresponding to requested distances
  """
    # Check if distances have already been computed, force computation otherwise
    if not 'background.radial_comoving_distance' in cosmo._workspace.keys():
        radial_comoving_distance(cosmo, 1.0)
    cache = cosmo._workspace['background.radial_comoving_distance']
    chi = np.atleast_1d(chi)
    return interp(chi, cache['chi'], cache['a'])