Skip to content

Commit

Permalink
Add property scale_factor0 to FLRW cosmologies
Browse files Browse the repository at this point in the history
This PR is part of a sequence to implement the Cosmology API.

Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman committed Jun 7, 2023
1 parent 0a71105 commit a572ff5
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions astropy/cosmology/flrw/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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``.
Expand Down

0 comments on commit a572ff5

Please sign in to comment.