Skip to content

Commit

Permalink
Merge branch 'main' into redshift
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaLynn authored Jul 16, 2024
2 parents 761b57e + 8de94c5 commit 64098cd
Show file tree
Hide file tree
Showing 32 changed files with 1,398 additions and 259 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies = [
"astropy",
"numpy",
"scipy",
"sncosmo",
]

[project.urls]
Expand Down
57 changes: 57 additions & 0 deletions src/tdastro/astro_utils/cosmology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import astropy.cosmology.units as cu
from astropy import units as u

from tdastro.base_models import FunctionNode


def redshift_to_distance(redshift, cosmology):
"""Compute a source's luminosity distance given its redshift and a
specified cosmology using astropy's redshift_distance().
Parameters
----------
redshift : `float`
The redshift value.
cosmology : `astropy.cosmology`
The cosmology specification.
Returns
-------
distance : `float`
The luminosity distance (in pc)
"""
z = redshift * cu.redshift
distance = z.to(u.pc, cu.redshift_distance(cosmology, kind="luminosity"))
return distance.value


class RedshiftDistFunc(FunctionNode):
"""A wrapper class for the redshift_to_distance() function.
Attributes
----------
cosmology : `astropy.cosmology`
The cosmology specification.
kind : `str`
The distance type for the Equivalency as defined by
astropy.cosmology.units.redshift_distance.
Parameters
----------
redshift : function or constant
The function or constant providing the redshift value.
cosmology : `astropy.cosmology`
The cosmology specification.
"""

def __init__(self, redshift, cosmology):
# Call the super class's constructor with the needed information.
super().__init__(
func=redshift_to_distance,
redshift=redshift,
cosmology=cosmology,
)

def __str__(self):
"""Return the string representation of the function."""
return f"RedshiftDistFunc({self.cosmology.name}, {self.kind})"
Loading

0 comments on commit 64098cd

Please sign in to comment.