Cosmology
The Cosmology module controls the cosmological parameters and various derived quantities. We can initialize a cosmology using init_cosmology. For examples on how to use this module and various functions within it, see Basic: Example - 1.
Initialization
LensFactory.Cosmology.init_cosmology — Type
init_cosmology(H0::Real = 70.0,
w::Real = -1.0,
Omega_m0::Real = 0.3,
Omega_r0::Real = 0.0,
Omega_w0::Real = 0.7,
Omega_k0::Real = 1.0 - Omega_m0 - Omega_r0 - Omega_w0)A struct to initialize a cosmology with given parameters.
For typical cases, the user provides values of H0, Omega_m0, and Omega_w0 (and Omega_r0 if non-zero). For such a case, the default value of Omega_k0 ensures that the sum of density parameters is equal to 1 (i.e., $\Omega_{m0} + \Omega_{r0} + \Omega_{w0} + \Omega_{k0} = 1$). However, if the user provides all four density parameters, the value of Omega_k0 provided by the user will be used and the universe will not necessarily be spatially flat.
Arguments
H0::Real = 70.0: Hubble constant in ${\rm \mathbf{km/s/Mpc}}$.w::Real = -1.0: Dark energy equation of state parameter.Omega_m0::Real = 0.3: Matter density parameter.Omega_r0::Real = 0.0: Radiation density parameter.Omega_w0::Real = 0.7: Dark energy density parameter.Omega_k0::Real = 1.0 - Omega_m0 - Omega_r0 - Omega_w0: Curvature density parameter.
Returns
init_cosmology::AbstractCosmology: Cosmology object.
Basics
LensFactory.Cosmology.scale_factor — Function
scale_factor(z::Real) --> RealCalculate scale factor, $a$, for a given redshift $z$,
\[a = \frac{1}{1+z}.\]
Arguments
z: Redshift.
Returns
a: Scale factor.
LensFactory.Cosmology.Ez — Function
Ez(cosmology::AbstractCosmology, z::Real) --> RealCalculate dimensionless Hubble parameter $(E)$ at redshift, $z$,
\[E(z) = \sqrt{ Ω_{m0} (1+z)^3 + Ω_{r0} (1+z)^4 + Ω_{k0} (1+z)^2 + Ω_{w0} (1+z)^{3(1+w)} }.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
Ez: Dimensionless Hubble parameter.
LensFactory.Cosmology.hubble_parameter — Function
hubble_parameter(cosmology::AbstractCosmology, z::Real) --> RealCalculate Hubble parameter, $H(z)$, for a given redshift $z$,
\[H(z) = H_0 \: E(z).\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
Hz: Hubble parameter (in ${\rm \mathbf{km/s/Mpc}}$).
Time
LensFactory.Cosmology.hubble_time — Function
hubble_time(H0::Real) --> RealCalculate the Hubble time, $t_H$,
\[t_H = \frac{1}{H_0}.\]
Arguments
H0: Hubble constant (in ${\rm \mathbf{km/s/Mpc}}$).
Returns
tH: Hubble time in ${\rm \mathbf{Gyr}}$.
LensFactory.Cosmology.age — Function
age(cosmology::AbstractCosmology, z::Real) --> RealCalculate the age of the Universe, $t_{\rm age})$, at a given redshift $z$,
\[t_{\rm age}(z) = \int_z^\infty \frac{1}{(1+z')H(z')} dz'.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
t_age: Age of the Universe (in ${\rm \mathbf{Gyr}}$).
LensFactory.Cosmology.lookback_time — Function
lookback_time(cosmology::AbstractCosmology, z::Real) --> RealCalculate lookbak time $(t_L)$ to a given redshift $z$ in ${\rm \mathbf{Gyr}}$,
\[t_L(z) = \int_0^z \frac{1}{(1+z')H(z')} dz'.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
t_lookback: Lookback time (in ${\rm \mathbf{Gyr}}$).
Density parameters
LensFactory.Cosmology.rho_cz — Function
rho_cz(cosmology::AbstractCosmology, z::Real) --> RealCalculate the critical density $(\rho_c)$ of the Universe at redshift $z$ in given units,
\[\rho_c(z) = \frac{3 H^2(z)}{8 π {\rm G} }.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Keyword Arguments
unit = :kg_m3: Output units of the critical surface density.:kg_m3$\Rightarrow{\rm \mathbf{kg/m^3}}$:msun_pc3$\Rightarrow{\rm \mathbf{M_⊙/pc^3}}$
Returns
rho_c: Critical density of the Universe.
LensFactory.Cosmology.Omega_mz — Function
Omega_mz(cosmology::AbstractCosmology, z::Real) --> RealCalculate the dimensionless matter density parameter $(\Omega_{m})$ at redshift $z$,
\[Ω_{m}(z) = Ω_{m}(0) \: (1+z)^3 \left( \frac{H0}{H(z)} \right)^2.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
Omega_m: Dimensionless matter density parameter.
LensFactory.Cosmology.Omega_rz — Function
Omega_rz(cosmology::AbstractCosmology, z::Real) --> RealCalculate the dimensionless radiation density parameter $(\Omega_{r})$ at redshift $z$,
\[Ω_{r}(z) = Ω_{r}(0) \: (1+z)^4 \left( \frac{H_0}{H(z)} \right)^2.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
Omega_r: Dimensionless radiation density parameter.
LensFactory.Cosmology.Omega_wz — Function
Omega_wz(cosmology::AbstractCosmology, z::Real) --> RealCalculate the dimensionless dark energy density parameter $(\Omega_{w})$ at redshift $z$,
\[Ω_{w}(z) = Ω_{w0} (1+z)^{3(1+w)} \left( \frac{H_0}{H(z)} \right)^2.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
Omega_w: Dimensionless dark energy density parameter.
LensFactory.Cosmology.Omega_kz — Function
Omega_kz(cosmology::AbstractCosmology, z::Real) --> RealCalculate the dimensionless curvature density parameter $(\Omega_{k})$ at redshift $z$,
\[Ω_{k}(z) = Ω_{k0} (1+z)^2 \left( \frac{H_0}{H(z)} \right)^2.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
Omega_k: Dimensionless curvature density parameter.
Distances
LensFactory.Cosmology.hubble_distance — Function
hubble_distance(H0::Real) --> RealCalculate the Hubble distance (i.e., size of the observable Universe) $(D_H)$ in ${\rm \mathbf{meters}}$,
\[D_H = \frac{\rm c}{\rm H_0}.\]
Arguments
H0: Hubble constant in ${\rm \mathbf{km/s/Mpc}}$.
Returns
D_H: Hubble distance in ${\rm \mathbf{meters}}$.
LensFactory.Cosmology.comoving_distance_radial — Function
comoving_distance_radial(cosmo::AbstractCosmology, z1::Real, z2::Real) --> RealCalculate the comoving radial distance $(D_C)$ between $z_1$ and $z_2$ in ${\rm \mathbf{meters}}$. The formula is,
\[D_C = D_H \int_{z_1}^{z_2} \frac{dz'}{E(z')}.\]
Arguments
cosmology: Cosmology object.z1: First redshift.z2: Second redshift.
Returns
D_C: Comoving radial distance in ${\rm \mathbf{meters}}$.
LensFactory.Cosmology.comoving_distance_transverse — Function
comoving_distance_transverse(cosmo::AbstractCosmology, z1::Real, z2::Real) --> RealCalculate the comoving transverse distance $(D_M)$ between, $z_1$ and $z_2$ in ${\rm \mathbf{meters}}$,
\[D_M = \begin{cases} D_H \frac{1}{\sqrt{\Omega_k}} \sinh \left[ \sqrt{\Omega_k} \: D_C / D_H \right], & \text{if } \Omega_k > 0, \\ D_C, & \text{if } \Omega_k = 0, \\ D_H \frac{1}{\sqrt{|\Omega_k|}} \sin \left[ \sqrt{|\Omega_k|} \: D_C / D_H \right], & \text{if } \Omega_k < 0. \\ \end{cases}\]
Arguments
cosmology: Cosmology object.z1: First redshift.z2: Second redshift.
Returns
D_M: Comoving radial distance in ${\rm \mathbf{meters}}$.
LensFactory.Cosmology.luminosity_distance — Function
luminosity_distance(cosmology::AbstractCosmology, z::Real) --> RealCalculate the luminosity distance $(D_L)$ to redshift $z$ in ${\rm \mathbf{meters}}$,
\[D_L(z) = (1+z) D_M(z).\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
D_L: Luminosity distance in ${\rm \mathbf{meters}}$.
LensFactory.Cosmology.angular_diameter_distance — Function
angular_diameter_distance(cosmology::AbstractCosmology, z1::Real, z2::Real) --> RealCalculate the angular diameter distance $(D_A)$ between redshifts $z_1$ and $z_2$ in ${\rm \mathbf{meters}}$,
\[D_A(z_1, z_2) = \frac{D_M(z_1, z_2)}{1+z_2}.\]
Arguments
cosmology: Cosmology object.z1: First redshift.z2: Second redshift.
Returns
D_A: Angular diameter distance in ${\rm \mathbf{meters}}$.
LensFactory.Cosmology.distance_modulus — Function
distance_modulus(cosmo::AbstractCosmology, z::Real) --> RealCalculate the distance modulus $(\mu)$ to a given redshift $z$,
\[\mu = 5 \log\left( \frac{D_L}{\rm pc} \right) - 5.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
mu: Distance modulus.
LensFactory.Cosmology.angular_scale — Function
angular_scale(cosmology::AbstractCosmology, z::Real) --> RealCalculate the angular size in ${\rm \mathbf{Kpc}}$ for $1''$ on sky at redhsift, $z$,
\[d = 1'' \times \left( \frac{D_A}{\rm{kpc}} \right).\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
d: Angular size in ${\rm \mathbf{Kpc}}$.
LensFactory.Cosmology.zs2adis — Function
zs2adis(cosmology::AbstractCosmology, z_d::Real, zs::Real;
dC = nothing, atol = DIST_ATOL, rtol = DIST_RTOL) --> RealDistance ratio $a_{\rm dis} = D_{ds}/D_s = D_A(z_d, zs) / D_A(0, zs)$ — the forward map that adis2zs inverts. The $(1+z_s)$ factors cancel, so $a_{\rm dis} = D_M(z_d, zs) / D_M(0, zs)$, built from the radial comoving distances via $χ(z_d, zs) = χ(zs) - χ(z_d)$. Only two 1-D integrals are needed, and $χ(z_d)$ is constant for a fixed cosmology + lens redshift — pass it as dC (radial comoving distance to the lens, meters) to cut each call to a single integral. Valid for flat, open, and closed models and any w.
Arguments
cosmology: Cosmology object.z_d: Lens redshift.zs: Source redshift (must satisfyzs > z_d).
Keyword Arguments
dC = nothing: Precomputed radial comoving distance $χ(z_d)$ (meters).atol = DIST_ATOL,rtol = DIST_RTOL: Quadrature tolerances.
Returns
a_dis: Dimensionless distance ratio $D_{ds}/D_s$.
LensFactory.Cosmology.adis2zs — Function
adis2zs(cosmology::AbstractCosmology, z_d::Real, adis::Real;
max_iter::Int64 = 10000,
tol::Float64 = 1E-6) --> RealCalculate the source redshift ($z_s$) from the distance ratio ($a_{\rm dis}$), using Bi-section method.
Arguments
cosmology: Cosmology object.z_d: Lens redshift.adis: Distance ratio, $a_{\rm dis}$.
Keyword Arguments
max_iter = 10000: Maximum number of iterations.tol = 1E-6: Tolerance for the root finding algorithm.
Returns
z_s: Redshift of the source.
Volumes
LensFactory.Cosmology.comoving_volume_element — Function
comoving_volume_element(cosmology::AbstractCosmology, z::Real) --> RealCalculate the comving volume element $(dV_C)$ at redshift $z$,
\[dV_C = D_H \frac{D_M^2(z)}{E(z)}.\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
dV_C: Comving volume element in ${\rm \mathbf{Gpc^3}}$.
LensFactory.Cosmology.comoving_volume — Function
comoving_volume(cosmology::AbstractCosmology, z::Real) --> RealCalculate the total comving volume up to redshift $z$,
\[V_C = \begin{cases} \frac{4π}{2} \frac{D_H^3}{Ω_k} \left[ \frac{D_M}{D_H} \sqrt{1+Ω_k \left(\frac{D_M}{D_H}\right)^2} - \frac{1}{\sqrt{|Ω_k|}} {\rm arcsinh}\left( \sqrt{|Ω_k|} \frac{D_M}{D_H} \right) \right], & \text{if } Ω_k > 0, \\ \frac{4π}{3} D_M^3, & \text{if } Ω_k = 0, \\ \frac{4π}{2} \frac{D_H^3}{Ω_k} \left[ \frac{D_M}{D_H} \sqrt{1+Ω_k \left(\frac{D_M}{D_H}\right)^2} - \frac{1}{\sqrt{|Ω_k|}} \arcsin\left( \sqrt{|Ω_k|} \frac{D_M}{D_H} \right) \right], & \text{if } Ω_k < 0. \\ \end{cases}\]
Arguments
cosmology: Cosmology object.z: Redshift.
Returns
com_vol: Comving volume up to redshift $z$ (in ${\rm \mathbf{Gpc^3}}$).