Skip to content

Commit

Permalink
Implement comoving_distance
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman committed May 19, 2023
1 parent 097b23a commit 0cfaab4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/cosmology/compat/classy/_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
from numpy import vectorize
from scipy.interpolate import InterpolatedUnivariateSpline

from cosmology.compat.classy import constants
from cosmology.compat.classy._core import Array, CosmologyWrapper, InputT
Expand All @@ -30,6 +31,8 @@ def __post_init__(self) -> None:
"""
super().__post_init__()

bkg = self.cosmo.get_background()

self._cosmo_fn: dict[str, Any]
object.__setattr__(
self,
Expand All @@ -39,6 +42,13 @@ def __post_init__(self) -> None:
"Hubble": vectorize(self.cosmo.Hubble),
"angular_distance": vectorize(self.cosmo.angular_distance),
"luminosity_distance": vectorize(self.cosmo.luminosity_distance),
"comoving_distance": InterpolatedUnivariateSpline(
bkg["z"][::-1],
bkg["comov. dist."][::-1],
k=3,
ext=2,
check_finite=True,
),
},
)

Expand Down Expand Up @@ -288,7 +298,10 @@ def comoving_distance(self, z1: InputT, z2: InputT | None = None, /) -> Array:
Array
The comoving distance :math:`d_c` in Mpc.
"""
raise NotImplementedError
z1, z2 = (0, z1) if z2 is None else (z1, z2)
return self._cosmo_fn["comoving_distance"](z2) - self._cosmo_fn[
"comoving_distance"
](z1)

@overload
def transverse_comoving_distance(self, z: InputT, /) -> Array:
Expand Down

0 comments on commit 0cfaab4

Please sign in to comment.