Constants (astropy.constants
)¶
Introduction¶
astropy.constants
contains a number of physical constants useful in
Astronomy. Constants are Quantity
objects with
additional metadata describing their provenance and uncertainties.
Getting Started¶
To use the constants in S.I. units, you can import the constants directly from
the astropy.constants
subpackage:
>>> from astropy.constants import G
or, if you want to avoid having to explicitly import all the constants you need, you can simply do:
>>> from astropy import constants as const
and then subsequently use for example const.G
. Constants are fullyfledged
Quantity
objects, so you can easily convert them to
different units for example:
>>> print(const.c)
Name = Speed of light in vacuum
Value = 299792458.0
Uncertainty = 0.0
Unit = m / s
Reference = CODATA 2014
>>> print(const.c.to('km/s'))
299792.458 km / s
>>> print(const.c.to('pc/yr'))
0.306601393788 pc / yr
and you can use them in conjunction with unit and other nonconstant
Quantity
objects:
>>> 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
It is possible to convert most constants to cgs using e.g.:
>>> const.c.cgs
<Quantity 2.99792458e+10 cm / s>
However, some constants are defined with different physical dimensions in cgs and cannot be directly converted. Because of this ambiguity, such constants cannot be used in expressions without specifying a system:
>>> 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.8032045057134676e08 Fr>
Collections of constants (and prior versions)¶
Constants are organized into version modules. The constants for
Astropy 1.3 can be accessed in the astropyconst13
module.
For example:
>>> from astropy.constants import astropyconst13 as const
>>> print(const.e)
Name = Electron charge
Value = 1.602176565e19
Uncertainty = 3.5e27
Unit = C
Reference = CODATA 2010
Physical CODATA constants are in modules with names like codata2010
or
codata2014
:
>>> from astropy.constants import codata2010 as const
>>> print(const.h)
Name = Planck constant
Value = 6.62606957e34
Uncertainty = 2.9e41
Unit = J s
Reference = CODATA 2010
Astronomical constants defined (primarily) by the IAU are collected in
modules with names like iau2012
or iau2015
:
>>> 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
The astronomical and physical constants are combined into modules with
names like astropyconst13
and astropyconst20
. To temporarily set
constants to an older version (e.g., for regression testing), a context
manager is available, as follows:
>>> from astropy import constants as const
>>> with const.set_enabled_constants('astropyconst13'):
... print(const.h)
Name = Planck constant
Value = 6.62606957e34
Uncertainty = 2.9e41
Unit = J s
Reference = CODATA 2010
>>> print(const.h)
Name = Planck constant
Value = 6.62607004e34
Uncertainty = 8.1e42
Unit = J s
Reference = CODATA 2014
Warning
Units such as u.M_sun
will use the current version of the
corresponding constant. When using prior versions of the constants,
quantities should be constructed with constants instead of units.
Reference/API¶
astropy.constants Package¶
Contains astronomical and physical constants for use in Astropy or other places.
A typical use case might be:
>>> 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>
The following constants are available:
Name 
Value 
Unit 
Description 

G 
6.67408e11 
m3 / (kg s2) 
Gravitational constant 
N_A 
6.02214086e+23 
1 / (mol) 
Avogadro’s number 
R 
8.3144598 
J / (K mol) 
Gas constant 
Ryd 
10973731.6 
1 / (m) 
Rydberg constant 
a0 
5.29177211e11 
m 
Bohr radius 
alpha 
0.00729735257 
Finestructure constant 

atm 
101325 
Pa 
Standard atmosphere 
b_wien 
0.0028977729 
m K 
Wien wavelength displacement law constant 
c 
299792458 
m / (s) 
Speed of light in vacuum 
e 
1.60217662e19 
C 
Electron charge 
eps0 
8.85418782e12 
F/m 
Electric constant 
g0 
9.80665 
m / s2 
Standard acceleration of gravity 
h 
6.62607004e34 
J s 
Planck constant 
hbar 
1.0545718e34 
J s 
Reduced Planck constant 
k_B 
1.38064852e23 
J / (K) 
Boltzmann constant 
m_e 
9.10938356e31 
kg 
Electron mass 
m_n 
1.67492747e27 
kg 
Neutron mass 
m_p 
1.6726219e27 
kg 
Proton mass 
mu0 
1.25663706e06 
N/A2 
Magnetic constant 
muB 
9.27400999e24 
J/T 
Bohr magneton 
sigma_T 
6.65245872e29 
m2 
Thomson scattering crosssection 
sigma_sb 
5.670367e08 
W / (K4 m2) 
StefanBoltzmann constant 
u 
1.66053904e27 
kg 
Atomic mass 
GM_earth 
3.986004e+14 
m3 / (s2) 
Nominal Earth mass parameter 
GM_jup 
1.2668653e+17 
m3 / (s2) 
Nominal Jupiter mass parameter 
GM_sun 
1.3271244e+20 
m3 / (s2) 
Nominal solar mass parameter 
L_bol0 
3.0128e+28 
W 
Luminosity for absolute bolometric magnitude 0 
L_sun 
3.828e+26 
W 
Nominal solar luminosity 
M_earth 
5.97236473e+24 
kg 
Earth mass 
M_jup 
1.89818717e+27 
kg 
Jupiter mass 
M_sun 
1.98847542e+30 
kg 
Solar mass 
R_earth 
6378100 
m 
Nominal Earth equatorial radius 
R_jup 
71492000 
m 
Nominal Jupiter equatorial radius 
R_sun 
695700000 
m 
Nominal solar radius 
au 
1.49597871e+11 
m 
Astronomical Unit 
kpc 
3.08567758e+19 
m 
Kiloparsec 
pc 
3.08567758e+16 
m 
Parsec 
Functions¶

Context manager to temporarily set values in the 
Classes¶
A physical or astronomical constant. 

An electromagnetic constant. 