The Cosmology API Astropy Compatibility Layer#
cosmology.compat.astropy
is a Cosmology API compatibility layer for
astropy
. With this module, you can use any
FLRW
-based astropy
cosmology in any context
that accepts a Cosmology API cosmology.
The two components of this module are:
The Cosmology API wrapper for |
|
Astropy cosmology constants. |
Quick Start#
We can write a function that accepts any Cosmology API cosmology…
# No implementation, just a description of the interface!
from cosmology.api import StandardCosmology
def flat_angular_diameter_distance(
cosmo: StandardCosmology[Array, Array], z: Array
) -> Array:
# Do some cosmology with any object that implements the API
if cosmo.Omega_k0 != 0:
raise ValueError("This function only works for flat cosmologies")
return cosmo.comoving_distance(z) / (1 + z)
and then use it with any Cosmology API cosmology, specifically
cosmology.compat.astropy
!
We make a compatible astropy
cosmology using this library…
from astropy.cosmology import Planck18 as astropy_planck18
from cosmology.compat.astropy import StandardCosmologyWrapper
planck18 = StandardCosmologyWrapper(astropy_planck18)
import astropy.units as u
import astropy.cosmology.units as cu
z = u.Quantity([0.1, 0.2, 0.3], cu.redshift)
which now works with the above function.
>>> flat_angular_diameter_distance(planck18, z)
<Quantity [393.2415434 , 702.98158286, 948.2358979 ] Mpc>
Contributors#
Main authors: Nathaniel Starkman, Nicolas Tessore
All contributors (alphabetical last name):