# 常量 (`astropy.constants` ）¶

## 介绍¶

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

## 入门¶

```>>> from astropy.constants import G
```

```>>> from astropy import constants as const
```

### 例子¶

```>>> 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
```

```>>> 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
```

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

```>>> 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>
```

## 常量集合（和以前的版本）¶

```>>> 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
```

```>>> 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
```

```>>> 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
```

```>>> 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'
```

```>>> 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'
```

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

## 参考/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

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

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

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

#### 功能¶

 `set_enabled_constants` \（modname） 4.0 版后已移除.

#### Classes¶

 `Constant` \（缩写，名称，值，单位，不确定度） 物理或天文常数。 `EMConstant` \（缩写，名称，值，单位\ [, ...] ） 电磁常数。