# 宇宙学计算 (astropy.cosmology ）¶

## 入门¶

### 实例¶

>>> from astropy.cosmology import WMAP9 as cosmo
>>> cosmo.H(0)
<Quantity 69.32 km / (Mpc s)>

>>> cosmo.kpc_proper_per_arcmin(3)
<Quantity 472.97709620405266 kpc / arcmin>


>>> from astropy.cosmology import WMAP9 as cosmo
>>> cosmo.comoving_distance([0.5, 1.0, 1.5])
<Quantity [1916.06941724, 3363.07062107, 4451.7475201 ] Mpc>


>>> from astropy.cosmology import FlatLambdaCDM
>>> cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Tcmb0=2.725)
>>> cosmo
FlatLambdaCDM(H0=70 km / (Mpc s), Om0=0.3, Tcmb0=2.725 K,
Neff=3.04, m_nu=[0. 0. 0.] eV, Ob0=None)


>>> from astropy.cosmology import WMAP9 as cosmo
>>> H0 = cosmo.H(0)
>>> H0.value, H0.unit
(69.32, Unit("km / (Mpc s)"))


## 使用 astropy.cosmology¶

### 实例¶

>>> from astropy.cosmology import FlatLambdaCDM
>>> cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
>>> cosmo
FlatLambdaCDM(H0=70 km / (Mpc s), Om0=0.3, Tcmb0=0 K,
Neff=3.04, m_nu=None, Ob0=None)


>>> from astropy.cosmology import FlatLambdaCDM
>>> import astropy.units as u
>>> cosmo = FlatLambdaCDM(H0=70 * u.km / u.s / u.Mpc, Tcmb0=2.725 * u.K, Om0=0.3)


>>> cosmo.luminosity_distance(4)
<Quantity 35842.353618623194 Mpc>


>>> cosmo.age(0)
<Quantity 13.461701658024014 Gyr>


>>> cosmo.age([0.5, 1, 1.5]).value
array([8.42128013, 5.74698021, 4.19645373])


FLRWFlatLambdaCDM 所有可用方法和属性的对象docstring。

>>> from astropy.cosmology import WMAP7   # WMAP 7-year cosmology
>>> WMAP7.critical_density(0)  # critical density at z = 0
<Quantity 9.31000324385361e-30 g / cm3>


>>> from astropy.cosmology import WMAP7   # WMAP 7-year cosmology
>>> WMAP7.Om([0, 1.0, 2.0]), WMAP7.Ode([0., 1.0, 2.0])
(array([0.272     , 0.74898522, 0.90905234]),
array([0.72791572, 0.2505506 , 0.0901026 ]))


>>> from astropy.cosmology import FlatLambdaCDM
>>> cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05)
>>> cosmo
FlatLambdaCDM(H0=70 km / (Mpc s), Om0=0.3, Tcmb0=0 K,
Neff=3.04, m_nu=None, Ob0=0.05)


>>> from astropy.cosmology import FlatLambdaCDM
>>> cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
>>> cosmo.Odm(1)
Traceback (most recent call last):
...
ValueError: Baryonic density not set for this cosmology, unclear
meaning of dark matter density


>>> from astropy.cosmology import FlatwCDM
>>> cosmo = FlatwCDM(name='SNLS3+WMAP7', H0=71.58, Om0=0.262, w0=-1.016)
>>> cosmo
FlatwCDM(name="SNLS3+WMAP7", H0=71.6 km / (Mpc s), Om0=0.262,
w0=-1.02, Tcmb0=0 K, Neff=3.04, m_nu=None, Ob0=None)


>>> from astropy.cosmology import WMAP9
>>> newcosmo = WMAP9.clone(name='WMAP9 modified', Om0=0.3141)
>>> WMAP9.H0, newcosmo.H0  # some values unchanged
(<Quantity 69.32 km / (Mpc s)>, <Quantity 69.32 km / (Mpc s)>)
>>> WMAP9.Om0, newcosmo.Om0  # some changed
(0.2865, 0.3141)
>>> WMAP9.Ode0, newcosmo.Ode0  # Indirectly changed since this is flat
(0.7134130719051658, 0.6858130719051657)


### 在给定的宇宙学量值下求红移¶

#### 例子¶

>>> import astropy.units as u
>>> from astropy.cosmology import Planck13, z_at_value
>>> z_at_value(Planck13.age, 2 * u.Gyr)
3.1981226843560968


### 内建宇宙学¶

>>> from astropy.cosmology import Planck13  # Planck 2013
>>> Planck13.lookback_time(2)  # lookback time in Gyr at z=2
<Quantity 10.51184138 Gyr>


H0型

WMAP5型

70.2

0.277

WMAP7型

70.4

0.272

WMAP9型

Hinshaw等人。2013

69.3

0.287

67.8

0.307

67.7

0.307

67.7

0.310

>>> from astropy.cosmology import WMAP7
>>> print(WMAP7.__doc__)
WMAP7 instance of FlatLambdaCDM cosmology
(from Komatsu et al. 2011, ApJS, 192, 18, doi: 10.1088/0067-0049/192/2/18.
Table 1 (WMAP + BAO + H0 ML).)


### 光子和中微子¶

#### 实例¶

>>> from astropy.cosmology import WMAP7   # WMAP 7-year cosmology
>>> WMAP7.Ogamma0, WMAP7.Onu0  # Current epoch values
(4.985694972799396e-05, 3.442154948307989e-05)
>>> z = [0, 1.0, 2.0]
>>> WMAP7.Ogamma(z), WMAP7.Onu(z)
(array([4.98603986e-05, 2.74593395e-04, 4.99915942e-04]),
array([3.44239306e-05, 1.89580995e-04, 3.45145089e-04]))


>>> from astropy.cosmology import FlatLambdaCDM
>>> import astropy.units as u
>>> cos = FlatLambdaCDM(70.4 * u.km / u.s / u.Mpc, 0.272, Tcmb0 = 0.0 * u.K)
>>> cos.Ogamma0, cos.Onu0
(0.0, 0.0)


>>> from astropy.cosmology import FlatLambdaCDM
>>> cos = FlatLambdaCDM(70.4, 0.272, Tcmb0=2.725, Neff=0)
>>> cos.Ogamma([0, 1, 2])  # Photons are still present
array([4.98603986e-05, 2.74642208e-04, 5.00086413e-04])
>>> cos.Onu([0, 1, 2])  # But not neutrinos
array([0., 0., 0.])


>>> from astropy.cosmology import FlatLambdaCDM
>>> import astropy.units as u
>>> H0 = 70.4 * u.km / u.s / u.Mpc
>>> m_nu = 0 * u.eV
>>> cosmo = FlatLambdaCDM(H0, 0.272, Tcmb0=2.725, m_nu=m_nu)
>>> cosmo.has_massive_nu
False
>>> cosmo.m_nu
<Quantity [0., 0., 0.] eV>
>>> m_nu = [0.0, 0.05, 0.10] * u.eV
>>> cosmo = FlatLambdaCDM(H0, 0.272, Tcmb0=2.725, m_nu=m_nu)
>>> cosmo.has_massive_nu
True
>>> cosmo.m_nu
<Quantity [0.  , 0.05, 0.1 ] eV>
>>> cosmo.Onu([0, 1.0, 15.0])
array([0.00327011, 0.00896845, 0.01257946])
>>> cosmo.Onu(1) * cosmo.critical_density(1)
<Quantity 2.444380380370406e-31 g / cm3>


## 开发人员：使用 astropy.cosmology 里面 astropy¶

def myfunc(..., cosmo=None):
from astropy.cosmology import default_cosmology

if cosmo is None:
cosmo = default_cosmology.get()



## 参考/API¶

### 天文宇宙学包裹¶

Astropy documentation 更多详细的使用示例和参考。

#### 功能¶

 z_at_value \（功能，fval[, zmin, zmax, ztol, ...] ） 找到红移 z 在哪 func(z) = fval .

#### Classes¶

 FLRW \（H0、Om0、Ode0[, Tcmb0, Neff, m_nu, ...] ） 描述各向同性和均匀宇宙学的一个类。 FlatLambdaCDM \（H0，Om0[, Tcmb0, Neff, m_nu, ...] ） 具有宇宙学常数且无曲率的FLRW宇宙学。 Flatw0waCDM \（H0，Om0[, w0, wa, Tcmb0, Neff, ...] ） 具有CPL暗能量状态方程且无曲率的FLRW宇宙学。 FlatwCDM \（H0，Om0[, w0, Tcmb0, Neff, m_nu, ...] ） 具有恒定暗能量状态方程且无空间曲率的FLRW宇宙学。 LambdaCDM \（H0、Om0、Ode0[, Tcmb0, Neff, ...] ） 具有宇宙学常数和曲率的FLRW宇宙学。 默认使用的宇宙学。改变它：：。 w0waCDM \（H0、Om0、Ode0[, w0, wa, Tcmb0, ...] ） 具有CPL暗能量状态方程和曲率的FLRW宇宙学。 w0wzCDM \（H0、Om0、Ode0[, w0, wz, Tcmb0, ...] ） 具有可变暗能量状态方程和曲率的FLRW宇宙学。 wCDM \（H0、Om0、Ode0[, w0, Tcmb0, Neff, m_nu, ...] ） 具有恒定暗能量状态方程和曲率的FLRW宇宙学。 wpwaCDM \（H0、Om0、Ode0[, wp, wa, zp, Tcmb0, ...] ） FLRW宇宙学，具有CPL暗能量状态方程、轴红移和曲率。