常量 (astropy.constants#

介绍#

astropy.constants 包含许多在天文学中有用的物理常量。一个 Constant 是一种 Quantity 对象,并具有描述其来源和不确定性的附加元数据。

入门#

您可以导入一个 Constant 直接从 astropy.constants 子套餐::

>>> from astropy.constants import G
>>> print(G)
  Name   = Gravitational constant
  Value  = 6.6743e-11
  Uncertainty  = 1.5e-15
  Unit  = m3 / (kg s2)
  Reference = CODATA 2018

或者,如果希望避免显式导入所需的所有常量,可以执行以下操作:

>>> from astropy import constants as const
>>> print(const.G)
  Name   = Gravitational constant
  ...

常量可用于 算术 运营和 NumPy函数 就像其他人一样 Quantity **

>>> from astropy import units as u
>>> F = (const.G * 3. * const.M_sun * 100 * u.kg) / (2.2 * u.au) ** 2
>>> print(F.to(u.N))  
0.3675671602160826 N

单位换算#

明确地说 转换为不同单位 通常不是必需的,但如果需要,可以执行以下操作:

>>> print(const.c)
  Name   = Speed of light in vacuum
  Value  = 299792458.0
  Uncertainty  = 0.0
  Unit  = m / s
  Reference = CODATA 2018

>>> print(const.c.to('km/s'))
299792.458 km / s

>>> print(const.c.to('pc/yr'))  
0.306601393788 pc / yr

可以将大多数常量转换为 Centimeter-Gram-Second (CGS) 单位使用,例如::

>>> const.c.cgs  
<Quantity   2.99792458e+10 cm / s>

但是,某些常量是用 different physical dimensions in CGS 并且不能直接转换。由于这种模糊性,如果不指定系统::,则不能在表达式中使用此类常量

>>> 100 * const.e
Traceback (most recent call last):
    ...
TypeError: Constant u'e' does not have physically compatible units
across all systems of units and cannot be combined with other
values without specifying a system (eg. e.emu)
>>> 100 * const.e.esu  
<Quantity 4.8032045057134676e-08 Fr>

常量集合(和以前的版本)#

常量被组织到版本模块中。的常量 astropy 2.0可以在 astropyconst20 模块。例如::

>>> from astropy.constants import astropyconst20 as const
>>> print(const.e)
  Name   = Electron charge
  Value  = 1.6021766208e-19
  Uncertainty  = 9.8e-28
  Unit  = C
  Reference = CODATA 2014

版本模块包含物理和天文常量,这两组也可以相互独立选择。物理 CODATA constants 位于名称如下的模块中 codata2010codata2014 ,或 codata2018 **

>>> from astropy.constants import codata2014 as const
>>> print(const.h)
  Name   = Planck constant
  Value  = 6.62607004e-34
  Uncertainty  = 8.1e-42
  Unit  = J s
  Reference = CODATA 2014

(主要)由国际天文联合会(IAU)定义的天文常数被收集在名称如下的模块中 iau2012iau2015 **

>>> from astropy.constants import iau2012 as const
>>> print(const.L_sun)
  Name   = Solar luminosity
  Value  = 3.846e+26
  Uncertainty  = 5e+22
  Unit  = W
  Reference = Allen's Astrophysical Quantities 4th Ed.

>>> from astropy.constants import iau2015 as const
>>> print(const.L_sun)
  Name   = Nominal solar luminosity
  Value  = 3.828e+26
  Uncertainty  = 0.0
  Unit  = W
  Reference = IAU 2015 Resolution B 3

但是,直接导入这些先前版本的模块会导致与已导入的其他子包不一致 astropy.constants 。值得注意的是, astropy.units 将已经使用了常量的默认版本。当以这种方式使用以前版本的常量时,应该使用常量而不是单位来构造数量。

确保在其他组件中一致使用先前版本的常量 astropy 包(如 astropy.units ),这意味着 astropy.constants ,物理常量和天文常量版本应通过 ScienceState 上课。这些参数必须在第一次导入之前进行设置 astropy.constantsastropy.units 。例如,您可以将CODATA2010物理常数与IAU 2012天文常数一起使用:

>>> from astropy import physical_constants, astronomical_constants
>>> physical_constants.set('codata2010')  
<ScienceState physical_constants: 'codata2010'>
>>> physical_constants.get()  
'codata2010'
>>> astronomical_constants.set('iau2012')  
<ScienceState astronomical_constants: 'iau2012'>
>>> astronomical_constants.get()  
'iau2012'

则导入的所有其他包 astropy.constants 将使用这些先前版本的常量进行自我一致的初始化。

也可以使用引用版本模块的值来设置版本:

>>> from astropy import physical_constants, astronomical_constants
>>> physical_constants.set('astropyconst13')  
<ScienceState physical_constants: 'codata2010'>
>>> physical_constants.get()  
'codata2010'
>>> astronomical_constants.set('astropyconst13')  
<ScienceState astronomical_constants: 'iau2012'>
>>> astronomical_constants.get()  
'iau2012'

如果 astropy.constantsastropy.units 已经被导入,一个 RuntimeError 将提高::

>>> import astropy.units
>>> from astropy import physical_constants, astronomical_constants
>>> astronomical_constants.set('astropyconst13')
Traceback (most recent call last):
    ...
RuntimeError: astropy.units is already imported

参考/API#

astropy.常数包裹#

包含天文和物理常数,用于天文或其他地方。

典型的用例可能是:

>>> from astropy.constants import c, m_e
>>> # ... define the mass of something you want the rest energy of as m ...
>>> m = m_e
>>> E = m * c**2
>>> E.to('MeV')  
<Quantity 0.510998927603161 MeV>

以下常量可用:

名字

价值

单位

描述

G

6.6743e-11号

m3/(kg s2)

引力常数

N_A

6.02214076e+23

1/(摩尔)

阿伏加德罗数

R

8.31446262

J/(千摩尔)

气体常数

黑麦

10973731.6

1/(米)

里德堡常数

a0

5.29177211e-11

玻尔半径

阿尔法

0.00729735257

精细结构常数

自动取款机

101325

宾夕法尼亚州

标准大气

b_wien

0.00289777196

m千

维恩波长位移定律常数

C

299792458

米/(秒)

真空中的光速

E

1.60217663e-19

C

电子电荷

eps0

8.85418781e-12号

F/m公司

真空介电常数

g0号

9.80665

米/秒2

标准重力加速度

H

6.62607015e-34

J s

普朗克常数

糖化血红蛋白

1.05457182e-34

J s

约化普朗克常数

k_B

1.380649e-23

J/(K)

玻尔兹曼常数

m_e

9.1093837e-31

公斤

电子质量

m_n

1.6749275e-27

公斤

中子质量

m_p

1.67262192e-27

公斤

质子质量

mu0单位

1.25663706e-06

N/A2

真空磁导率

muB公司

9.27401008e-24

J/T公司

玻尔磁子

sigma_T

6.65245873e-29

平方米

汤姆逊散射截面

sigma_sb

电话:4208-745

W/(K4平方米)

斯特凡玻尔兹曼常数

U

1.66053907e-27

公斤

原子质量

GM_earth

3.986004e+14

m3/(s2)

标称地球质量参数

GM_jup

1.2668653e+17

m3/(s2)

名义木星质量参数

GM_sun

1.3271244e+20

m3/(s2)

标称太阳质量参数

L_bol0

3.0128e+28

W

绝对辐射量0的光度

L_sun

3.828e+26

W

标称太阳光度

M_earth

5.97216787e+24

公斤

地球质量

M_jup

1.8981246e+27

公斤

木星质量

M_sun

1.98840987e+30

公斤

太阳质量

R_earth

6378100

标称地球赤道半径

R_jup

71492000

木星名义赤道半径

R_sun

695700000

标称太阳半径

澳大利亚

1.49597871e+11

天文单位

科索沃保护团

3.08567758e+19

千帕

个人电脑

3.08567758e+16

帕塞克

Classes#

Constant(abbrev, name, value, unit, uncertainty)

物理或天文常数。

EMConstant(abbrev, name, value, unit, ...[, ...])

电磁常数。

类继承图#

Inheritance diagram of astropy.constants.constant.Constant, astropy.constants.constant.EMConstant