Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow floats #27

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/cosmology/api/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def critical_density0(self) -> ArrayT:
# ==============================================================
# Methods

def scale_factor(self, z: ArrayT, /) -> ArrayT:
def scale_factor(self, z: ArrayT | float, /) -> ArrayT:
"""Redshift-dependenct scale factor.

The scale factor is defined as :math:`a = a_0 / (1 + z)`.

Parameters
----------
z : Array, positional-only
z : Array or float, positional-only
The redshift(s) at which to evaluate the scale factor.

Returns
Expand All @@ -84,7 +84,7 @@ def scale_factor(self, z: ArrayT, /) -> ArrayT:
"""
...

def Otot(self, z: ArrayT, /) -> ArrayT:
def Otot(self, z: ArrayT | float, /) -> ArrayT:
r"""Redshift-dependent total density parameter.

Parameters
Expand All @@ -98,14 +98,14 @@ def Otot(self, z: ArrayT, /) -> ArrayT:
"""
...

def critical_density(self, z: ArrayT, /) -> ArrayT:
def critical_density(self, z: ArrayT | float, /) -> ArrayT:
"""Redshift-dependent critical density in Msol Mpc-3."""
...

# ----------------------------------------------
# Time

def age(self, z: ArrayT, /) -> ArrayT:
def age(self, z: ArrayT | float, /) -> ArrayT:
"""Age of the universe in Gyr at redshift ``z``.

Parameters
Expand All @@ -119,7 +119,7 @@ def age(self, z: ArrayT, /) -> ArrayT:
"""
...

def lookback_time(self, z: ArrayT, /) -> ArrayT:
def lookback_time(self, z: ArrayT | float, /) -> ArrayT:
"""Lookback time to redshift ``z`` in Gyr.

The lookback time is the difference between the age of the Universe now
Expand All @@ -139,7 +139,7 @@ def lookback_time(self, z: ArrayT, /) -> ArrayT:
# ----------------------------------------------
# Comoving distance

def comoving_distance(self, z: ArrayT, /) -> ArrayT:
def comoving_distance(self, z: ArrayT | float, /) -> ArrayT:
r"""Comoving line-of-sight distance :math:`d_c(z)` in Mpc.

The comoving distance along the line-of-sight between two objects
Expand All @@ -156,7 +156,7 @@ def comoving_distance(self, z: ArrayT, /) -> ArrayT:
"""
...

def comoving_transverse_distance(self, z: ArrayT, /) -> ArrayT:
def comoving_transverse_distance(self, z: ArrayT | float, /) -> ArrayT:
r"""Transverse comoving distance :math:`d_M(z)` in Mpc.

This value is the transverse comoving distance at redshift ``z``
Expand All @@ -175,7 +175,7 @@ def comoving_transverse_distance(self, z: ArrayT, /) -> ArrayT:
"""
...

def comoving_volume(self, z: ArrayT, /) -> ArrayT:
def comoving_volume(self, z: ArrayT | float, /) -> ArrayT:
r"""Comoving volume in cubic Mpc.

This is the volume of the universe encompassed by redshifts less than
Expand All @@ -193,7 +193,7 @@ def comoving_volume(self, z: ArrayT, /) -> ArrayT:
"""
...

def differential_comoving_volume(self, z: ArrayT, /) -> ArrayT:
def differential_comoving_volume(self, z: ArrayT | float, /) -> ArrayT:
r"""Differential comoving volume in cubic Mpc per steradian.

If :math:`V_c` is the comoving volume of a redshift slice with solid
Expand All @@ -212,7 +212,7 @@ def differential_comoving_volume(self, z: ArrayT, /) -> ArrayT:
# ----------------------------------------------
# Angular diameter distance

def angular_diameter_distance(self, z: ArrayT, /) -> ArrayT:
def angular_diameter_distance(self, z: ArrayT | float, /) -> ArrayT:
"""Angular diameter distance :math:`d_A(z)` in Mpc.

This gives the proper (sometimes called 'physical') transverse
Expand All @@ -239,7 +239,7 @@ def angular_diameter_distance(self, z: ArrayT, /) -> ArrayT:
# ----------------------------------------------
# Luminosity distance

def luminosity_distance(self, z: ArrayT, /) -> ArrayT:
def luminosity_distance(self, z: ArrayT | float, /) -> ArrayT:
"""Redshift-dependent luminosity distance in Mpc.

This is the distance to use when converting between the bolometric flux
Expand Down
14 changes: 7 additions & 7 deletions src/cosmology/api/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def Ok0(self) -> ArrayT:
"""Omega curvature; the effective curvature density/critical density at z=0."""
...

def Ok(self, z: ArrayT, /) -> ArrayT:
def Ok(self, z: ArrayT | float, /) -> ArrayT:
"""Redshift-dependent curvature density parameter.

Parameters
Expand All @@ -41,7 +41,7 @@ def Om0(self) -> ArrayT:
"""Omega matter; matter density/critical density at z=0."""
...

def Om(self, z: ArrayT, /) -> ArrayT:
def Om(self, z: ArrayT | float, /) -> ArrayT:
"""Redshift-dependent non-relativistic matter density parameter.

Parameters
Expand Down Expand Up @@ -69,7 +69,7 @@ def Ob0(self) -> ArrayT:
"""Omega baryon; baryon density/critical density at z=0."""
...

def Ob(self, z: ArrayT, /) -> ArrayT:
def Ob(self, z: ArrayT | float, /) -> ArrayT:
"""Redshift-dependent baryon density parameter.

Parameters
Expand Down Expand Up @@ -102,7 +102,7 @@ def m_nu(self) -> tuple[ArrayT, ...]:
"""Neutrino mass in eV."""
...

def Onu(self, z: ArrayT, /) -> ArrayT:
def Onu(self, z: ArrayT | float, /) -> ArrayT:
r"""Redshift-dependent neutrino density parameter.

Parameters
Expand All @@ -125,7 +125,7 @@ def Ode0(self) -> ArrayT:
"""Omega dark energy; dark energy density/critical density at z=0."""
...

def Ode(self, z: ArrayT, /) -> ArrayT:
def Ode(self, z: ArrayT | float, /) -> ArrayT:
"""Redshift-dependent dark energy density parameter.

Parameters
Expand All @@ -148,7 +148,7 @@ def Odm0(self) -> ArrayT:
"""Omega dark matter; dark matter density/critical density at z=0."""
...

def Odm(self, z: ArrayT, /) -> ArrayT:
def Odm(self, z: ArrayT | float, /) -> ArrayT:
"""Redshift-dependent dark matter density parameter.

Parameters
Expand Down Expand Up @@ -176,7 +176,7 @@ def Ogamma0(self) -> ArrayT:
"""Omega gamma; the density/critical density of photons at z=0."""
...

def Ogamma(self, z: ArrayT, /) -> ArrayT:
def Ogamma(self, z: ArrayT | float, /) -> ArrayT:
"""Redshift-dependent photon density parameter.

Parameters
Expand Down
10 changes: 5 additions & 5 deletions src/cosmology/api/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def Otot0(self) -> ArrayT:
# ==============================================================
# Methods

def Tcmb(self, z: ArrayT, /) -> ArrayT:
def Tcmb(self, z: ArrayT | float, /) -> ArrayT:
"""Temperature of the CMB at redshift z in Kelvin.

Parameters
Expand All @@ -147,7 +147,7 @@ def Tcmb(self, z: ArrayT, /) -> ArrayT:
# ----------------------------------------------
# Hubble

def H(self, z: ArrayT, /) -> ArrayT:
def H(self, z: ArrayT | float, /) -> ArrayT:
"""Hubble function :math:`H(z)` in km s-1 Mpc-1.

Parameters
Expand All @@ -161,7 +161,7 @@ def H(self, z: ArrayT, /) -> ArrayT:
"""
...

def efunc(self, z: ArrayT, /) -> ArrayT:
def efunc(self, z: ArrayT | float, /) -> ArrayT:
"""Standardised Hubble function :math:`E(z) = H(z)/H_0`.

Parameters
Expand All @@ -175,7 +175,7 @@ def efunc(self, z: ArrayT, /) -> ArrayT:
"""
...

def inv_efunc(self, z: ArrayT, /) -> ArrayT:
def inv_efunc(self, z: ArrayT | float, /) -> ArrayT:
"""Inverse of ``efunc``.

Parameters
Expand All @@ -192,7 +192,7 @@ def inv_efunc(self, z: ArrayT, /) -> ArrayT:
# ----------------------------------------------
# Omega

def Otot(self, z: ArrayT, /) -> ArrayT:
def Otot(self, z: ArrayT | float, /) -> ArrayT:
r"""Redshift-dependent total density parameter.

This is the sum of the matter, radiation, neutrino, dark energy, and
Expand Down