uvex_transients.utils.cosmology.resolve_cosmological_distances#

uvex_transients.utils.cosmology.resolve_cosmological_distances(redshift: float | NDArray[float64] | Quantity | None = None, luminosity_distance: Quantity | None = None, angular_diameter_distance: Quantity | None = None, proper_distance: Quantity | None = None, cosmology: Cosmology | None = None) → dict[str, float | NDArray[float64] | Quantity][source]#

Resolve cosmological distance measures and redshift.

Given exactly one of redshift or a cosmological distance, compute all other distance measures consistently using the specified cosmology.

Parameters:
  • redshift (float or array-like, optional) – Cosmological redshift.

  • luminosity_distance (~astropy.units.Quantity, optional) – Luminosity distance \(D_L\).

  • angular_diameter_distance (~astropy.units.Quantity, optional) – Angular diameter distance \(D_A\).

  • proper_distance (~astropy.units.Quantity, optional) – Proper (comoving line-of-sight) distance \(D\).

  • cosmology (~astropy.cosmology.FLRW, optional) – Cosmology used to compute the relations between redshift and distances. If None, the configured default cosmology is used.

Returns:

Dictionary containing

  • redshift : float or ndarray

  • luminosity_distance : ~astropy.units.Quantity

  • angular_diameter_distance : ~astropy.units.Quantity

  • proper_distance : ~astropy.units.Quantity

Return type:

dict

Raises:

ValueError – If neither redshift nor exactly one distance is provided, unless the redshift + luminosity_distance shortcut below applies.

Notes

The relations between cosmological distances are

\[D_L = (1+z)^2 D_A\]

and

\[D = D_C\]

where \(D_C\) is the line-of-sight comoving distance.

Astropy internally handles these relations via the cosmology object.

As a shortcut, redshift and luminosity_distance may be given together, as an already-consistent pair (e.g. a per-event redshift and a luminosity distance already interpolated off a cached grid, rather than looked up fresh here). In that case angular_diameter_distance/ proper_distance are derived from the two directly (\(D_A = D_L/(1+z)^2\), \(D_C = D_L/(1+z)\)), with no cosmology lookup at all – cosmology is ignored in this branch. This is what lets a SpectralModel.flux/flux_band call reuse an already-known distance instead of re-deriving it from redshift on every call.

Examples

Resolve distances from redshift

>>> distances = resolve_cosmological_distances(
...     redshift=0.5
... )
>>> distances["luminosity_distance"]
<Quantity 2919.62495218 Mpc>

Resolve redshift from luminosity distance

>>> import astropy.units as u
>>> distances = resolve_cosmological_distances(
...     luminosity_distance=3 * u.Gpc
... )
>>> distances["redshift"]
<Quantity 0.51147033 redshift>