aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/utils/cosmology.py
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-07-27 10:20:01 +0800
committerAaron LI <aly@aaronly.me>2017-07-27 10:20:01 +0800
commit48db49ce4a9fb4a23b22d1c5f2350d169b01da3c (patch)
tree8df0f8c99b4bf7dc87be06a7a98fd4e2b5042f1f /fg21sim/utils/cosmology.py
parent915e838fc1722f4a03052f48a4f224e061511049 (diff)
downloadfg21sim-48db49ce4a9fb4a23b22d1c5f2350d169b01da3c.tar.bz2
utils/cosmology.py: age() and redshift() accepts numpy arrays
Signed-off-by: Aaron LI <aly@aaronly.me>
Diffstat (limited to 'fg21sim/utils/cosmology.py')
-rw-r--r--fg21sim/utils/cosmology.py17
1 files changed, 10 insertions, 7 deletions
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