Skip to content

Background

Computes the square of the scale-factor-dependent term \(E(a)\) in the Hubble parameter.

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., matter density, curvature, radiation density).

required
a Union[float, ndarray]

Scale factor. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

Square of the scaling of the Hubble constant as a function of the scale factor. Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The Hubble parameter at scale factor \(a\) is given by:

\[ H^2(a) = E^2(a) H_0^2 \]

where \(E^2(a)\) is obtained through Friedmann's Equation (see Percival (2005)):

\[ E^2(a) = \Omega_m a^{-3} + \Omega_k a^{-2} + \Omega_r a^{-4} + \Omega_{de} e^{f(a)} \]

Here, \(f(a)\) is the Dark Energy evolution parameter.

Source code in jax_cosmo/background.py
def Esqr(cosmo: Cosmology, a: Union[float, np.ndarray]) -> Union[float, np.ndarray]:
    r"""
    Computes the square of the scale-factor-dependent term $E(a)$ in the Hubble parameter.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters
            (e.g., matter density, curvature, radiation density).
        a (Union[float, np.ndarray]): Scale factor. Can be a scalar or an array.

    Returns:
        Square of the scaling of the Hubble constant as a function of the scale factor. Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The Hubble parameter at scale factor $a$ is given by:

        $$
        H^2(a) = E^2(a) H_0^2
        $$

        where $E^2(a)$ is obtained through Friedmann's Equation (see [Percival (2005)](https://arxiv.org/pdf/astro-ph/0508156)):

        $$
        E^2(a) = \Omega_m a^{-3} + \Omega_k a^{-2} +  \Omega_r a^{-4} + \Omega_{de} e^{f(a)}
        $$

        Here, $f(a)$ is the Dark Energy evolution parameter.
    """
    return (
        cosmo.Omega_m * np.power(a, -3)
        + cosmo.Omega_k * np.power(a, -2)
        + cosmo.Omega_r * np.power(a, -4)
        + cosmo.Omega_de * np.exp(f_de(cosmo, a))
    )

Computes the Dark Energy equation of state parameter using the Linder parametrization.

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological parameters structure containing w0 and wa.

required
a Union[float, ndarray]

Scale factor. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

The Dark Energy equation of state parameter at the specified scale factor. Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The Linder parametrization Linder (2003) for the Dark Energy equation of state \(p = w \rho\) is given by:

\(w(a) = w_0 + w_a (1 - a)\)

Source code in jax_cosmo/background.py
def w(cosmo: Cosmology, a: Union[float, np.ndarray]) -> Union[float, np.ndarray]:
    r"""
    Computes the Dark Energy equation of state parameter using the Linder parametrization.

    Args:
        cosmo (Cosmology): Cosmological parameters structure containing `w0` and `wa`.
        a (Union[float, jnp.ndarray]): Scale factor. Can be a scalar or an array.

    Returns:
        The Dark Energy equation of state parameter at the specified scale factor. Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The Linder parametrization [Linder (2003)](https://arxiv.org/abs/astro-ph/0208512)
        for the Dark Energy equation of state $p = w \rho$ is given by:

        $w(a) = w_0 + w_a (1 - a)$
    """
    return cosmo.w0 + (1.0 - a) * cosmo.wa

Computes the evolution parameter for the Dark Energy density.

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological parameters structure containing w0 and wa.

required
a Union[float, ndarray]

Scale factor. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

The evolution parameter of the Dark Energy density as a function of the scale factor. Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

For a given parametrization of the Dark Energy equation of state, the scaling of the Dark Energy density with time can be written as:

\[ \rho_{de}(a) = \rho_{de}(a=1) e^{f(a)} \]

See Percival (2005) and note the difference in the exponent base in the parametrizations where \(f(a)\) is computed as:

\[ f(a) = -3 \int_0^{\ln(a)} [1 + w(a')] \, d \ln(a') \]

In the case of Linder's parametrization for the Dark Energy equation of state, \(f(a)\) becomes:

\[ f(a) = -3 (1 + w_0 + w_a) \ln(a) + 3 w_a (a - 1) \]
Source code in jax_cosmo/background.py
def f_de(cosmo: Cosmology, a: Union[float, np.ndarray]) -> Union[float, np.ndarray]:
    r"""Computes the evolution parameter for the Dark Energy density.

    Args:
        cosmo (Cosmology): Cosmological parameters structure containing `w0` and `wa`.
        a (Union[float, np.ndarray]): Scale factor. Can be a scalar or an array.

    Returns:
        The evolution parameter of the Dark Energy density as a function of the scale factor. Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        For a given parametrization of the Dark Energy equation of state, the scaling of the
        Dark Energy density with time can be written as:

        $$
        \rho_{de}(a) = \rho_{de}(a=1) e^{f(a)}
        $$

        See [Percival (2005)](https://arxiv.org/pdf/astro-ph/0508156) and note the difference in
        the exponent base in the parametrizations where $f(a)$ is computed as:

        $$
        f(a) = -3 \int_0^{\ln(a)} [1 + w(a')] \, d \ln(a')
        $$

        In the case of Linder's parametrization for the Dark Energy equation of state, $f(a)$ becomes:

        $$
        f(a) = -3 (1 + w_0 + w_a) \ln(a) + 3 w_a (a - 1)
        $$
    """
    return -3.0 * (1.0 + cosmo.w0 + cosmo.wa) * np.log(a) + 3.0 * cosmo.wa * (a - 1.0)

Computes the Hubble parameter \(H(a)\) at a given scale factor \(a\).

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., matter density, curvature, radiation density).

required
a Union[float, ndarray]

Scale factor. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

Hubble parameter at the requested scale factor \(a\) in units of [km/s/(Mpc/h)]. Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The Hubble parameter is calculated as:

\[ H(a) = H_0 \sqrt{E^2(a)} \]

where \(H_0\) is the Hubble constant in [km/s/(Mpc/h)] and \(E^2(a)\) is derived from Friedmann's Equation.

Source code in jax_cosmo/background.py
def H(cosmo: Cosmology, a: Union[float, np.ndarray]) -> Union[float, np.ndarray]:
    r"""
    Computes the Hubble parameter $H(a)$ at a given scale factor $a$.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters
            (e.g., matter density, curvature, radiation density).
        a (Union[float, np.ndarray]): Scale factor. Can be a scalar or an array.

    Returns:
        Hubble parameter at the requested scale factor $a$ in units of [km/s/(Mpc/h)]. Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The Hubble parameter is calculated as:

        $$
        H(a) = H_0 \sqrt{E^2(a)}
        $$

        where $H_0$ is the Hubble constant in [km/s/(Mpc/h)] and $E^2(a)$ is derived from Friedmann's Equation.
    """
    return const.H0 * np.sqrt(Esqr(cosmo, a))

Computes the non-relativistic matter density \(\Omega_m(a)\) at a given scale factor \(a\).

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., matter density, curvature).

required
a Union[float, ndarray]

Scale factor. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

Non-relativistic matter density at the requested scale factor \(a\). Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The evolution of matter density \(\Omega_m(a)\) is given by:

\[ \Omega_m(a) = \frac{\Omega_m a^{-3}}{E^2(a)} \]

where \(\Omega_m\) is the present-day matter density parameter, and \(E^2(a)\) is derived from Friedmann's Equation. For more details, see Equation 6 in Percival (2005).

Source code in jax_cosmo/background.py
def Omega_m_a(
    cosmo: Cosmology, a: Union[float, np.ndarray]
) -> Union[float, np.ndarray]:
    r"""
    Computes the non-relativistic matter density $\Omega_m(a)$ at a given scale factor $a$.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters
            (e.g., matter density, curvature).
        a (Union[float, np.ndarray]): Scale factor. Can be a scalar or an array.

    Returns:
        Non-relativistic matter density at the requested scale factor $a$. Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The evolution of matter density $\Omega_m(a)$ is given by:

        $$
        \Omega_m(a) = \frac{\Omega_m a^{-3}}{E^2(a)}
        $$

        where $\Omega_m$ is the present-day matter density parameter, and $E^2(a)$ is derived from Friedmann's Equation.
        For more details, see Equation 6 in [Percival (2005)](https://arxiv.org/pdf/astro-ph/0508156).
    """
    return cosmo.Omega_m * np.power(a, -3) / Esqr(cosmo, a)

Computes the Dark Energy density \(\Omega_{de}(a)\) at a given scale factor \(a\).

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., Dark Energy density, matter density).

required
a Union[float, ndarray]

Scale factor. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

Dark Energy density at the requested scale factor \(a\). Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The evolution of the Dark Energy density \(\Omega_{de}(a)\) is given by:

\[ \Omega_{de}(a) = \frac{\Omega_{de} e^{f(a)}}{E^2(a)} \]

where \(\Omega_{de}\) is the present-day Dark Energy density parameter, \(E^2(a)\) is derived from Friedmann's Equation, and \(f(a)\) is the Dark Energy evolution parameter.

For more details, see Equation 6 in Percival (2005).

Source code in jax_cosmo/background.py
def Omega_de_a(
    cosmo: Cosmology, a: Union[float, np.ndarray]
) -> Union[float, np.ndarray]:
    r"""
    Computes the Dark Energy density $\Omega_{de}(a)$ at a given scale factor $a$.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters
            (e.g., Dark Energy density, matter density).
        a (Union[float, np.ndarray]): Scale factor. Can be a scalar or an array.

    Returns:
        Dark Energy density at the requested scale factor $a$. Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The evolution of the Dark Energy density $\Omega_{de}(a)$ is given by:

        $$
        \Omega_{de}(a) = \frac{\Omega_{de} e^{f(a)}}{E^2(a)}
        $$

        where $\Omega_{de}$ is the present-day Dark Energy density parameter,
        $E^2(a)$ is derived from Friedmann's Equation, and $f(a)$ is the Dark Energy evolution parameter.

        For more details, see Equation 6 in [Percival (2005)](https://arxiv.org/pdf/astro-ph/0508156).
    """
    return cosmo.Omega_de * np.exp(f_de(cosmo, a)) / Esqr(cosmo, a)

Computes the radial comoving distance \(\chi(a)\) at a given scale factor \(a\).

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., Hubble constant, matter density, Dark Energy density).

required
a Union[float, ndarray]

Scale factor. Can be a scalar or an array.

required
log10_amin float

Logarithm (base 10) of the minimum scale factor to consider. Default is -4, which corresponds to very high redshift.

-4
steps int

Number of integration steps for computing the radial comoving distance. Default is 512.

512

Returns:

Type Description
Union[float, ndarray]

Radial comoving distance \(\chi(a)\) corresponding to the specified scale factor \(a\). Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

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

\[ \chi(a) = R_H \int_a^1 \frac{da^\prime}{{a^\prime}^2 E(a^\prime)} \]

where \(R_H\) is the Hubble radius, and \(E(a)\) is the function dependent on cosmological parameters (calculated from Friedmann's Equation).

Source code in jax_cosmo/background.py
def radial_comoving_distance(
    cosmo: Cosmology,
    a: Union[float, np.ndarray],
    log10_amin: float = -4,
    steps: int = 512,
) -> Union[float, np.ndarray]:
    r"""
    Computes the radial comoving distance $\chi(a)$ at a given scale factor $a$.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters
            (e.g., Hubble constant, matter density, Dark Energy density).
        a (Union[float, np.ndarray]): Scale factor. Can be a scalar or an array.
        log10_amin (float, optional): Logarithm (base 10) of the minimum scale factor to consider.
            Default is -4, which corresponds to very high redshift.
        steps (int, optional): Number of integration steps for computing the radial comoving distance.
            Default is 512.

    Returns:
        Radial comoving distance $\chi(a)$ corresponding to the specified scale factor $a$. Returns a scalar if the input is a scalar, or an array if the input is an array.

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

        $$
        \chi(a) = R_H \int_a^1 \frac{da^\prime}{{a^\prime}^2 E(a^\prime)}
        $$

        where $R_H$ is the Hubble radius, and $E(a)$ is the function dependent on cosmological parameters
        (calculated from Friedmann's Equation).

    """
    # 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)

Computes the derivative of the radial comoving distance with respect to the scale factor.

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., Hubble constant, matter density, Dark Energy density).

required
a Union[float, ndarray]

Scale factor or an array of scale factors to compute the derivative. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

Derivative of the radial comoving distance with respect to the scale factor at the specified scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The expression for the derivative of the radial comoving distance with respect to the scale factor is:

\[ \frac{d \chi}{da}(a) = \frac{R_H}{a^2 E(a)} \]

where \(R_H\) is the Hubble radius, \(a\) is the scale factor, and \(E(a)\) is the function derived from Friedmann's Equation.

Source code in jax_cosmo/background.py
def dchioverda(
    cosmo: Cosmology, a: Union[float, np.ndarray]
) -> Union[float, np.ndarray]:
    r"""
    Computes the derivative of the radial comoving distance with respect to the scale factor.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters
            (e.g., Hubble constant, matter density, Dark Energy density).
        a (Union[float, np.ndarray]): Scale factor or an array of scale factors to compute the derivative.
            Can be a scalar or an array.

    Returns:
        Derivative of the radial comoving distance with respect to the scale factor at the specified scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The expression for the derivative of the radial comoving distance with respect to the scale factor is:

        $$
        \frac{d \chi}{da}(a) = \frac{R_H}{a^2 E(a)}
        $$

        where $R_H$ is the Hubble radius, $a$ is the scale factor, and $E(a)$ is the function derived from Friedmann's Equation.
    """
    return const.rh / (a**2 * np.sqrt(Esqr(cosmo, a)))

Computes the transverse comoving distance for a given cosmological model and scale factor.

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., Hubble constant, matter density, curvature).

required
a Union[float, ndarray]

Scale factor or an array of scale factors to compute the transverse comoving distance. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

Transverse comoving distance corresponding to the specified scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The transverse comoving distance depends on the curvature of the universe and is related to the radial comoving distance (\(\chi(a)\)) through the following piecewise formula:

\[ f_k(a) = \left\lbrace \begin{matrix} R_H \frac{1}{\sqrt{\Omega_k}} \sinh(\sqrt{|\Omega_k|} \chi(a) R_H) & \text{for } \Omega_k > 0 \\ \chi(a) & \text{for } \Omega_k = 0 \\ R_H \frac{1}{\sqrt{\Omega_k}} \sin(\sqrt{|\Omega_k|} \chi(a) R_H) & \text{for } \Omega_k < 0 \end{matrix} \right. \]

where: - \(R_H\) is the Hubble radius. - \(\Omega_k\) is the curvature parameter. - \(\chi(a)\) is the radial comoving distance at the given scale factor \(a\).

Source code in jax_cosmo/background.py
def transverse_comoving_distance(
    cosmo: Cosmology, a: Union[float, np.ndarray]
) -> Union[float, np.ndarray]:
    r"""
    Computes the transverse comoving distance for a given cosmological model and scale factor.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters
            (e.g., Hubble constant, matter density, curvature).
        a (Union[float, np.ndarray]): Scale factor or an array of scale factors to compute the transverse comoving distance.
            Can be a scalar or an array.

    Returns:
        Transverse comoving distance corresponding to the specified scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The transverse comoving distance depends on the curvature of the universe and is related to
        the radial comoving distance ($\chi(a)$) through the following piecewise formula:

        $$
        f_k(a) = \left\lbrace
        \begin{matrix}
        R_H \frac{1}{\sqrt{\Omega_k}} \sinh(\sqrt{|\Omega_k|} \chi(a) R_H) & \text{for } \Omega_k > 0 \\
        \chi(a) & \text{for } \Omega_k = 0 \\
        R_H \frac{1}{\sqrt{\Omega_k}} \sin(\sqrt{|\Omega_k|} \chi(a) R_H) & \text{for } \Omega_k < 0
        \end{matrix}
        \right.
        $$

        where:
        - $R_H$ is the Hubble radius.
        - $\Omega_k$ is the curvature parameter.
        - $\chi(a)$ is the radial comoving distance at the given scale factor $a$.
    """
    index = cosmo.k + 1

    def open_universe(chi):
        return const.rh / cosmo.sqrtk * np.sinh(cosmo.sqrtk * chi / const.rh)

    def flat_universe(chi):
        return chi

    def close_universe(chi):
        return const.rh / cosmo.sqrtk * np.sin(cosmo.sqrtk * chi / const.rh)

    branches = (open_universe, flat_universe, close_universe)

    chi = radial_comoving_distance(cosmo, a)

    return lax.switch(cosmo.k + 1, branches, chi)

Computes the angular diameter distance for a given cosmological model and scale factor.

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., Hubble constant, matter density, curvature).

required
a Union[float, ndarray]

Scale factor or an array of scale factors to compute the angular diameter distance. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

Angular diameter distance corresponding to the specified scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The angular diameter distance is expressed in terms of the transverse comoving distance as:

\[ d_A(a) = a f_k(a) \]

where:

  • \(a\) is the scale factor.

  • \(f_k(a)\) is the transverse comoving distance at the given scale factor \(a\), which depends on the curvature of the universe.

Source code in jax_cosmo/background.py
def angular_diameter_distance(
    cosmo: Cosmology, a: Union[float, np.ndarray]
) -> Union[float, np.ndarray]:
    r"""
    Computes the angular diameter distance for a given cosmological model and scale factor.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters
            (e.g., Hubble constant, matter density, curvature).
        a (Union[float, np.ndarray]): Scale factor or an array of scale factors to compute the angular diameter distance.
            Can be a scalar or an array.

    Returns:
        Angular diameter distance corresponding to the specified scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The angular diameter distance is expressed in terms of the transverse comoving distance as:

        $$
        d_A(a) = a f_k(a)
        $$

        where:

        - $a$ is the scale factor.

        - $f_k(a)$ is the transverse comoving distance at the given scale factor $a$,
          which depends on the curvature of the universe.
    """
    return a * transverse_comoving_distance(cosmo, a)

Computes the linear growth factor \(D(a)\) at a given scale factor, normalized such that \(D(a=1) = 1\).

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmology object containing relevant parameters (e.g., matter density, Hubble constant, growth rate parameters).

required
a Union[float, ndarray]

Scale factor or an array of scale factors to compute the growth factor at. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

Growth factor computed at the requested scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The computation of the growth factor depends on the cosmological model and its parameters. If the \(\gamma\) parameter is defined in the cosmology model, the growth factor is computed assuming the \(f = \Omega^\gamma\) growth rate. Otherwise, the usual ordinary differential equation (ODE) for growth will be solved to compute the growth factor.

Source code in jax_cosmo/background.py
def growth_factor(
    cosmo: Cosmology, a: Union[float, np.ndarray]
) -> Union[float, np.ndarray]:
    r"""
    Computes the linear growth factor $D(a)$ at a given scale factor,
    normalized such that $D(a=1) = 1$.

    Args:
        cosmo (Cosmology): Cosmology object containing relevant parameters
            (e.g., matter density, Hubble constant, growth rate parameters).
        a (Union[float, np.ndarray]): Scale factor or an array of scale factors
            to compute the growth factor at. Can be a scalar or an array.

    Returns:
        Growth factor computed at the requested scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The computation of the growth factor depends on the cosmological model and its parameters.
        If the $\gamma$ parameter is defined in the cosmology model, the growth factor is computed
        assuming the $f = \Omega^\gamma$ growth rate. Otherwise, the usual ordinary differential equation
        (ODE) for growth will be solved to compute the growth factor.
    """

    if cosmo._flags["gamma_growth"]:
        return _growth_factor_gamma(cosmo, a)
    else:
        return _growth_factor_ODE(cosmo, a)

Computes the growth rate \(dD/d\ln a\) at a given scale factor.

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmology object containing relevant parameters (e.g., matter density, Hubble constant, growth rate parameters).

required
a Union[float, ndarray]

Scale factor or an array of scale factors to compute the growth rate at. Can be a scalar or an array.

required

Returns:

Type Description
Union[float, ndarray]

Growth rate computed at the requested scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The computation of the growth rate depends on the cosmological model and its parameters. If the \(\gamma\) parameter is defined in the cosmology model, the growth rate is computed assuming the \(f = \Omega^\gamma\) growth rate model. Otherwise, the usual ordinary differential equation (ODE) for growth will be solved to compute the growth rate.

The LCDM approximation to the growth rate \(f_{\gamma}(a)\) is given by:

\[ f_{\gamma}(a) = \Omega_m^{\gamma}(a) \]

where \(\gamma\) in LCDM is approximately given by \(\gamma \approx 0.55\).

For more details, see Equation 32 in 2019:Euclid Preparation VII (2019).

Source code in jax_cosmo/background.py
def growth_rate(
    cosmo: Cosmology, a: Union[float, np.ndarray]
) -> Union[float, np.ndarray]:
    r"""
    Computes the growth rate $dD/d\ln a$ at a given scale factor.

    Args:
        cosmo (Cosmology): Cosmology object containing relevant parameters
            (e.g., matter density, Hubble constant, growth rate parameters).
        a (Union[float, np.ndarray]): Scale factor or an array of scale factors
            to compute the growth rate at. Can be a scalar or an array.

    Returns:
        Growth rate computed at the requested scale factor(s). Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The computation of the growth rate depends on the cosmological model and its parameters.
        If the $\gamma$ parameter is defined in the cosmology model, the growth rate is computed
        assuming the $f = \Omega^\gamma$ growth rate model. Otherwise, the usual ordinary differential
        equation (ODE) for growth will be solved to compute the growth rate.

        The LCDM approximation to the growth rate $f_{\gamma}(a)$ is given by:

        $$
        f_{\gamma}(a) = \Omega_m^{\gamma}(a)
        $$

        where $\gamma$ in LCDM is approximately given by $\gamma \approx 0.55$.

        For more details, see Equation 32 in [2019:Euclid Preparation VII (2019)](https://arxiv.org/abs/1910.09273).
    """
    if cosmo._flags["gamma_growth"]:
        return _growth_rate_gamma(cosmo, a)
    else:
        return _growth_rate_ODE(cosmo, a)

Computes the luminosity distance for a given cosmological model and scale factor.

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., Hubble constant, matter density, Dark Energy density).

required
a Union[float, ndarray]

Scale factor of the Universe (inverse of 1 + redshift). Can be a scalar or an array.

required
log10_amin float

Logarithm (base 10) of the minimum scale factor to consider. Default is -4, which corresponds to very high redshift.

-4
steps int

Number of integration steps for computing the radial comoving distance. Default is 512.

512

Returns:

Type Description
Union[float, ndarray]

Luminosity distance in units of Mpc/h (or physical distance divided by the reduced Hubble constant). Returns a scalar if the input is a scalar, or an array if the input is an array.

Notes

The luminosity distance is computed by integrating the radial comoving distance and then applying the formula for luminosity distance. It is a measure of the distance to an object based on its luminosity.

The formula for luminosity distance is typically given by:

\[ D_L(a) = (1 + z) \cdot \chi(a) \]

where \(z = \frac{1}{a} - 1\) is the redshift, and \(\chi(a)\) is the radial comoving distance.

Source code in jax_cosmo/background.py
def luminosity_distance(
    cosmo: Cosmology,
    a: Union[float, np.ndarray],
    log10_amin: float = -4,
    steps: int = 512,
) -> Union[float, np.ndarray]:
    r"""
    Computes the luminosity distance for a given cosmological model and scale factor.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters
            (e.g., Hubble constant, matter density, Dark Energy density).
        a (Union[float, np.ndarray]): Scale factor of the Universe (inverse of 1 + redshift).
            Can be a scalar or an array.
        log10_amin (float, optional): Logarithm (base 10) of the minimum scale factor to consider.
            Default is -4, which corresponds to very high redshift.
        steps (int, optional): Number of integration steps for computing the radial comoving distance.
            Default is 512.

    Returns:
        Luminosity distance in units of Mpc/h (or physical distance divided by the reduced Hubble constant). Returns a scalar if the input is a scalar, or an array if the input is an array.

    Notes:
        The luminosity distance is computed by integrating the radial comoving distance and then applying the
        formula for luminosity distance. It is a measure of the distance to an object based on its luminosity.

        The formula for luminosity distance is typically given by:

        $$
        D_L(a) = (1 + z) \cdot \chi(a)
        $$

        where $z = \frac{1}{a} - 1$ is the redshift, and $\chi(a)$ is the radial comoving distance.
    """
    comoving_radial = radial_comoving_distance(cosmo, a, log10_amin, steps) / cosmo.h
    return comoving_radial / a

Computes the distance modulus, which quantifies the difference between the apparent and absolute magnitudes of an astronomical object.

Parameters:

Name Type Description Default
cosmo Cosmology

Cosmological model object containing relevant parameters (e.g., Hubble constant, matter density).

required
a float

Scale factor of the Universe (inverse of 1 + redshift).

required
log10_amin float

Logarithm (base 10) of the minimum scale factor to consider. Defaults to -4, corresponding to very high redshift.

-4
steps int

Number of integration steps for computing the radial comoving distance. Defaults to 512.

512

Returns:

Type Description
float

Distance modulus in magnitudes, which quantifies the difference between the apparent and absolute magnitudes of an object.

Notes

The distance modulus is calculated using the luminosity distance as:

\[ \mu = 5 \log_{10}(d_L \cdot 10) + 20 \]

where \(d_L\) is the luminosity distance in megaparsecs.

Source code in jax_cosmo/background.py
def distance_modulus(
    cosmo: Cosmology,
    a: float,
    log10_amin: float = -4,
    steps: int = 512,
) -> float:
    r"""
    Computes the distance modulus, which quantifies the difference between the apparent and absolute magnitudes
    of an astronomical object.

    Args:
        cosmo (Cosmology): Cosmological model object containing relevant parameters (e.g., Hubble constant, matter density).
        a (float): Scale factor of the Universe (inverse of 1 + redshift).
        log10_amin (float, optional): Logarithm (base 10) of the minimum scale factor to consider.
            Defaults to -4, corresponding to very high redshift.
        steps (int, optional): Number of integration steps for computing the radial comoving distance.
            Defaults to 512.

    Returns:
        Distance modulus in magnitudes, which quantifies the difference between the apparent and absolute magnitudes of an object.

    Notes:
        The distance modulus is calculated using the luminosity distance as:

        $$
        \mu = 5 \log_{10}(d_L \cdot 10) + 20
        $$

        where $d_L$ is the luminosity distance in megaparsecs.
    """
    lum_dist = luminosity_distance(cosmo, a, log10_amin, steps)
    return 5.0 * np.log10(lum_dist * 10) + 20.0