Public Methods

The following methods are part of our publicly exported API.

Temperatures

Cosmology.T_cmbFunction
T_cmb([u::Unitful.Unitlike,] c::AbstractCosmology)
T_cmb([u::Unitful.Unitlike,] c::AbstractCosmology, z)
T_cmb([u::Unitful.Unitlike,] z, Tcmb0)

Return the temperature of the CMB at redshift z, in Kelvin. Will convert to compatible unit u if provided.

\[\text{T}_\text{CMB}(z) = \text{T}_\text{CMB,0} \times \left( 1+z \right)\]

Examples

julia> T_cmb(Cosmology.Planck18) ≈ 2.7255 * Unitful.K
true

julia> T_cmb(Cosmology.Planck18, 1.0) ≈ 5.451 * Unitful.K
true

julia> T_cmb(Unitful.°C, Cosmology.Planck18, 1.0) ≈ -267.69899999999996 * Unitful.°C
true

julia> T_cmb(1.0, 2.7255) ≈ 5.451 * Unitful.K
true

julia> T_cmb(1.0, 2.7255 * Unitful.K) ≈ 5.451 * Unitful.K
true

julia> T_cmb(Unitful.°C, 1.0, 2.7255 * Unitful.K) ≈ -267.69899999999996 * Unitful.°C
true
source
Cosmology.T_nuFunction
T_nu([u::Unitful.Unitlike,] c::AbstractCosmology [,z::Number])
T_nu(Tcmb0::Number [,z::Number])
T_nu(Tcmb0::u.Temperature [,z::Number])

Return the neutrino temperature of the cosmology at redshift z in Kelvin. If z is not provided, will return neutrino temperature at z=0. Will convert to compatible unit u if provided.

\[\begin{aligned} \text{T}_{\nu,0} &= \frac{4}{11}^{\left(1/3\right)} \times \text{T}_\text{CMB,0} \newline \text{T}_\nu(z) &= \text{T}_{\nu,0} \times \left( 1+z \right) \end{aligned}\]

See, e.g., Equation 3.1.20 on page 154 of Weinberg's "Cosmology" for an explanation of the prefactor.

Examples

julia> T_nu(2.7255) ≈ 1.9453688391750839 * Unitful.K
true

julia> T_nu(Cosmology.Planck18) ≈ 1.9453688391750839 * Unitful.K
true

julia> T_nu(2.7255, 1) ≈ 3.8907376783501677 * Unitful.K
true

julia> T_nu(2.7255 * Unitful.K, 1) ≈ 3.8907376783501677 * Unitful.K
true

julia> T_nu(Cosmology.Planck18) ≈ 1.9453688391750839 * Unitful.K
true

julia> T_nu(Cosmology.Planck18, 1) ≈ 3.8907376783501677 * Unitful.K
true
source

Hubble Factors

Cosmology.EFunction
E(c::AbstractCosmology, z::Real)
E(z,h,OmegaM,OmegaK,OmegaL,OmegaG,Tcmb0,m_nu,Neff,w0=-1,wa=0)

Return the Hubble parameter as a function of redshift, in units of H₀.

\[E(z) \equiv \frac{H(z)}{H_0} = \frac{H(z)}{h} \ \frac{1}{100 \ \text{km} \ \text{s}^{-1} \ \text{Mpc}^{-1}}\]

See also a2E, H.

Examples

julia> E(Cosmology.Planck18,1.0)
1.7828937335017068
source
Cosmology.HFunction
H(c::AbstractCosmology, z::Real)

Return the Hubble parameter as a function of redshift, in km / s / Mpc. From the Friedmann equation,

\[H^2 = \left( \frac{\dot{a}}{a} \right) = \frac{8 \pi G \rho}{3} - \frac{kc^2}{a^2}\]

where a is the cosmological scale factor, $\dot{a}$ is the time derivative of a, G is Newton's gravitational constant, c is the speed of light, $\rho$ is a mass density, and k is the curvature parameter. k is typically -1, 0, or 1; k=-1 corresponds to an open Universe (forever expanding), k=0 corresponds to a "flat" Universe with ρ==ρ_c, and k=1 corresponds to a closed Universe (eventual contraction). See also Ω_k.

Examples

julia> H(Cosmology.Planck18,1.0) ≈ 120.63059000872548 * Unitful.km / UnitfulAstro.Mpc / Unitful.s
true
source
Cosmology.hubble_timeFunction
hubble_time(c::AbstractCosmology, z::Real)

Return $\frac{1}{\text{H}\left(z\right)}$ in Gyr.

Examples

julia> hubble_time(Cosmology.Planck18, 1.0) ≈ 8.105673872689037 * Unitful.Gyr
true
source
Cosmology.hubble_distFunction
hubble_dist(c::AbstractCosmology, z::Real)

Return the speed of light times the Hubble time at redshift z in Mpc.

\[ D(z) = \frac{c}{H(z)}\]

Examples

julia> hubble_dist(Cosmology.Planck18,1.0) ≈ 2485.21090693758 * UnitfulAstro.Mpc
true
source

Lengths and Volumes

Cosmology.comoving_radial_distFunction
comoving_radial_dist([u::Unitlike,] c::AbstractCosmology, [z₁,] z₂; kws...)

Calculate the comoving radial distance (sometimes also called comoving line-of-sight distance) in Mpc at redshift z₂ as seen by an observer at z₁. Redshift z₁ defaults to 0 if omitted. Will convert to compatible unit u if provided. kws are integration options passed to QuadGK.quadgk.

\[\begin{aligned} D_R(z_1,z_2) = \frac{c}{H_0} \int_{z_1}^{z_2} \frac{1}{E(z)} \ dz = \frac{c}{H_0} \int_{a(z_2)}^{a(z_1)} \frac{1}{E(a^{\prime}) \, a^{\prime \, 2}} \ da^{\prime} \end{aligned}\]

Examples

julia> comoving_radial_dist(Cosmology.Planck18, 1.0) ≈ 3395.6344711515626 * UnitfulAstro.Mpc
true

julia> comoving_radial_dist(Cosmology.Planck18, 1.0, 2.0) ≈ 1912.5544127348157 * UnitfulAstro.Mpc
true

julia> comoving_radial_dist(UnitfulAstro.Gpc, Cosmology.Planck18, 1.0, 2.0) ≈ 1.9125544127348157 * UnitfulAstro.Gpc
true
source
Cosmology.comoving_transverse_distFunction
comoving_transverse_dist(c::AbstractCosmology, z₁, z₂ = nothing; kws...)

Returns the comoving transverse distance between two points with an angular separation of 1 radian at redshift z₂ as measured by an observer at redshift z₁. This is the same as the comoving distance if Ω_k is zero (as in the current concordance ΛCDM model). Will convert to compatible unit u if provided. kws are integration options passed to quadgk.

\[D_T(z_1,z_2) = \begin{cases} \frac{c}{H_0 \ \sqrt{\Omega_{k,0}}} \ \text{sinh} \left( \frac{H_0 \ \sqrt{\Omega_{k,0}}}{c} \ D_R(z_1,z_2) \right) \ &\forall \ \Omega_k > 0 \newline D_R(z_1,z_2) \ &\forall \ \Omega_k = 0 \newline \frac{c}{H_0 \ \sqrt{-\Omega_{k,0}}} \ \text{sin} \left( \frac{H_0 \ \sqrt{-\Omega_{k,0}}}{c} \ D_R(z_1,z_2) \right) \ &\forall \ \Omega_k < 0 \newline \end{cases}\]

where $D_R(z_1,z_2)$ is the comoving radial distance.

Examples

julia> comoving_transverse_dist(Cosmology.Planck18, 1.0) == comoving_radial_dist(Cosmology.Planck18, 1.0)
true

julia> comoving_transverse_dist(cosmology(OmegaK=0.1), 1.0) ≈ 3331.2531218753124 * UnitfulAstro.Mpc
true
source
Cosmology.angular_diameter_distFunction
angular_diameter_dist([u::Unitlike,] c::AbstractCosmology, [z₁,] z₂; kws...)

Ratio of the proper transverse size in Mpc of an object at redshift z₂ to its angular size in radians, as seen by an observer at z₁. Redshift z₁ defaults to 0 if omitted. Will convert to compatible unit u if provided. kws are integration options passed to quadgk.

\[\begin{aligned} D_A(z_1,z_2) &= \frac{D_T(z_1, z_2)}{1+z_2} = D_T(z_1, z_2) \, a(z_2) \newline D_A(z) &= \frac{D_T(z)}{1+z} = D_T(z) \, a(z) \end{aligned}\]

where $D_T$ is the comoving transverse distance and a is the scale factor.

Examples

julia> angular_diameter_dist(Cosmology.Planck18, 1.0) ≈ 1697.8172355757813 * UnitfulAstro.Mpc
true

julia> angular_diameter_dist(Cosmology.Planck18, 1.0, 2.0) ≈ 637.5181375782719 * UnitfulAstro.Mpc
true

julia> angular_diameter_dist(UnitfulAstro.Gpc, Cosmology.Planck18, 1.0, 2.0) ≈ 0.6375181375782719 * UnitfulAstro.Gpc
true
source
Cosmology.luminosity_distFunction
luminosity_dist([u::Unitlike,] c::AbstractCosmology, z; kws...)

Bolometric luminosity distance in Mpc at redshift z. Will convert to compatible unit u if provided. kws... are integration options passed to QuadGK.quadgk.

\[D_L(z) = D_T(z) \times \left(1 + z\right) = \frac{D_T(z)}{a\left(z\right)}\]

where $D_T$ is the comoving transverse distance and a is the scale factor.

Examples

julia> luminosity_dist(Cosmology.Planck18, 1.0) ≈ 6791.268942303125 * UnitfulAstro.Mpc
true

julia> luminosity_dist(UnitfulAstro.Gpc, Cosmology.Planck18, 1.0) ≈ 6.791268942303125 * UnitfulAstro.Gpc
true
source
Cosmology.distmodFunction
distmod(c::AbstractCosmology, z; kws...)

Distance modulus in magnitudes at redshift z. kws... are integration options passed to QuadGK.quadgk.

\[\mu(z) = 5 \times \text{log}_{10} \left( D_L(z) \right) + 25\]

where $D_L(z)$ is the luminosity distance in units of Mpc.

Examples

julia> distmod(Cosmology.Planck18,1.0)
44.159754646918806
source
Cosmology.comoving_volumeFunction
comoving_volume([u::Unitlike,] c::AbstractCosmology, z; kws...)

Comoving volume in Gpc^3 at redshift z. Will convert to compatible unit u if provided. kws... are integration options passed to QuadGK.quadgk.

Examples

julia> comoving_volume(Cosmology.Planck18, 1.0) ≈ 164.00285577357855 * UnitfulAstro.Gpc^3
true

julia> comoving_volume(UnitfulAstro.Mpc^3, Cosmology.Planck18, 1.0) ≈ 1.6400285577357855e11 * UnitfulAstro.Mpc^3
true
source
Cosmology.comoving_volume_elementFunction
comoving_volume_element([u::Unitlike,] c::AbstractCosmology, z; kws...)

Comoving volume element in Gpc out to redshift z. Will convert to compatible unit u if provided. kws... are integration options passed to QuadGK.quadgk.

Examples

julia> comoving_volume_element(Cosmology.Planck18, 1.0) ≈ 28.655310479576467 * UnitfulAstro.Gpc^3
true

julia> comoving_volume_element(UnitfulAstro.Mpc^3, Cosmology.Planck18, 1.0) ≈ 2.8655310479576466e10 * UnitfulAstro.Mpc^3
true
source
Cosmology.sound_horizonFunction
sound_horizon(c::AbstractCosmology)

Return the sound horizon length (in Mpc), given by Equation 26 in Eisenstein & Hu 1998.

\[s = \frac{44.5 \, \text{log} \left( 9.83 / \Omega_0 / h^2 \right)}{ \sqrt{ 1 + 10 \, \left( \Omega_b \, h^2 \right)^{3/4} } } \ \text{Mpc}\]

Examples

julia> sound_horizon(Cosmology.Planck18) ≈ 150.10339082768203 * UnitfulAstro.Mpc
true
source

Times

Cosmology.ageFunction
age([u::Unitlike,] c::AbstractCosmology, z; kws...)

Return the age of the universe in Gyr at redshift z. Will convert to compatible unit u if provided. kws... are integration options passed to QuadGK.quadgk.

Examples

julia> age(Cosmology.Planck18, 0.0) ≈ 13.786885301987898 * Unitful.Gyr
true

julia> age(UnitfulAstro.Myr, Cosmology.Planck18, 0.0) ≈ 13786.885301987897 * Unitful.Myr
true
source
Cosmology.lookback_timeFunction
lookback_time([u::Unitlike,] c::AbstractCosmology, z; kws...)

Difference between age at redshift 0 and age at redshift z in Gyr. Will convert to compatible unit u if provided. kws... are integration options passed to QuadGK.quadgk.

Examples

julia> lookback_time(Cosmology.Planck18, 1.0) ≈ 7.935542002084356 * Unitful.Gyr
true

julia> lookback_time(UnitfulAstro.Myr, Cosmology.Planck18, 1.0) ≈ 7935.542002084356 * Unitful.Myr
true
source
Cosmology.matter_radiation_equalityFunction
matter_radiation_equality(c::AbstractCosmology)

Return the redshift of matter-radiation equality. This is computed as Equation 2 in Eisenstein and Hu 1998. I previously had a different formula but couldn't figure out where it came from.

Examples

julia> matter_radiation_equality(Cosmology.Planck18) ≈ 3413.1817608491015
true
source

Densities

Cosmology.ρ_cFunction
ρ_c([u::UnitLike,] c::AbstractCosmology, z)
ρ_c([u::UnitLike,] z, h, OmegaM, OmegaK, OmegaL, Tcmb0, m_nu, Neff, w0=-1, wa=0)
ρ_c(h::Number,E::Number)

The critical density of the Universe at redshift z, in g / cm^3. Will convert to compatible unit u if provided.

\[\begin{aligned} \rho_{0,c} &\equiv \frac{3 H_0^2}{8 \pi G} = 1.878 \times 10^{-29} \ h^2 \ \text{g/cm}^3 \newline \rho_{c}(z) &\equiv \frac{3 H(z)^2}{8 \pi G} = 1.878 \times 10^{-29} \ \left(E(z) \times h\right)^2 \ \text{g/cm}^3 \end{aligned}\]

where E is the Hubble factor in units of $H_0$. See, e.g., Equation 1.5.28 on page 57 of Weinberg's "Cosmology" for more information.

Examples

julia> ρ_c(Cosmology.Planck18, 0.0) ≈ 8.598814256619093e-30 * Unitful.g / Unitful.cm^3
true

julia> ρ_c(UnitfulAstro.Msun / UnitfulAstro.kpc^3, Cosmology.Planck18, 0.0) ≈ 127.05281539744222 * UnitfulAstro.Msun / UnitfulAstro.kpc^3
true

Notes

If you want the critical density with the dimensionless hubble constant h factored out (i.e., in units of [density * h^2] you need to divide this result by h^2.

source
Cosmology.ρ_mFunction
ρ_m([u::UnitLike,] c::AbstractCosmology, z)
ρ_m([u::UnitLike,] z, h, OmegaM)

The matter density of the universe at redshift z, in g / cm^3. Will convert to compatible unit u if provided.

\[\rho_m(z) = 1.878 \times 10^{-29} \ h^2 \ \Omega_{m,0} \ (1+z)^3 \ \text{g/cm}^3 \]

Examples

julia> ρ_m(Cosmology.Planck18, 0.0) ≈ 2.6627088227046682e-30 * Unitful.g / Unitful.cm^3
true

julia> ρ_m(UnitfulAstro.Msun / UnitfulAstro.kpc^3, Cosmology.Planck18, 0.0) ≈ 39.343174815971956 * UnitfulAstro.Msun / UnitfulAstro.kpc^3
true

Notes

If you want the critical density with the dimensionless hubble constant h factored out (i.e., in units of [density * h^2] you need to divide this result by h^2.

source
Cosmology.ρ_bFunction
ρ_b([u::UnitLike,] c::AbstractCosmology, z)
ρ_b([u::UnitLike,] z, h, OmegaB)

The baryon density of the universe at redshift z, in g / cm^3. Will convert to compatible unit u if provided.

\[\rho_b(z) = 1.878 \times 10^{-29} \ h^2 \ \Omega_{b,0} \ (1+z)^3 \ \text{g/cm}^3 \]

Examples

julia> ρ_b(Cosmology.Planck18, 0.0) ≈ 4.21083934146637e-31 * Unitful.g / Unitful.cm^3
true

julia> ρ_b(UnitfulAstro.Msun / UnitfulAstro.kpc^3, Cosmology.Planck18, 0.0) ≈ 6.221776370012746 * UnitfulAstro.Msun / UnitfulAstro.kpc^3
true

Notes

If you want the critical density with the dimensionless hubble constant h factored out (i.e., in units of [density * h^2] you need to divide this result by h^2.

source
Cosmology.ρ_dmFunction
ρ_dm([u::UnitLike,] c::AbstractCosmology, z)
ρ_dm([u::UnitLike,] z, h, OmegaDM)

The dark matter density of the universe at redshift z, in g / cm^3. Will convert to compatible unit u if provided.

\[\rho_{dm}(z) = 1.878 \times 10^{-29} \ h^2 \ \Omega_{dm,0} \ (1+z)^3 \ \text{g/cm}^3 \]

Examples

julia> ρ_dm(Cosmology.Planck18, 0.0) ≈ 2.2416248885580312e-30 * Unitful.g / Unitful.cm^3
true

julia> ρ_dm(UnitfulAstro.Msun / UnitfulAstro.kpc^3, Cosmology.Planck18, 0.0) ≈ 33.12139844595921 * UnitfulAstro.Msun / UnitfulAstro.kpc^3
true

Notes

If you want the critical density with the dimensionless hubble constant h factored out (i.e., in units of [density * h^2] you need to divide this result by h^2.

source
Cosmology.ρ_ΛFunction
ρ_Λ([u::UnitLike,] c::AbstractCosmology, z)
ρ_Λ([u::UnitLike,] z, h, Ω_Λ, w0=-1, wa=0)

The dark energy density of the universe at redshift z, in g / cm^3. Will convert to compatible unit u if provided. For a general dark energy equation of state $w(z)$,

\[\rho_\Lambda(z) = \rho_{\Lambda,0} \ \exp \left[ 3 \int_0^z \frac{1+w \left( z^\prime\right)}{1+z^\prime} \ dz^\prime \ \right]\]

For constant $w$, this reduces to

\[\rho_\Lambda(z) = 1.878 \times 10^{-29} \ h^2 \ \Omega_{\Lambda,0} \ \left(1+z\right)^{3\left(1+w\right)} \ \text{g/cm}^3 \]

and for a cosmological constant $w=-1$,

\[\rho_\Lambda(z) = 1.878 \times 10^{-29} \ h^2 \ \Omega_{\Lambda,0} \ \text{g/cm}^3 \]

See also de_density_scale.

Examples

julia> ρ_Λ(Cosmology.Planck18, 0.0) ≈ 5.923261432735804e-30 * Unitful.g / Unitful.cm^3
true

julia> ρ_Λ(UnitfulAstro.Msun / UnitfulAstro.kpc^3, Cosmology.Planck18, 0.0) ≈ 87.51986249556084 * UnitfulAstro.Msun / UnitfulAstro.kpc^3
true

julia> ρ_Λ(Cosmology.Planck18, 0.0) == ρ_Λ(Cosmology.Planck18, 1.0)
true

Notes

If you want the critical density with the dimensionless hubble constant h factored out (i.e., in units of [density * h^2] you need to divide this result by h^2.

source
Cosmology.ρ_γFunction
ρ_γ([u::UnitLike,] c::AbstractCosmology, z)
ρ_γ([u::UnitLike,] z, h, Ω_γ)

The photon matter density of the universe at redshift z, in g / cm^3. Will convert to compatible unit u if provided.

\[\rho_\gamma(z) = 1.878 \times 10^{-29} \ h^2 \ \Omega_{\gamma,0} \ (1+z)^4 \ \text{g/cm}^3 \]

Examples

julia> ρ_γ(Cosmology.Planck18, 0.0) ≈ 4.645092477570597e-34 * Unitful.g / Unitful.cm^3
true

julia> ρ_γ(UnitfulAstro.Msun / UnitfulAstro.kpc^3, Cosmology.Planck18, 0.0) ≈ 0.006863412319931541 * UnitfulAstro.Msun / UnitfulAstro.kpc^3
true

Notes

If you want the critical density with the dimensionless hubble constant h factored out (i.e., in units of [density * h^2] you need to divide this result by h^2.

source
Cosmology.ρ_νFunction
ρ_ν([u::UnitLike,] c::AbstractCosmology, z)
ρ_ν([u::UnitLike,] z, h, Tcmb0, Neff, m_nu, N_nu=Cosmology.n_nu(Neff))

The neutrino energy density of the universe at redshift z, in g / cm^3. Will convert to compatible unit u if provided.

\[\rho_\nu(z) = 1.878 \times 10^{-29} \ h^2 \ \Omega_{\nu,0} \ (1+z)^4 \ \text{g/cm}^3 \]

Examples

julia> ρ_ν(Cosmology.Planck18, 0.0) ≈ 1.2379491930863195e-32 * Unitful.g / Unitful.cm^3
true

julia> ρ_ν(UnitfulAstro.Msun / UnitfulAstro.kpc^3, Cosmology.Planck18, 0.0) ≈ 0.1829146735894845 * UnitfulAstro.Msun / UnitfulAstro.kpc^3
true

Notes

If you want the critical density with the dimensionless hubble constant h factored out (i.e., in units of [density * h^2] you need to divide this result by h^2.

source
Cosmology.ρ_rFunction
ρ_r([u::UnitLike,] c::AbstractCosmology, z)
ρ_r([u::UnitLike,] z, h, Tcmb0, Neff, m_nu, N_nu=Cosmology.n_nu(Neff))

The energy density of the universe in relativistic species at redshift z, in g / cm^3. Will convert to compatible unit u if provided.

\[\rho_r(z) = 1.878 \times 10^{-29} \ h^2 \ \Omega_{r,0} \ (1+z)^4 \ \text{g/cm}^3 \]

Examples

julia> ρ_r(Cosmology.Planck18, 0.0) ≈ 1.2844001178620257e-32 * Unitful.g / Unitful.cm^3
true

julia> ρ_r(UnitfulAstro.Msun / UnitfulAstro.kpc^3, Cosmology.Planck18, 0.0) ≈ 0.18977808590941606 * UnitfulAstro.Msun / UnitfulAstro.kpc^3
true

julia> ρ_r(Cosmology.Planck18, 0.0) ≈ ρ_γ(Cosmology.Planck18, 0.0) + ρ_ν(Cosmology.Planck18, 0.0)
true

Notes

If you want the critical density with the dimensionless hubble constant h factored out (i.e., in units of [density * h^2] you need to divide this result by h^2.

source
Cosmology.lagrangianRFunction
lagrangianR([u::UnitLike,] M::Union{Real,u.Mass}, c::AbstractCosmology, z::Real=0.0)

The Lagrangian radius (in Mpc) of a sphere of mass M (in solar masses) at redshift z; i.e. the radius of a sphere that would enclose the mass M given the mean density of the universe at redshift z.

\[R(z) = \left( \frac{3 M}{4π \ ρ_m(z)} \right)^{1/3}\]

Examples

julia> lagrangianR(10^12, Cosmology.Planck18, 0.0) == lagrangianR(10^12, Cosmology.Planck18) == lagrangianR(10^12 * UnitfulAstro.Msun, Cosmology.Planck18) ≈ 1.8239544820629736 * UnitfulAstro.Mpc
true

julia> lagrangianR(Unitful.m, 10^12, Cosmology.Planck18, 0.0) ≈ 5.628135454962416e22 * Unitful.m
true

Notes

If you want to provide M in units of Msun / h and get out R in units of Mpc / h, then you need to multiply the result by h^(2/3); i.e. R[Mpc/h] = lagrangianR(M[Msun/h], c, z) * h^(2/3).

source
Cosmology.lagrangianMFunction
lagrangianM([u::UnitLike,] R::Union{Number,u.Length}, c::AbstractCosmology, z::Number=0.0)

The Lagrangian mass of a sphere of radius R in Mpc at redshift z; i.e. the mass enclosed by a sphere of radius R at redshift z given the mean density of the universe at redshift z.

\[M(z) = \frac{4π}{3} R^3 ρ_m(z)\]

Examples

julia> lagrangianM(8.0, Cosmology.Planck18, 0.0) == lagrangianM(8.0, Cosmology.Planck18) == lagrangianM(8.0 * UnitfulAstro.Mpc, Cosmology.Planck18) ≈ 8.437775631070308e13 * UnitfulAstro.Msun
true

julia> lagrangianM(Unitful.kg, 8.0, Cosmology.Planck18, 0.0) ≈ 1.6777756351555676e44 * Unitful.kg
true

Notes

If you want to provide R in units of Mpc / h and get out M in units of Msun / h, then you need to divide the result by h^2; i.e. M[Msun/h] = lagrangianR(R[Mpc/h], c, z) / h^2.

source
Cosmology.Ω_mFunction
Ω_m(c::AbstractCosmology,z)
Ω_m(c::AbstractCosmology)
Ω_m(z,h,OmegaM,OmegaK,OmegaL,Tcmb0,m_nu,Neff,w0=-1,wa=0)

Density of matter at redshift z in units of the critical density. When called without a redshift, returns the z=0 value.

Examples

julia> Ω_m(Cosmology.Planck18)
0.30966

julia> Ω_m(Cosmology.Planck18, 1.0)
0.7793349973337195
source
Cosmology.Ω_bFunction
Ω_b(c::AbstractCosmology,z)
Ω_b(c::AbstractCosmology)
Ω_b(z,h,OmegaM,OmegaB,OmegaK,OmegaL,Tcmb0,m_nu,Neff,w0=-1,wa=0)

Density of baryons at redshift z in units of the critical density. When called without a redshift, returns the z=0 value.

Examples

julia> Ω_b(Cosmology.Planck18)
0.04897

julia> Ω_b(Cosmology.Planck18, 1.0)
0.1232449616335085
source
Cosmology.Ω_dmFunction
Ω_dm(c::AbstractCosmology,z)
Ω_dm(c::AbstractCosmology)
Ω_dm(z,h,OmegaM,OmegaB,OmegaK,OmegaL,Tcmb0,m_nu,Neff,w0=-1,wa=0)

Density of dark matter at redshift z in units of the critical density. When called without a redshift, returns the z=0 value.

Examples

julia> Ω_dm(Cosmology.Planck18)
0.26069

julia> Ω_dm(Cosmology.Planck18, 1.0)
0.6560900357002108
source
Cosmology.Ω_kFunction
Ω_k(c::AbstractCosmology,z)
Ω_k(c::AbstractCosmology)
Ω_k(z,h,OmegaM,OmegaK,OmegaL,Tcmb0,m_nu,Neff,w0=-1,wa=0)

Energy density of curvature at redshift z in units of the critical density. When called without a redshift, returns the z=0 value.

\[\Omega_k = -\frac{k}{H_0^2}\]

where k is the curvature parameter in the Friedmann equation. See Equations 1.5.19 and 1.5.40 on pages 56 and 60 in Weinberg's "Cosmology".

Examples

julia> Ω_k(Cosmology.Planck18) == Ω_k(Cosmology.Planck18, 1.0) == 0.0
true

julia> Ω_k( cosmology(OmegaK = 0.1 ), 1.0)
0.11498515039500401

julia> Ω_k( cosmology(OmegaK = -0.1 ), 1.0)
-0.13895112427920248
source
Cosmology.Ω_γFunction
Ω_γ(c::AbstractCosmology,z)
Ω_γ(c::AbstractCosmology)
Ω_γ(z,h,OmegaM,OmegaK,OmegaL,Tcmb0,m_nu,Neff,w0=-1,wa=0)

Energy density of photons at redshift z in units of the critical density. Calculated from T_cmb. When called without a redshift, returns the z=0 value.

Examples

julia> Ω_γ(Cosmology.Planck18) ≈ 5.4020151371393475e-5
true

julia> Ω_γ(Cosmology.Planck18, 10000.0) ≈ 0.44150560915009124
true
source
Cosmology.Ω_νFunction
Ω_ν(c::AbstractCosmology,z)
Ω_ν(z,h,OmegaM,OmegaK,OmegaL,Tcmb0,m_nu,Neff,w0=-1,wa=0)

Energy density in neutrinos at redshift z in units of the critical density. When called without a redshift, returns the z=0 value.

Examples

julia> Ω_ν(Cosmology.Planck18) ≈ 0.0014396743040860382
true

julia> Ω_ν(Cosmology.Planck18, 10000.0) ≈ 0.30543520244776484
true
source
Cosmology.Ω_rFunction
Ω_r(c::AbstractCosmology,z)
Ω_r(c::AbstractCosmology)
Ω_r(z,h,OmegaM,OmegaK,OmegaL,Tcmb0,m_nu,Neff,w0=-1,wa=0)

Energy density in radiation at redshift z in units of the critical density. Evaluated as Ω_γ(c,z) + Ω_ν(c,z); sum of photons and neutrinos. When called without a redshift, returns the z=0 value.

Examples

julia> Ω_r(Cosmology.Planck18) ≈ 0.0014936944554574316
true

julia> Ω_r(Cosmology.Planck18, 10000.0) ≈ 0.7469408115978561
true

julia> Ω_r(Cosmology.Planck18, 10000.0) == Ω_γ(Cosmology.Planck18, 10000.0) + Ω_ν(Cosmology.Planck18, 10000.0)
true
source
Cosmology.Ω_ΛFunction
Ω_Λ(c::AbstractCosmology,z)
Ω_Λ(c::AbstractCosmology)
Ω_Λ(z,h,OmegaM,OmegaK,OmegaL,Tcmb0,m_nu,Neff,w0=-1,wa=0)

Energy density in dark energy at redshift z in units of the critical density. When called without a redshift, returns the z=0 value.

Examples

julia> Ω_Λ(Cosmology.Planck18)
0.6888463055445425

julia> Ω_Λ(Cosmology.Planck18, 1.0)
0.21670623978512665
source
Cosmology.δcFunction
δc(c::AbstractCosmology, z::Real)
δc(z::Real, h, OmegaM, OmegaK, OmegaL, Tcmb0, m_nu, Neff, w0=-1, wa=0)

The linear overdensity threshold for halo collapse as calculated from the spherical top-hat collapse model. The canonical value for an Einstein-de-Sitter (EdS) cosmology is $3/5(3π/2)^{2/3} ≈ 1.686$ but there is a redshift dependence for non-EdS cosmologies. We adopt the fitting function from Nakamura & Suto 1997 (Equation C-28 in the ArXiv version), also given by Equation 56 in Chisari et al. 2019.

Examples

julia> δc(Cosmology.Planck18, 0.0) ≈ 1.675910191226453
true

julia> δc(Cosmology.Planck18, 10.0) ≈ 1.686388790734125
true

julia> δc(Cosmology.Planck18,10^10,0.0,1.0,1.5) ≈ 1.712312778883257
true
source
δc(c::AbstractCosmology, M::Union{Real,AbstractArray}, z::Real, mx::Real, gx::Real=1.5)

Return the linear overdensity threshold for collapse in warm dark matter cosmologies as formulated by Equations 7–10 in Benson 2013. M is the halo mass, z is the redshift of evaluation, mx is the mass of the WDM particle in keV, and gx is the effective degrees of freedom with 1.5 being the expected value for a fermionic spin-1/2 particle.

Examples

julia> δc(Cosmology.Planck18, 10^10, 0.0, 1.0, 1.5) ≈ 1.712312778883257
true
source

Equation Solving

Cosmology.z_at_valueFunction
z_at_value(c::AbstractCosmology, func::Function, fval; zmin=1e-8, zmax=1000.0, kws...)

Find the redshift z at which func(c,z) == fval for cosmology instance c. This uses a numerical root finder and searches between zmin and zmax. Additional kws... are passed through to Roots.find_zero.

Examples

julia> z_at_value(Cosmology.Planck18, scale_factor, 0.8) ≈ 0.25
true

julia> z_at_value(Cosmology.Planck18, distmod, 50.0) ≈ 9.5f0
true
Warning

Not all cosmological methods defined in this module are monotonic with redshift, such that there may not be a unique solution over the default zmin->zmax (e.g., angular_diameter_dist). In this case, you need to make sure that zmin and zmax properly bracket the solution you are looking for.

julia> z_at_value(Cosmology.Planck18, angular_diameter_dist, 1250.0; zmin=1e-5, zmax=2.5)
0.46668775101654764

julia> z_at_value(Cosmology.Planck18, angular_diameter_dist, 1250.0; zmin=2.5, zmax=10.0)
5.595635655898187
source

Miscellaneous

Cosmology.scale_factorFunction
scale_factor(z::Real)
scale_factor(c::AbstractCosmology, z::Real)

Calculate the scale factor at redshift z. The scale factor is defined as $a=\frac{1}{1+z}$. The method that takes a cosmology is for compatibility with z_at_value. The derivative with respect to z is available as ∇scale_factor.

Examples

julia> scale_factor(1.0)
0.5

julia> scale_factor(Cosmology.Planck18, 1.0)
0.5
source
Cosmology.∇scale_factorFunction
∇scale_factor(z::Real) or ∇scale_factor(c::AbstractCosmology, z::Real)

Calculate the derivative of the scale factor at redshift z with respect to z; $\frac{da}{dz} = -\frac{1}{\left(1+z\right)^2}$.

Examples

julia> ∇scale_factor(1.0)
-0.25

julia> ∇scale_factor(Cosmology.Planck18, 1.0)
-0.25
source