cosmology.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:yt 作者: yt-project 项目源码 文件源码
def t_from_z(self, z):
        """
        Compute the age of the Universe from redshift.  This is based on Enzo's
        CosmologyComputeTimeFromRedshift.C, but altered to use physical units.  
        Similar to hubble_time, but using an analytical function.

        Parameters
        ----------
        z : float
            Redshift.

        Examples
        --------

        >>> from yt.utilities.cosmology import Cosmology
        >>> co = Cosmology()
        >>> print(co.t_from_z(0.).in_units("Gyr"))

        See Also
        --------

        hubble_time

        """
        omega_curvature = 1.0 - self.omega_matter - self.omega_lambda

        # 1) For a flat universe with omega_matter = 1, things are easy.

        if ((self.omega_matter == 1.0) and (self.omega_lambda == 0.0)):
            t0 = 2.0/3.0/np.power(1+z, 1.5)

        # 2) For omega_matter < 1 and omega_lambda == 0 see
        #    Peebles 1993, eq. 13-3, 13-10.

        if ((self.omega_matter < 1) and (self.omega_lambda == 0)):
            eta = np.arccosh(1 + 
                             2*(1-self.omega_matter)/self.omega_matter/(1+z))
            t0 = self.omega_matter/ \
              (2*np.power(1.0-self.omega_matter, 1.5))*\
              (np.sinh(eta) - eta)

        # 3) For omega_matter > 1 and omega_lambda == 0, use sin/cos.

        if ((self.omega_matter > 1) and (self.omega_lambda == 0)):
            eta = np.arccos(1 - 2*(1-self.omega_matter)/self.omega_matter/(1+z))
            t0 = self.omega_matter/(2*np.power(1.0-self.omega_matter, 1.5))*\
                (eta - np.sin(eta))

        # 4) For flat universe, with non-zero omega_lambda, see eq. 13-20.

        if ((np.fabs(omega_curvature) < 1.0e-3) and (self.omega_lambda != 0)):
            t0 = 2.0/3.0/np.sqrt(1-self.omega_matter)*\
                np.arcsinh(np.sqrt((1-self.omega_matter)/self.omega_matter)/ \
                               np.power(1+z, 1.5))

        # Now convert from Time * H0 to time.

        my_time = t0 / self.hubble_constant

        return my_time.in_base(self.unit_system)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号