From 48db49ce4a9fb4a23b22d1c5f2350d169b01da3c Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 27 Jul 2017 10:20:01 +0800 Subject: utils/cosmology.py: age() and redshift() accepts numpy arrays Signed-off-by: Aaron LI --- fg21sim/utils/cosmology.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'fg21sim/utils/cosmology.py') diff --git a/fg21sim/utils/cosmology.py b/fg21sim/utils/cosmology.py index 5d5e42f..23a5e1f 100644 --- a/fg21sim/utils/cosmology.py +++ b/fg21sim/utils/cosmology.py @@ -182,19 +182,20 @@ class Cosmology: Parameters ---------- - z : float + z : `~numpy.ndarray` Redshift Returns ------- - age : float + age : `~numpy.ndarray` Age of the universe (cosmic time) at the given redshift. Unit: [Gyr] References: Ref.[thomas2000],Eq.(18) """ + z = np.asarray(z) t_H = self.hubble_time - t = (t_H * (2/3/np.sqrt(1-self.Om0)) * + t = ((2*t_H / 3 / np.sqrt(1-self.Om0)) * np.arcsinh(np.sqrt((1/self.Om0 - 1) / (1+z)**3))) return t @@ -212,17 +213,19 @@ class Cosmology: Parameters ---------- - age : float - Age of the universe (cosmic time), unit [Gyr] + age : `~numpy.ndarray` + Age of the universe (i.e., cosmic time) + Unit: [Gyr] Returns ------- - z : float + z : `~numpy.ndarray` Redshift corresponding to the specified age. """ + age = np.asarray(age) t_H = self.hubble_time term1 = (1/self.Om0) - 1 - term2 = np.sinh(3*age*np.sqrt(1-self.Om0) / (2*t_H)) ** 2 + term2 = np.sinh(3*age * np.sqrt(1-self.Om0) / (2*t_H)) ** 2 z = (term1 / term2) ** (1/3) - 1 return z -- cgit v1.2.2