phytorch.cosmology

Core abstract classes

class phytorch.cosmology.core.Cosmology

The abstract base class for all cosmologies.

__new__(**kwargs)
class phytorch.cosmology.core.FLRWDriver

An abstract class that defines basic dimensionless routines.

Subclasses must implement concrete calculation routines:

  • The dimensionless Hubble parameter \(E^2(z) \equiv (H(z) / H_0)\) in the _e2func method.

  • The (dimensionless) comoving distance

    \[\frac{\chi(z_1, z_2)}{cH_0^{-1}} = \int_{z_1}^{z_2} \frac{\mathrm{d}z}{E(z)}\]

    either in the comoving_distance_dimless_z1z2 or comoving_distance_dimless method.

  • The (dimensionless) lookback time

    \[\frac{t(z_1, z_2)}{H_0^{-1}} = \int_{z_1}^{z_2} \frac{\mathrm{d}z}{(z+1) E(z)}\]

    either in the lookback_time_dimless or age_dimless method.

  • The (dimensionless) absorption distance

    \[\frac{d_{\mathrm{abs}}(z_1, z_2)}{cH_0^{-1}} = \int_{z_1}^{z_2} \frac{(z+1)^2}{E(z)} \mathrm{d}z\]

    in the absorption_distance_dimless method.

Ok(z, *, O0_name='Ok0', power=2)

Relative effective curvature density at the given redshift.

Return type:

_TN

abstract _e2func(zp1)

Function that calculates the dimensionless Hubble parameter for the concrete cosmological model.

Must be overridden in subclasses. Note that the argument is \(z+1\).

Return type:

_TN

abs_distance_integrand(z)

Integrand of the (dimensionless) absorption distance:

\[\frac{H_0}{c} \frac{\mathrm{d}d_{\mathrm{abs}}}{\mathrm{d}z} = \frac{(z+1)^2}{E(z)}.\]
Return type:

_TN

abstract absorption_distance_dimless(z)

Dimensionless absorption_distance (in units of the hubble_distance).

Return type:

_TN

age_dimless(z)

Dimensionless age of the universe (in units of the hubble_time).

Return type:

_TN

angular_diameter_distance_dimless(z)

Dimensionless angular_diameter_distance (in units of the hubble_distance).

Return type:

_TN

angular_diameter_distance_dimless_z1z2(z1, z2)

Dimensionless angular_diameter_distance_z1z2 (in units of the hubble_distance).

comoving_distance_dimless(z)

Dimensionless comoving_distance (in units of the hubble_distance).

Return type:

_TN

comoving_distance_dimless_z1z2(z1, z2)

Dimensionless comoving_distance_z1z2 (in units of the hubble_distance).

Return type:

_TN

comoving_transverse_distance_dimless(z)

Dimensionless comoving_transverse_distance (in units of the hubble_distance).

Return type:

_TN

comoving_transverse_distance_dimless_z1z2(z1, z2)

Dimensionless comoving_transverse_distance_z1z2 (in units of the hubble_distance).

Return type:

_TN

comoving_volume_dimless(z, eps=1e-08)

Dimensionless comoving_volume (in units of the hubble_volume).

Return type:

_TN

differential_comoving_volume_dimless(z)

Dimensionless differential_comoving_volume (in units of the hubble_volume per steradian).

Return type:

_TN

e2func(z, zp1=None)

Dimensionless Hubble parameter squared at the given redshift (\(E^2(z) \equiv (H(z) / H_0)^2\)).

Return type:

_TN

efunc(z)

Dimensionless Hubble parameter at the given redshift.

Return type:

_TN

inv_efunc(z)

Inverse of the dimensionless Hubble parameter at the given redshift.

Return type:

_TN

lookback_time_dimless(z)

Dimensionless lookback_time (in units of the hubble_time).

Return type:

_TN

lookback_time_integrand(z)

Integrand of the (dimensionless) lookback time:

\[H_0 \frac{\mathrm{d}t}{\mathrm{d}z} = \frac{1}{(z+1) E(z)}.\]
Return type:

_TN

luminosity_distance_dimless(z)

Dimensionless luminosity_distance (in units of the hubble_distance).

Return type:

_TN

transform_curved(distance_dimless)

Transform (dimensionless) radial to transverse distance using curvature:

\[\frac{D_M}{cH_0^{-1}} = \frac{\chi}{cH_0^{-1}} \operatorname{sinc}\left(\mathrm{i} \sqrt{\Omega_{k0}} \frac{\chi}{cH_0^{-1}}\right).\]

The result is always well-defined and real since

\[\begin{split}\operatorname{sinc}\left(\mathrm{i} \sqrt{\Omega_{k0}} \frac{\chi}{cH_0^{-1}}\right) = \begin{cases} \operatorname{sinc}\left(\sqrt{\left|\Omega_{k0}\right|} \frac{\chi}{cH_0^{-1}}\right) & \text{for } \Omega_{k0} < 0, \\ 1 & \text{for } \Omega_{k0} = 0, \\ \operatorname{sinhc}\left(\sqrt{\left|\Omega_{k0}\right|} \frac{\chi}{cH_0^{-1}}\right) & \text{for } \Omega_{k0} > 0, \end{cases}\end{split}\]

where \(\operatorname{sinhc}(x) \equiv \sinh(x) / x\).

Notes

Note that the PyTorch definition of sinc is slightly modified: \(\operatorname{sinc}(x) \equiv \sin(\pi x) / (\pi x)\).

Return type:

_TN

Ok0: _TN = Parameter(default=<empty>)

Relative effective curvature density at the present time.

property isqrtOk0_pi: _TN

\(\mathrm{i} \sqrt{\Omega_{k0}} / \pi \in \mathbb{C}\)

property sqrtOk0: _TN

\(\sqrt{\Omega_{k0}} \in \mathbb{C}\)

class phytorch.cosmology.core.FLRW

The abstract base class for FLRW cosmologies.

Implements dimensionfull calculations on top of the dimensionless routines from FLRWDriver.

H(z)

Value of the Hubble parameter \(H(z)\) at the given redshift.

Return type:

unitful

abs_distance_integrand(z)

Integrand of the (dimensionless) absorption distance:

\[\frac{H_0}{c} \frac{\mathrm{d}d_{\mathrm{abs}}}{\mathrm{d}z} = \frac{(z+1)^2}{E(z)}.\]
Return type:

_TN

absorption_distance(z)

Absorption distance to the given redshift:

\[d_{\mathrm{abs}}(z) = \frac{c}{H_0} \int_{0}^{z} \frac{(z+1)^2}{E(z)} \mathrm{d}z.\]

Notes

For compatibility with AstroPy, the absorption_distance is returned as dimensionless instead of a quantity and is thus equivalent to absorption_distance_dimless.

Return type:

_TN

abstract absorption_distance_dimless(z)

Dimensionless absorption_distance (in units of the hubble_distance).

Return type:

_TN

age(z)

Age of the universe at the given redshift:

\[t(\infty) - t(z) = \frac{1}{H_0} \int_{z}^{\infty} \frac{\mathrm{d}z}{(z+1)E(z)}.\]
Return type:

unitful

age_dimless(z)

Dimensionless age of the universe (in units of the hubble_time).

Return type:

_TN

angular_diameter_distance(z)

Angular diameter / size distance to the given redshift:

\[D_A(z) = \frac{D_M(z)}{z+1}.\]
Return type:

unitful

angular_diameter_distance_dimless(z)

Dimensionless angular_diameter_distance (in units of the hubble_distance).

Return type:

_TN

angular_diameter_distance_dimless_z1z2(z1, z2)

Dimensionless angular_diameter_distance_z1z2 (in units of the hubble_distance).

angular_diameter_distance_z1z2(z1, z2)

Angular diameter / size distance between two given redshifts:

\[D_A(z_1, z_2) = \frac{D_M(z_1, z_2)}{z_2+1}.\]
Return type:

unitful

comoving_distance(z)

Comoving distance to the given redshift:

\[\chi(z) = \frac{c}{H_0} \int_{0}^{z} \frac{\mathrm{d}z}{E(z)}.\]
Return type:

unitful

comoving_distance_dimless(z)

Dimensionless comoving_distance (in units of the hubble_distance).

Return type:

_TN

comoving_distance_dimless_z1z2(z1, z2)

Dimensionless comoving_distance_z1z2 (in units of the hubble_distance).

Return type:

_TN

comoving_distance_z1z2(z1, z2)

Comoving distance between two given redshifts:

\[\chi(z_1, z_2) = \frac{c}{H_0} \int_{z_1}^{z_2} \frac{\mathrm{d}z}{E(z)}.\]
Return type:

unitful

comoving_transverse_distance(z)

Comoving transverse distance to the given redshift.

Refer to transform_curved.

Return type:

unitful

comoving_transverse_distance_dimless(z)

Dimensionless comoving_transverse_distance (in units of the hubble_distance).

Return type:

_TN

comoving_transverse_distance_dimless_z1z2(z1, z2)

Dimensionless comoving_transverse_distance_z1z2 (in units of the hubble_distance).

Return type:

_TN

comoving_transverse_distance_z1z2(z1, z2)

Comoving transverse distance between two given redshifts.

Refer to transform_curved.

Return type:

unitful

comoving_volume(z)

Comoving spherical volume to the given redshift:

\[V(z) = 8\pi \chi^3 \operatorname{csinc}\left(2 \mathrm{i} \sqrt{\Omega_{k0}} \frac{\chi}{cH_0^{-1}}\right),\]

where \(\operatorname{csinc(x)} \equiv (1 - \operatorname{sinc}(x)) / x^2\) (with the limit \(\operatorname{csinc(x)} \rightarrow 1/6\) as \(x \rightarrow 0\)), resulting from the integration of differential_comoving_volume.

Return type:

unitful

comoving_volume_dimless(z, eps=1e-08)

Dimensionless comoving_volume (in units of the hubble_volume).

Return type:

_TN

critical_density(z)

Critical density at the given redshift:

\[\rho_{\mathrm{cr}}(z) = \frac{3}{8\pi} \frac{H(z)^2}{G}.\]
Return type:

unitful

differential_comoving_volume(z)

Differential comoving volume at the given redshift:

\[\frac{\mathrm{d}V(z)}{\mathrm{d}\Omega \mathrm{d}z} = \frac{cH_0^{-1}}{E(z)} D_M^2(z),\]

where \(\mathrm{d}\Omega\) is an infinitesimal solid angle.

Return type:

unitful

differential_comoving_volume_dimless(z)

Dimensionless differential_comoving_volume (in units of the hubble_volume per steradian).

Return type:

_TN

distmod(z)

Distance modulus in magnitudes (unitless):

\[\mu(z) = 2.5 \log_{10}\left[\left(D_L / 10\,\mathrm{pc}\right)^2\right].\]

Note that this formulation allows negative luminosity distances 🙃

Return type:

_TN

e2func(z, zp1=None)

Dimensionless Hubble parameter squared at the given redshift (\(E^2(z) \equiv (H(z) / H_0)^2\)).

Return type:

_TN

efunc(z)

Dimensionless Hubble parameter at the given redshift.

Return type:

_TN

inv_efunc(z)

Inverse of the dimensionless Hubble parameter at the given redshift.

Return type:

_TN

lookback_distance(z)

Lookback distance (length that light traverses during lookback_time) to the given redshift.

Return type:

unitful

lookback_time(z)

Lookback time to the given redshift:

\[t(z) = \frac{1}{H_0} \int_{0}^{z} \frac{\mathrm{d}z}{(z+1)E(z)}.\]
Return type:

unitful

lookback_time_dimless(z)

Dimensionless lookback_time (in units of the hubble_time).

Return type:

_TN

lookback_time_integrand(z)

Integrand of the (dimensionless) lookback time:

\[H_0 \frac{\mathrm{d}t}{\mathrm{d}z} = \frac{1}{(z+1) E(z)}.\]
Return type:

_TN

luminosity_distance(z)

Luminosity distance to the given redshift:

\[D_L(z) = (z+1)^2 D_A(z) = (z+1) D_M(z).\]
Return type:

unitful

luminosity_distance_dimless(z)

Dimensionless luminosity_distance (in units of the hubble_distance).

Return type:

_TN

transform_curved(distance_dimless)

Transform (dimensionless) radial to transverse distance using curvature:

\[\frac{D_M}{cH_0^{-1}} = \frac{\chi}{cH_0^{-1}} \operatorname{sinc}\left(\mathrm{i} \sqrt{\Omega_{k0}} \frac{\chi}{cH_0^{-1}}\right).\]

The result is always well-defined and real since

\[\begin{split}\operatorname{sinc}\left(\mathrm{i} \sqrt{\Omega_{k0}} \frac{\chi}{cH_0^{-1}}\right) = \begin{cases} \operatorname{sinc}\left(\sqrt{\left|\Omega_{k0}\right|} \frac{\chi}{cH_0^{-1}}\right) & \text{for } \Omega_{k0} < 0, \\ 1 & \text{for } \Omega_{k0} = 0, \\ \operatorname{sinhc}\left(\sqrt{\left|\Omega_{k0}\right|} \frac{\chi}{cH_0^{-1}}\right) & \text{for } \Omega_{k0} > 0, \end{cases}\end{split}\]

where \(\operatorname{sinhc}(x) \equiv \sinh(x) / x\).

Notes

Note that the PyTorch definition of sinc is slightly modified: \(\operatorname{sinc}(x) \equiv \sin(\pi x) / (\pi x)\).

Return type:

_TN

H0: _GQuantity = Parameter(default=<Unit: 100 km s^(-1) Mpc^(-1)>)

The Hubble constant \(H_0 \equiv H(z=0)\).

property critical_density0: unitful

Critical density at the present time:

\[\rho_{\mathrm{cr}}(z=0) = \frac{3}{8\pi} \frac{H_0^2}{G}.\]
property hubble_distance: unitful

Hubble distance (“size of the universe”): \(cH_0^{-1}\).

property hubble_distance_in_10pc: _TN

Hubble distance in units of 10pc (unitless).

property hubble_time: unitful

Hubble time (“age of the universe”): \(H_0^{-1}\).

property hubble_volume: unitful

Hubble distance cubed.

property isqrtOk0_pi: _TN

\(\mathrm{i} \sqrt{\Omega_{k0}} / \pi \in \mathbb{C}\)

property sqrtOk0: _TN

\(\sqrt{\Omega_{k0}} \in \mathbb{C}\)

Special abstract classes

class phytorch.cosmology.special.decdm.BaseDECDM

A cosmology with cold dark matter (CDM) and abstract dark energy (DE).

Ob(z, *, O0_name='Ob0', power=3)

Relative density of baryonic matter at the given redshift.

Return type:

_TN

Ode(z, zp1=None)

Relative density of dark energy at the given redshift.

Return type:

_TN

Odm(z, *, O0_name='Odm0', power=3)

Relative density of non-baryonic matter at the given redshift.

Return type:

_TN

Om(z, *, O0_name='Om0', power=3)

Relative density of all nonrelativistic matter at the given redshift.

Return type:

_TN

Ob0: _TN = Parameter(default=0.0)

Relative density of baryonic matter at the present time.

property Ode0: _TN

Relative density of dark energy at the present time.

property Odm0: _TN

Relative density of non-baryonic matter at the present time.

Om0: _TN = Parameter(default=<empty>)

Relative density of all nonrelativistic matter at the present time.

class phytorch.cosmology.special.decdm.RadiationFLRWMixin

Abstract base class for FLRW cosmologies with radiation.

Or(z, *, O0_name='Or0', power=4)

Relative density of radiation (incl. relativistic matter) at the given redshift.

Notes

This is not the same as astropy.cosmology.FLRW.Ogamma when Neff is non-zero.

Return type:

_TN

Tcmb(z)

Temperature of the CMB (relativistic species) at the given redshift.

Return type:

unitful

Neff: _TN = Parameter(default=0.0)

Number of effective neutrino species.

Or0: _TN = Parameter(default=0.0)

Relative density of radiation (incl. relativistic matter) at the present time.

Notes

This is not the same as astropy.cosmology.FLRW.Ogamma0 when Neff is non-zero.

property Tcmb0: unitful

Temperature of the CMB (relativistic species) at the present time.

Concrete classes

class phytorch.cosmology.special.concrete.LambdaCDM

Dark energy from a cosmological constant \(\Lambda\), implying an equation of state

\[w(z) = w_0 = -1.\]
class phytorch.cosmology.special.concrete.LambdaCDMR

LambdaCDM with radiation.

class phytorch.cosmology.special.concrete.w0waCDM

Cosmology with a dark energy evolving linearly with scale factor:

\[w(z) = w_0 + w_a (1-a) = w_0 + w_a \left(1 - \frac{1}{z+1}\right).\]
class phytorch.cosmology.special.concrete.w0waCDMR

w0waCDM with radiation.

class phytorch.cosmology.special.concrete.w0wzCDM

Cosmology with a dark energy evolving linearly with redshift:

\[w(z) = w_0 + w_z z.\]
class phytorch.cosmology.special.concrete.w0wzCDMR

w0wzCDM with radiation.

class phytorch.cosmology.special.concrete.wCDM

Cosmology with a dark energy with constant equation of state:

\[w(z) = w_0 = \mathrm{const}.\]
class phytorch.cosmology.special.concrete.wCDMR

wCDM with radiation.

class phytorch.cosmology.special.concrete.wpwaCDM

Cosmology with a pivoting dark energy equation of state:

\[w(z) = w_p + w_a (a_p-a) = w_p + w_a \left(\frac{1}{z_p+1} - \frac{1}{z+1}\right).\]
class phytorch.cosmology.special.concrete.wpwaCDMR

wpwaCDM with radiation.

Drivers