From c0e1be75714ecacd159c839fade8e9538d68c5fd Mon Sep 17 00:00:00 2001 From: Nathaniel Starkman Date: Mon, 29 May 2023 16:24:44 -0400 Subject: [PATCH] Add property scale_factor0 to FLRW cosmologies This PR is part of a sequence to implement the Cosmology API. Signed-off-by: Nathaniel Starkman --- astropy/cosmology/flrw/base.py | 45 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/astropy/cosmology/flrw/base.py b/astropy/cosmology/flrw/base.py index bd8648593bc4..9bff97455e7b 100644 --- a/astropy/cosmology/flrw/base.py +++ b/astropy/cosmology/flrw/base.py @@ -66,7 +66,32 @@ def quad(*args, **kwargs): ############################################################################## -class FLRW(Cosmology): +class _ScaleFactorMixin: + @property + def scale_factor0(self): + """Scale factor at redshift 0.""" + return 1.0 + + def scale_factor(self, z): + """Scale factor at redshift ``z``. + + The scale factor is defined as :math:`a = 1 / (1 + z)`. + + Parameters + ---------- + z : Quantity-like ['redshift'], array-like, or `~numbers.Number` + Input redshift. + + Returns + ------- + a : ndarray or float + Scale factor at each input redshift. + Returns `float` if the input is scalar. + """ + return 1.0 / (aszarr(z) + 1.0) + + +class FLRW(Cosmology, _ScaleFactorMixin): """ A class describing an isotropic and homogeneous (Friedmann-Lemaitre-Robertson-Walker) cosmology. @@ -900,24 +925,6 @@ def H(self, z): """ return self._H0 * self.efunc(z) - def scale_factor(self, z): - """Scale factor at redshift ``z``. - - The scale factor is defined as :math:`a = 1 / (1 + z)`. - - Parameters - ---------- - z : Quantity-like ['redshift'], array-like, or `~numbers.Number` - Input redshift. - - Returns - ------- - a : ndarray or float - Scale factor at each input redshift. - Returns `float` if the input is scalar. - """ - return 1.0 / (aszarr(z) + 1.0) - def lookback_time(self, z): """Lookback time in Gyr to redshift ``z``.