gwforge.GWForge.cosmology

Attributes

Classes

FlatwCDM

Flat dark-energy background with analytic parameter derivatives.

Functions

astropy_cosmology([name, H0, Om0, Ode0, Tcmb0, Ob0])

Resolve a GWForge cosmology specification to an astropy cosmology.

differential_comoving_volume(cosmology, redshift)

Full-sky dV_c/dz in Mpc^3 for either cosmology flavour.

luminosity_distance(cosmology, redshift)

Luminosity distance in Mpc for either cosmology flavour.

Module Contents

gwforge.GWForge.cosmology.SPEED_OF_LIGHT[source]
gwforge.GWForge.cosmology.QUADRATURE_ORDER = 64[source]
gwforge.GWForge.cosmology.NEWTON_ITERATIONS = 6[source]
gwforge.GWForge.cosmology._GUESS_NODES[source]
gwforge.GWForge.cosmology.COSMOLOGY_PARAMETERS = ('H0', 'Om0', 'w0')[source]
gwforge.GWForge.cosmology.astropy_cosmology(name='Planck18', H0=None, Om0=None, Ode0=None, Tcmb0=2.725, Ob0=None)[source]

Resolve a GWForge cosmology specification to an astropy cosmology.

Setting Tcmb0 = 0 removes radiation and massive neutrinos, which makes the result identical to FlatwCDM(H0, Om0, w0=-1) when Ode0 = 1 - Om0.

Parameters:
  • name (str) – An astropy.cosmology realization name, or anything else (e.g. "custom") to request an explicit LambdaCDM.

  • H0 (float or None) – Hubble constant in km/s/Mpc. Required if name is not a realization.

  • Om0 (float or None) – Present-day matter and dark-energy density parameters.

  • Ode0 (float or None) – Present-day matter and dark-energy density parameters.

  • Tcmb0 (float) – CMB temperature in K. 0 disables radiation and neutrinos.

  • Ob0 (float or None) – Baryon density parameter.

Return type:

astropy.cosmology.FLRW

Raises:

ValueError – If name is not a realization and the explicit parameters are incomplete.

class gwforge.GWForge.cosmology.FlatwCDM(H0=67.66, Om0=0.3111, w0=-1.0)[source]

Flat dark-energy background with analytic parameter derivatives.

\[E(z)^2 = \Omega_{m,0}(1 + z)^3 + (1 - \Omega_{m,0})(1 + z)^{3(1 + w_0)}\]

Usage

>>> cosmology = FlatwCDM(H0=67.66, Om0=0.3111)
>>> cosmology.luminosity_distance(1.0)            # Mpc
>>> cosmology.derivatives(1.0)["Om0"]["luminosity_distance"]
H0[source]

Hubble constant, km/s/Mpc.

Type:

float

Om0[source]

Present-day matter density parameter.

Type:

float

w0[source]

Dark-energy equation of state. -1 is flat LCDM.

Type:

float

hubble_distance[source]

\(D_H = c / H_0\), Mpc.

Type:

float

H0[source]
Om0[source]
w0[source]
hubble_distance[source]
__repr__()[source]
classmethod from_astropy(cosmology, w0=-1.0, fold_neutrinos=True)[source]

Build a FlatwCDM matching an astropy cosmology.

astropy realizations carry radiation and massive neutrinos, which this two-component background does not have. fold_neutrinos adds Onu0 to Om0, treating neutrinos as cold matter – a good approximation at the redshifts gravitational-wave catalogues reach, and the convention this module documents its residuals against.

Parameters:
  • cosmology (astropy.cosmology.FLRW)

  • w0 (float) – Equation of state to give the result.

  • fold_neutrinos (bool) – Add Onu0 to Om0.

Return type:

FlatwCDM

to_astropy()[source]

The exactly equivalent astropy cosmology (no radiation, no neutrinos).

Return type:

astropy.cosmology.FlatLambdaCDM or astropy.cosmology.FlatwCDM

efunc(redshift)[source]

\(E(z) = H(z) / H_0\).

_efunc_squared(redshift)[source]
defunc_dz(redshift)[source]

\(dE/dz\).

Carries the dark-energy term. The LCDM expression \(1.5\,\Omega_{m,0}(1+z)^2 / E\) is the \(w_0 = -1\) special case only, and using it under wCDM is wrong by 26% at \(w_0 = -0.8\).

_quadrature_nodes(redshift)[source]

Gauss-Legendre nodes and half-width for [0, z], broadcast over z.

Returns (sample_redshifts, half) with shapes (..., order) and (..., 1), so the integral of f is (half * (weights * f).sum(-1)).

comoving_distance(redshift)[source]

\(D_C(z) = D_H \int_0^z dz'/E(z')\), Mpc.

luminosity_distance(redshift)[source]

\(d_L = (1 + z) D_C(z)\), Mpc.

ddL_dz(redshift)[source]

\(dd_L/dz = D_C(z) + (1 + z) D_H / E(z)\), Mpc.

d2dL_dz2(redshift)[source]

\(d^2 d_L/dz^2 = 2 D_H/E - (1 + z) D_H E'/E^2\), Mpc.

differential_comoving_volume(redshift)[source]

Full-sky \(dV_c/dz = 4\pi D_C^2 D_H / E\), Mpc^3.

Note the \(4\pi\): astropy’s method of the same name is per steradian.

redshift_of_distance(distance)[source]

Invert \(d_L(z)\), by table-seeded Newton on the exact derivative.

Parameters:

distance (array_like) – Luminosity distance in Mpc.

Return type:

numpy.ndarray

_dinv_efunc(redshift)[source]

d(1/E)/dLambda for each cosmology parameter, as a dict of arrays.

These are the closed-form integrands that make derivatives() exact: the same Gauss-Legendre weights that build \(D_C\) also build \(\partial D_C/\partial\Lambda\).

_defunc(redshift)[source]

dE/dLambda at fixed z, as a dict of arrays.

derivatives(redshift, parameters=COSMOLOGY_PARAMETERS)[source]

Analytic derivatives of the background quantities at fixed z.

Parameters:
Returns:

{parameter: {"comoving_distance": ..., "luminosity_distance": ..., "ddL_dz": ..., "differential_comoving_volume": ...}}, every entry an array shaped like redshift.

Return type:

dict

Notes

H0 enters only through \(D_H = c/H_0\), because \(E(z)\) is dimensionless and carries no \(H_0\). Hence \(\partial_{H_0} D_C = -D_C/H_0\), \(\partial_{H_0}(dV_c/dz) = -3 (dV_c/dz)/H_0\) and \(\partial_{H_0}(dd_L/dz) = -(dd_L/dz)/H_0\) – the \(-3/H_0 + 1/H_0 = -2/H_0\) that the spectral-siren measure term reduces to.

dredshift_dparameter(redshift, parameters=COSMOLOGY_PARAMETERS)[source]

dz/dLambda at fixed luminosity distance.

Implicit differentiation of \(d_L(z;\Lambda) = \mathrm{const}\):

\[\frac{\partial z}{\partial\Lambda} = -\left(\frac{\partial d_L}{\partial\Lambda}\right)_{\!z} \Big/ \frac{d d_L}{d z}.\]

This is the chain that carries cosmology into the spectral-siren score: a trial cosmology moves the redshift assigned to a measured distance, which moves the source-frame masses and the merger-rate shape.

Parameters:
  • redshift (array_like) – Redshift at the fiducial cosmology.

  • parameters (sequence of str)

Returns:

{parameter: array}.

Return type:

dict

parameters()[source]

The cosmology parameters as a plain dict.

gwforge.GWForge.cosmology.differential_comoving_volume(cosmology, redshift)[source]

Full-sky dV_c/dz in Mpc^3 for either cosmology flavour.

astropy’s differential_comoving_volume is per steradian and carries units; FlatwCDM’s is already full-sky and unitless. Population code wants one number either way, so it goes through here.

Parameters:
  • cosmology (FlatwCDM or astropy.cosmology.FLRW)

  • redshift (array_like)

Return type:

numpy.ndarray

gwforge.GWForge.cosmology.luminosity_distance(cosmology, redshift)[source]

Luminosity distance in Mpc for either cosmology flavour.

Parameters:
  • cosmology (FlatwCDM or astropy.cosmology.FLRW)

  • redshift (array_like)

Return type:

numpy.ndarray