python - 天体宇宙学问题,cosmology.H(z)函数是无量纲的

标签 python astropy

我正在尝试使用 astropy.cosmology。正如文档所说,当我使用 Hubble 参数方法时,它应该给我一个带单位的值 - astropy.cosmology documentation

但它只给了我一个数字,如下所示 -

ohm@ohm-ThinkCentre-M57:~/projects/mucalc$ python
Python 2.7.3 (default, Sep 26 2013, 20:08:41) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from astropy import cosmology
>>> cosmology.core.set_current(cosmology.Planck13)
>>> H0 = cosmology.H(10**6)
>>> print H0
647883886243.0
>>> H0.value
ERROR: AttributeError: 'numpy.float64' object has no attribute 'value' [unknown]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'numpy.float64' object has no attribute 'value'
>>> 

可能是什么问题?

最佳答案

Astropy 0.3 中添加了对数量的支持(参见 here ),因此您看到的是 Astropy 0.2.x 的预期行为。这是 0.3 的输出:

In [1]: from astropy import cosmology

In [2]: cosmology.core.set_current(cosmology.Planck13)

In [3]: H0 = cosmology.H(10**6)

In [4]: print H0
6.47883897961e+11 km / (Mpc s)

请注意,您还可以:

In [8]: from astropy.cosmology import Planck13

In [9]: print Planck13.H(10**6)
6.47883897961e+11 km / (Mpc s)

哪个更简洁。

关于python - 天体宇宙学问题,cosmology.H(z)函数是无量纲的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21555673/

相关文章:

python - 单元测试 - 测试字典相等性

python - Python语法错误

python - 如何使用 selenium 记录 mathjax 加载时间

python - `if False` 什么时候在 Python 中执行?

python - 使用 Azure Function App 和 Python 更新 Azure 表

python - WCS 作为使用 astropy 加载的数据立方体切片的 matplotlib 投影?

python - 我该怎么做才能让我的程序不因 .fits 文件中不存在的 header 而引发 KeyError?

android - 我如何为 kivy android 安装编译 astropy(使用 numpy)?

visual-studio-code - VScode (?) 中astropy 的pylint 错误不正确

python - Astropy 中是否内置了日落/日出功能?