Units and Quantities (astropy.units)

Introduction

astropy.units handles defining, converting between, and performing arithmetic with physical quantities, such as meters, seconds, Hz, etc. It also handles logarithmic units such as magnitude and decibel.

astropy.units does not know spherical geometry or sexagesimal (hours, min, sec): if you want to deal with celestial coordinates, see the astropy.coordinates package.

Getting Started

Most users of the astropy.units package will work with “quantities”: the combination of a value and a unit. The easiest way to create a Quantity is to simply multiply or divide a value by one of the built-in units. It works with scalars, sequences and Numpy arrays:

>>> from astropy import units as u
>>> 42.0 * u.meter
<Quantity 42.0 m>
>>> [1., 2., 3.] * u.m
<Quantity [ 1., 2., 3.] m>
>>> import numpy as np
>>> np.array([1., 2., 3.]) * u.m
<Quantity [ 1., 2., 3.] m>

You can get the unit and value from a Quantity using the unit and value members:

>>> q = 42.0 * u.meter
>>> q.value
42.0
>>> q.unit
Unit("m")

From this simple building block, it’s easy to start combining quantities with different units:

>>> 15.1 * u.meter / (32.0 * u.second)  
<Quantity 0.471875 m / s>
>>> 3.0 * u.kilometer / (130.51 * u.meter / u.second)  
<Quantity 0.022986744310780783 km s / m>
>>> (3.0 * u.kilometer / (130.51 * u.meter / u.second)).decompose()  
<Quantity 22.986744310780782 s>

Unit conversion is done using the to() method, which returns a new Quantity in the given unit:

>>> x = 1.0 * u.parsec
>>> x.to(u.km)  
<Quantity 30856775814671.914 km>

It is also possible to work directly with units at a lower level, for example, to create custom units:

>>> from astropy.units import imperial

>>> cms = u.cm / u.s
>>> # ...and then use some imperial units
>>> mph = imperial.mile / u.hour

>>> # And do some conversions
>>> q = 42.0 * cms
>>> q.to(mph)  
<Quantity 0.939513242662849 mi / h>

Units that “cancel out” become a special unit called the “dimensionless unit”:

>>> u.m / u.m
Unit(dimensionless)

astropy.units is able to match compound units against the units it already knows about:

>>> (u.s ** -1).compose()  
[Unit("Bq"), Unit("Hz"), Unit("3.7e+10 Ci")]

And it can convert between unit systems, such as SI or CGS:

>>> (1.0 * u.Pa).cgs
<Quantity 10.0 Ba>

The units mag, dex and dB are special, being logarithmic units, for which a value is the logarithm of a physical quantity in a given unit. These can be used with a physical unit in parentheses to create a corresponding logarithmic quantity:

>>> -2.5 * u.mag(u.ct / u.s)
<Magnitude -2.5 mag(ct / s)>
>>> from astropy import constants as c
>>> u.Dex((c.G * u.M_sun / u.R_sun**2).cgs)  
<Dex 4.43842814841305 dex(cm / s2)>

astropy.units also handles equivalencies, such as that between wavelength and frequency. To use that feature, equivalence objects are passed to the to() conversion method. For instance, a conversion from wavelength to frequency doesn’t normally work:

>>> (1000 * u.nm).to(u.Hz)  
Traceback (most recent call last):
  ...
UnitConversionError: 'nm' (length) and 'Hz' (frequency) are not convertible

but by passing an equivalency list, in this case spectral(), it does:

>>> (1000 * u.nm).to(u.Hz, equivalencies=u.spectral())
<Quantity 299792457999999.94 Hz>

Quantities and units can be printed nicely to strings using the Format String Syntax, the preferred string formatting syntax in recent versions of python. Format specifiers (like 0.03f) in new-style format strings will used to format the quantity value:

>>> q = 15.1 * u.meter / (32.0 * u.second)
>>> q  
<Quantity 0.471875 m / s>
>>> "{0:0.03f}".format(q)
'0.472 m / s'

The value and unit can also be formatted separately. Format specifiers used on units can be used to choose the unit formatter:

>>> q = 15.1 * u.meter / (32.0 * u.second)
>>> q  
<Quantity 0.471875 m / s>
>>> "{0.value:0.03f} {0.unit:FITS}".format(q)
'0.472 m s-1'

See Also

Reference/API

astropy.units.quantity Module

This module defines the Quantity object, which represents a number with some associated units. Quantity objects support operations like ordinary numbers, but will deal with unit conversions internally.

Classes

Quantity A Quantity represents a number with some associated unit.

Class Inheritance Diagram

Inheritance diagram of astropy.units.quantity.Quantity

astropy.units Package

This subpackage contains classes and functions for defining and converting between different physical units.

This code is adapted from the pynbody units module written by Andrew Pontzen, who has granted the Astropy project permission to use the code under a BSD license.

Functions

add_enabled_equivalencies(equivalencies) Adds to the equivalencies enabled in the unit registry.
add_enabled_units(units) Adds to the set of units enabled in the unit registry.
brightness_temperature(beam_area, disp) Defines the conversion between Jy/beam and “brightness temperature”, \(T_B\), in Kelvins.
def_physical_type(unit, name) Adds a new physical unit mapping.
def_unit(s[, represents, doc, format, ...]) Factory function for defining new units.
dimensionless_angles() Allow angles to be equivalent to dimensionless (with 1 rad = 1 m/m = 1).
doppler_optical(rest) Return the equivalency pairs for the optical convention for velocity.
doppler_radio(rest) Return the equivalency pairs for the radio convention for velocity.
doppler_relativistic(rest) Return the equivalency pairs for the relativistic convention for velocity.
get_current_unit_registry()
get_physical_type(unit) Given a unit, returns the name of the physical quantity it represents.
logarithmic() Allow logarithmic units to be converted to dimensionless fractions
mass_energy() Returns a list of equivalence pairs that handle the conversion between mass and energy.
parallax() Returns a list of equivalence pairs that handle the conversion between parallax angle and distance.
quantity_input A decorator for validating the units of arguments to functions.
set_enabled_equivalencies(equivalencies) Sets the equivalencies enabled in the unit registry.
set_enabled_units(units) Sets the units enabled in the unit registry.
spectral() Returns a list of equivalence pairs that handle spectral wavelength, wave number, frequency, and energy equivalences.
spectral_density(wav[, factor]) Returns a list of equivalence pairs that handle spectral density with regard to wavelength and frequency.
temperature() Convert between Kelvin, Celsius, and Fahrenheit here because Unit and CompositeUnit cannot do addition or subtraction properly.
temperature_energy() Convert between Kelvin and keV(eV) to an equivalent amount.

Classes

CompositeUnit Create a composite unit using expressions of previously defined units.
Decibel
DecibelUnit([physical_unit, function_unit]) Logarithmic physical units expressed in dB
Dex
DexUnit([physical_unit, function_unit]) Logarithmic physical units expressed in magnitudes
FunctionQuantity A representation of a (scaled) function of a number with a unit.
FunctionUnitBase([physical_unit, function_unit]) Abstract base class for function units.
IrreducibleUnit Irreducible units are the units that all other units are defined in terms of.
LogQuantity A representation of a (scaled) logarithm of a number with a unit
LogUnit([physical_unit, function_unit]) Logarithmic unit containing a physical one
MagUnit(*args, **kwargs) Logarithmic physical units expressed in magnitudes
Magnitude
NamedUnit The base class of units that have a name.
PrefixUnit A unit that is simply a SI-prefixed version of another unit.
Quantity A Quantity represents a number with some associated unit.
Unit The main unit class.
UnitBase Abstract base class for units.
UnitConversionError Used specifically for errors related to converting between units or interpreting units in terms of other units.
UnitsError The base class for unit-specific exceptions.
UnitsWarning The base class for unit-specific exceptions.
UnrecognizedUnit A unit that did not parse correctly.

Class Inheritance Diagram

Inheritance diagram of astropy.units.core.CompositeUnit, astropy.units.function.logarithmic.Decibel, astropy.units.function.logarithmic.DecibelUnit, astropy.units.function.logarithmic.Dex, astropy.units.function.logarithmic.DexUnit, astropy.units.function.core.FunctionQuantity, astropy.units.function.core.FunctionUnitBase, astropy.units.core.IrreducibleUnit, astropy.units.function.logarithmic.LogQuantity, astropy.units.function.logarithmic.LogUnit, astropy.units.function.logarithmic.MagUnit, astropy.units.function.logarithmic.Magnitude, astropy.units.core.NamedUnit, astropy.units.core.PrefixUnit, astropy.units.quantity.Quantity, astropy.units.core.Unit, astropy.units.core.UnitBase, astropy.units.core.UnitConversionError, astropy.units.core.UnitsError, astropy.units.core.UnitsWarning, astropy.units.core.UnrecognizedUnit

astropy.units.format Package

A collection of different unit formats.

Functions

get_format([format]) Get a formatter by name.

Classes

Base The abstract base class of all unit formats.
Generic A “generic” format.
CDS Support the Centre de Données astronomiques de Strasbourg Standards for Astronomical Catalogues 2.0 format, and the complete set of supported units.
Console Output-only format for to display pretty formatting at the console.
Fits The FITS standard unit format.
Latex Output LaTeX to display the unit based on IAU style guidelines.
LatexInline Output LaTeX to display the unit based on IAU style guidelines with negative powers.
OGIP Support the units in Office of Guest Investigator Programs (OGIP) FITS files.
Unicode Output-only format to display pretty formatting at the console using Unicode characters.
Unscaled A format that doesn’t display the scale part of the unit, other than that, it is identical to the Generic format.
VOUnit The IVOA standard for units used by the VO.

Class Inheritance Diagram

Inheritance diagram of astropy.units.format.base.Base, astropy.units.format.generic.Generic, astropy.units.format.cds.CDS, astropy.units.format.console.Console, astropy.units.format.fits.Fits, astropy.units.format.latex.Latex, astropy.units.format.latex.LatexInline, astropy.units.format.ogip.OGIP, astropy.units.format.unicode_format.Unicode, astropy.units.format.generic.Unscaled, astropy.units.format.vounit.VOUnit

astropy.units.si Module

This package defines the SI units. They are also available in the astropy.units namespace.

Available Units
Unit Description Represents Aliases SI Prefixes
A ampere: base unit of electric current in SI   ampere, amp T
a annum (a) \(\mathrm{365.25\,d}\) annum T
Angstrom ångström: 10 ** -10 m \(\mathrm{0.1\,nm}\) AA, angstrom F
arcmin arc minute: angular measurement \(\mathrm{0.016666667\,{}^{\circ}}\) arcminute T
arcsec arc second: angular measurement \(\mathrm{0.00027777778\,{}^{\circ}}\) arcsecond T
bar bar: pressure \(\mathrm{100000\,Pa}\)   F
Bq becquerel: unit of radioactivity \(\mathrm{Hz}\) becquerel F
C coulomb: electric charge \(\mathrm{A\,s}\) coulomb T
cd candela: base unit of luminous intensity in SI   candela T
Ci curie: unit of radioactivity \(\mathrm{3.7 \times 10^{10}\,Bq}\) curie F
d day (d) \(\mathrm{24\,h}\) day T
deg degree: angular measurement 1/360 of full rotation \(\mathrm{0.017453293\,rad}\) degree T
deg_C Degrees Celsius   Celsius F
eV Electron Volt \(\mathrm{1.6021766 \times 10^{-19}\,J}\) electronvolt T
F Farad: electrical capacitance \(\mathrm{\frac{C}{V}}\) Farad, farad T
fortnight fortnight \(\mathrm{2\,wk}\)   F
g gram (g) \(\mathrm{0.001\,kg}\) gram T
H Henry: inductance \(\mathrm{\frac{Wb}{A}}\) Henry, henry T
h hour (h) \(\mathrm{3600\,s}\) hour, hr T
hourangle hour angle: angular measurement with 24 in a full circle \(\mathrm{15\,{}^{\circ}}\)   F
Hz Frequency \(\mathrm{\frac{1}{s}}\) Hertz, hertz T
J Joule: energy \(\mathrm{N\,m}\) Joule, joule T
K Kelvin: temperature with a null point at absolute zero.   Kelvin T
kg kilogram: base unit of mass in SI.   kilogram F
l liter: metric unit of volume \(\mathrm{1000\,cm^{3}}\) L, liter T
lm lumen: luminous flux \(\mathrm{cd\,sr}\) lumen T
lx lux: luminous emittence \(\mathrm{\frac{lm}{m^{2}}}\) lux T
m meter: base unit of length in SI   meter T
mas arc second: angular measurement \(\mathrm{0.001\,{}^{\prime\prime}}\)   F
micron micron: alias for micrometer (um) \(\mathrm{\mu m}\)   F
min minute (min) \(\mathrm{60\,s}\) minute T
mol mole: amount of a chemical substance in SI.   mole T
N Newton: force \(\mathrm{\frac{kg\,m}{s^{2}}}\) Newton, newton T
Ohm Ohm: electrical resistance \(\mathrm{\frac{V}{A}}\) ohm T
Pa Pascal: pressure \(\mathrm{\frac{J}{m^{3}}}\) Pascal, pascal T
% percent: one hundredth of unity, factor 0.01 \(\mathrm{0.01\,}\) pct F
rad radian: angular measurement of the ratio between the length on an arc and its radius   radian T
S Siemens: electrical conductance \(\mathrm{\frac{A}{V}}\) Siemens, siemens T
s second: base unit of time in SI.   second T
sday Sidereal day (sday) is the time of one rotation of the Earth. \(\mathrm{86164.091\,s}\)   F
sr steradian: unit of solid angle in SI \(\mathrm{rad^{2}}\) steradian T
t Metric tonne \(\mathrm{1000\,kg}\) tonne F
T Tesla: magnetic flux density \(\mathrm{\frac{Wb}{m^{2}}}\) Tesla, tesla T
uas arc second: angular measurement \(\mathrm{1 \times 10^{-6}\,{}^{\prime\prime}}\)   F
V Volt: electric potential or electromotive force \(\mathrm{\frac{J}{C}}\) Volt, volt T
W Watt: power \(\mathrm{\frac{J}{s}}\) Watt, watt T
Wb Weber: magnetic flux \(\mathrm{V\,s}\) Weber, weber T
wk week (wk) \(\mathrm{7\,d}\) week F
yr year (yr) \(\mathrm{365.25\,d}\) year T

astropy.units.cgs Module

This package defines the CGS units. They are also available in the top-level astropy.units namespace.

Available Units
Unit Description Represents Aliases SI Prefixes
abC abcoulomb: CGS (EMU) of charge \(\mathrm{Bi\,s}\) abcoulomb F
Ba Barye: CGS unit of pressure \(\mathrm{\frac{g}{cm\,s^{2}}}\) Barye, barye T
Bi Biot: CGS (EMU) unit of current \(\mathrm{\frac{cm^{1/2}\,g^{1/2}}{s}}\) Biot, abA, abampere, emu F
C coulomb: electric charge \(\mathrm{A\,s}\) coulomb F
cd candela: base unit of luminous intensity in SI   candela F
cm centimeter (cm) \(\mathrm{cm}\) centimeter F
D Debye: CGS unit of electric dipole moment \(\mathrm{3.3333333 \times 10^{-30}\,C\,m}\) Debye, debye T
deg_C Degrees Celsius   Celsius F
dyn dyne: CGS unit of force \(\mathrm{\frac{cm\,g}{s^{2}}}\) dyne T
erg erg: CGS unit of energy \(\mathrm{\frac{cm^{2}\,g}{s^{2}}}\)   T
Fr Franklin: CGS (ESU) unit of charge \(\mathrm{\frac{cm^{3/2}\,g^{1/2}}{s}}\) Franklin, statcoulomb, statC, esu F
G Gauss: CGS unit for magnetic field \(\mathrm{0.0001\,T}\) Gauss, gauss T
g gram (g) \(\mathrm{0.001\,kg}\) gram F
Gal Gal: CGS unit of acceleration \(\mathrm{\frac{cm}{s^{2}}}\) gal T
K Kelvin: temperature with a null point at absolute zero.   Kelvin F
k kayser: CGS unit of wavenumber \(\mathrm{\frac{1}{cm}}\) Kayser, kayser T
mol mole: amount of a chemical substance in SI.   mole F
P poise: CGS unit of dynamic viscosity \(\mathrm{\frac{g}{cm\,s}}\) poise T
rad radian: angular measurement of the ratio between the length on an arc and its radius   radian F
s second: base unit of time in SI.   second F
sr steradian: unit of solid angle in SI \(\mathrm{rad^{2}}\) steradian F
St stokes: CGS unit of kinematic viscosity \(\mathrm{\frac{cm^{2}}{s}}\) stokes T
statA statampere: CGS (ESU) unit of current \(\mathrm{\frac{Fr}{s}}\) statampere F

astropy.units.astrophys Module

This package defines the astrophysics-specific units. They are also available in the astropy.units namespace.

Available Units
Unit Description Represents Aliases SI Prefixes
adu adu     T
AU astronomical unit: approximately the mean Earth–Sun distance. \(\mathrm{1.4959787 \times 10^{11}\,m}\) au, astronomical_unit T
barn barn: unit of area used in HEP \(\mathrm{1 \times 10^{-28}\,m^{2}}\) barn T
beam beam     T
bin bin     T
bit b (bit)   b T
byte B (byte) \(\mathrm{8\,bit}\) B T
chan chan     T
ct count (ct)   count T
cycle cycle: angular measurement, a full turn or rotation \(\mathrm{6.2831853\,rad}\) cy F
earthMass Earth mass \(\mathrm{5.9742 \times 10^{24}\,kg}\) M_earth, Mearth T
earthRad Earth radius \(\mathrm{6378136\,m}\) R_earth, Rearth T
electron Number of electrons     F
jupiterMass Jupiter mass \(\mathrm{1.8987 \times 10^{27}\,kg}\) M_jup, Mjup, M_jupiter, Mjupiter T
jupiterRad Jupiter radius \(\mathrm{71492000\,m}\) R_jup, Rjup, R_jupiter, Rjupiter T
Jy Jansky: spectral flux density \(\mathrm{1 \times 10^{-26}\,\frac{W}{Hz\,m^{2}}}\) Jansky, jansky T
lyr Light year \(\mathrm{9.4607305 \times 10^{15}\,m}\) lightyear T
M_e Electron mass \(\mathrm{9.1093829 \times 10^{-31}\,kg}\)   F
M_p Proton mass \(\mathrm{1.6726218 \times 10^{-27}\,kg}\)   F
pc parsec: approximately 3.26 light-years. \(\mathrm{3.0856776 \times 10^{16}\,m}\) parsec T
ph photon (ph)   photon T
pix pixel (pix)   pixel T
R Rayleigh: photon flux \(\mathrm{7.9577472 \times 10^{8}\,\frac{ph}{s\,sr\,m^{2}}}\) Rayleigh, rayleigh T
Ry Rydberg: Energy of a photon whose wavenumber is the Rydberg constant \(\mathrm{13.605693\,eV}\) rydberg T
solLum Solar luminance \(\mathrm{3.846 \times 10^{26}\,W}\) L_sun, Lsun T
solMass Solar mass \(\mathrm{1.9891 \times 10^{30}\,kg}\) M_sun, Msun T
solRad Solar radius \(\mathrm{6.95508 \times 10^{8}\,m}\) R_sun, Rsun T
Sun Sun     F
u Unified atomic mass unit \(\mathrm{1.6605389 \times 10^{-27}\,kg}\) Da, Dalton T
vox voxel (vox)   voxel T

astropy.units.function.units Module

This package defines units that can also be used as functions of other units. If called, their arguments are used to initialize the corresponding function unit (e.g., u.mag(u.ct/u.s)). Note that the prefixed versions cannot be called, as it would be unclear what, e.g., u.mmag(u.ct/u.s) would mean.

Available Units
Unit Description Represents Aliases SI Prefixes
dB Decibel: ten per base 10 logarithmic unit \(\mathrm{0.1\,dex}\) decibel F
dex Dex: Base 10 logarithmic unit     F
mag Astronomical magnitude: -2.5 per base 10 logarithmic unit \(\mathrm{-0.4\,dex}\)   T

astropy.units.imperial Module

This package defines colloquially used Imperial units. By default, they are not enabled. To enable them, do:

>>> from astropy.units import imperial
>>> imperial.enable()  
Available Units
Unit Description Represents Aliases SI Prefixes
ac International acre \(\mathrm{43560\,ft^{2}}\) acre F
BTU British thermal unit \(\mathrm{1.0550559\,kJ}\) btu F
cal Thermochemical calorie: pre-SI metric unit of energy \(\mathrm{4.184\,J}\) calorie F
cup U.S. \(\mathrm{0.5\,pint}\)   F
deg_F Degrees Fahrenheit   Fahrenheit F
foz U.S. \(\mathrm{0.125\,cup}\) fluid_oz, fluid_ounce F
ft International foot \(\mathrm{12\,inch}\) foot F
fur Furlong \(\mathrm{660\,ft}\) furlong F
gallon U.S. \(\mathrm{3.7854118\,\mathcal{l}}\)   F
hp Electrical horsepower \(\mathrm{745.69987\,W}\) horsepower F
inch International inch \(\mathrm{2.54\,cm}\)   F
kcal Calorie: colloquial definition of Calorie \(\mathrm{1000\,cal}\) Cal, Calorie, kilocal, kilocalorie F
kip Kilopound: force \(\mathrm{1000\,lbf}\) kilopound F
kn nautical unit of speed: 1 nmi per hour \(\mathrm{\frac{nmi}{h}}\) kt, knot, NMPH F
lb International avoirdupois pound: mass \(\mathrm{16\,oz}\) lbm, pound F
lbf Pound: force \(\mathrm{\frac{ft\,slug}{s^{2}}}\)   F
mi International mile \(\mathrm{5280\,ft}\) mile F
mil Thousandth of an inch \(\mathrm{0.001\,inch}\) thou F
nmi Nautical mile \(\mathrm{1852\,m}\) nauticalmile, NM F
oz International avoirdupois ounce: mass \(\mathrm{28.349523\,g}\) ounce F
pint U.S. \(\mathrm{0.5\,quart}\)   F
psi Pound per square inch: pressure \(\mathrm{\frac{lbf}{inch^{2}}}\)   F
quart U.S. \(\mathrm{0.25\,gallon}\)   F
slug slug: mass \(\mathrm{32.174049\,lb}\)   F
st International avoirdupois stone: mass \(\mathrm{14\,lb}\) stone F
tbsp U.S. \(\mathrm{0.5\,foz}\) tablespoon F
ton International avoirdupois ton: mass \(\mathrm{2000\,lb}\)   F
tsp U.S. \(\mathrm{0.33333333\,tbsp}\) teaspoon F
yd International yard \(\mathrm{3\,ft}\) yard F

Functions

enable() Enable Imperial units so they appear in results of find_equivalent_units and compose.

astropy.units.cds Module

This package defines units used in the CDS format.

Contains the units defined in Centre de Données astronomiques de Strasbourg Standards for Astronomical Catalogues 2.0 format, and the complete set of supported units. This format is used by VOTable up to version 1.2.

To include them in compose and the results of find_equivalent_units, do:

>>> from astropy.units import cds
>>> cds.enable()  
Available Units
Unit Description Represents Aliases SI Prefixes
% percent \(\mathrm{\%}\)   F
--- dimensionless and unscaled \(\mathrm{}\)   F
\h Planck constant \(\mathrm{6.6260696 \times 10^{-34}\,J\,s}\)   T
A Ampere \(\mathrm{A}\)   T
a year \(\mathrm{a}\)   T
a0 Bohr radius \(\mathrm{5.2917721 \times 10^{-11}\,m}\)   T
AA Angstrom \(\mathrm{\mathring{A}}\) Å, Angstrom, Angstroem T
al Light year \(\mathrm{lyr}\)   T
alpha Fine structure constant \(\mathrm{0.0072973526\,}\)   T
arcm minute of arc \(\mathrm{{}^{\prime}}\) arcmin T
arcs second of arc \(\mathrm{{}^{\prime\prime}}\) arcsec T
atm atmosphere \(\mathrm{101325\,Pa}\)   T
AU astronomical unit \(\mathrm{AU}\) au T
bar bar \(\mathrm{bar}\)   T
barn barn \(\mathrm{barn}\)   T
bit bit \(\mathrm{bit}\)   T
byte byte \(\mathrm{byte}\)   T
C Coulomb \(\mathrm{C}\)   T
c speed of light \(\mathrm{2.9979246 \times 10^{8}\,\frac{m}{s}}\)   T
cal calorie \(\mathrm{4.1854\,J}\)   T
cd candela \(\mathrm{cd}\)   T
Crab Crab (X-ray) flux     T
ct count \(\mathrm{ct}\)   T
D Debye (dipole) \(\mathrm{D}\)   T
d Julian day \(\mathrm{d}\)   T
deg degree \(\mathrm{{}^{\circ}}\) °, degree T
dyn dyne \(\mathrm{dyn}\)   T
e electron charge \(\mathrm{1.6021766 \times 10^{-19}\,C}\)   T
eps0 electric constant \(\mathrm{8.8541878 \times 10^{-12}\,\frac{F}{m}}\)   T
erg erg \(\mathrm{erg}\)   T
eV electron volt \(\mathrm{eV}\)   T
F Farad \(\mathrm{F}\)   T
G Gravitation constant \(\mathrm{6.67384 \times 10^{-11}\,\frac{m^{3}}{kg\,s^{2}}}\)   T
g gram \(\mathrm{g}\)   T
gauss Gauss \(\mathrm{G}\)   T
geoMass Earth mass \(\mathrm{M_{\oplus}}\) Mgeo T
H Henry \(\mathrm{H}\)   T
h hour \(\mathrm{h}\)   T
hr hour \(\mathrm{h}\)   T
Hz Hertz \(\mathrm{Hz}\)   T
inch inch \(\mathrm{0.0254\,m}\)   T
J Joule \(\mathrm{J}\)   T
JD Julian day \(\mathrm{d}\)   T
jovMass Jupiter mass \(\mathrm{M_{\rm J}}\) Mjup T
Jy Jansky \(\mathrm{Jy}\)   T
k Boltzmann \(\mathrm{1.3806488 \times 10^{-23}\,\frac{J}{K}}\)   T
K Kelvin \(\mathrm{K}\)   T
l litre \(\mathrm{\mathcal{l}}\)   T
lm lumen \(\mathrm{lm}\)   T
Lsun solar luminosity \(\mathrm{L_{\odot}}\) solLum T
lx lux \(\mathrm{lx}\)   T
lyr Light year \(\mathrm{lyr}\)   T
m meter \(\mathrm{m}\)   T
mag magnitude \(\mathrm{mag}\)   T
mas millisecond of arc \(\mathrm{marcsec}\)   F
me electron mass \(\mathrm{9.1093829 \times 10^{-31}\,kg}\)   T
min minute \(\mathrm{min}\)   T
MJD Julian day \(\mathrm{d}\)   T
mmHg millimeter of mercury \(\mathrm{133.32239\,Pa}\)   T
mol mole \(\mathrm{mol}\)   T
mp proton mass \(\mathrm{1.6726218 \times 10^{-27}\,kg}\)   T
Msun solar mass \(\mathrm{M_{\odot}}\) solMass T
mu0 magnetic constant \(\mathrm{1.2566371 \times 10^{-6}\,\frac{N}{A^{2}}}\) µ0 T
muB Bohr magneton \(\mathrm{9.2740097 \times 10^{-24}\,\frac{J}{T}}\)   T
N Newton \(\mathrm{N}\)   T
Ohm Ohm \(\mathrm{\Omega}\)   T
Pa Pascal \(\mathrm{Pa}\)   T
pc parsec \(\mathrm{pc}\)   T
ph photon \(\mathrm{ph}\)   T
pi π \(\mathrm{3.1415927\,}\)   T
pix pixel \(\mathrm{pix}\)   T
ppm parts per million \(\mathrm{1 \times 10^{-6}\,}\)   T
R gas constant \(\mathrm{8.3144621\,\frac{J}{K\,mol}}\)   T
rad radian \(\mathrm{rad}\)   T
Rgeo Earth equatorial radius \(\mathrm{6378136\,m}\)   T
Rjup Jupiter equatorial radius \(\mathrm{71492000\,m}\)   T
Rsun solar radius \(\mathrm{R_{\odot}}\) solRad T
Ry Rydberg \(\mathrm{R_{\infty}}\)   T
s second \(\mathrm{s}\) sec T
S Siemens \(\mathrm{S}\)   T
sr steradian \(\mathrm{sr}\)   T
Sun solar unit \(\mathrm{Sun}\)   T
T Tesla \(\mathrm{T}\)   T
t metric tonne \(\mathrm{1000\,kg}\)   T
u atomic mass \(\mathrm{1.6605389 \times 10^{-27}\,kg}\)   T
V Volt \(\mathrm{V}\)   T
W Watt \(\mathrm{W}\)   T
Wb Weber \(\mathrm{Wb}\)   T
yr year \(\mathrm{a}\)   T
µas microsecond of arc \(\mathrm{\mu arcsec}\)   F

Functions

enable() Enable CDS units so they appear in results of find_equivalent_units and compose.

astropy.units.equivalencies Module

A set of standard astronomical equivalencies.

Functions

parallax() Returns a list of equivalence pairs that handle the conversion between parallax angle and distance.
spectral() Returns a list of equivalence pairs that handle spectral wavelength, wave number, frequency, and energy equivalences.
spectral_density(wav[, factor]) Returns a list of equivalence pairs that handle spectral density with regard to wavelength and frequency.
doppler_radio(rest) Return the equivalency pairs for the radio convention for velocity.
doppler_optical(rest) Return the equivalency pairs for the optical convention for velocity.
doppler_relativistic(rest) Return the equivalency pairs for the relativistic convention for velocity.
mass_energy() Returns a list of equivalence pairs that handle the conversion between mass and energy.
brightness_temperature(beam_area, disp) Defines the conversion between Jy/beam and “brightness temperature”, \(T_B\), in Kelvins.
dimensionless_angles() Allow angles to be equivalent to dimensionless (with 1 rad = 1 m/m = 1).
logarithmic() Allow logarithmic units to be converted to dimensionless fractions
temperature() Convert between Kelvin, Celsius, and Fahrenheit here because Unit and CompositeUnit cannot do addition or subtraction properly.
temperature_energy() Convert between Kelvin and keV(eV) to an equivalent amount.

astropy.units.function Package

This subpackage contains classes and functions for defining and converting between different function units and quantities, i.e., using units which are some function of a physical unit, such as magnitudes and decibels.

Classes

Decibel
DecibelUnit([physical_unit, function_unit]) Logarithmic physical units expressed in dB
Dex
DexUnit([physical_unit, function_unit]) Logarithmic physical units expressed in magnitudes
FunctionQuantity A representation of a (scaled) function of a number with a unit.
FunctionUnitBase([physical_unit, function_unit]) Abstract base class for function units.
LogQuantity A representation of a (scaled) logarithm of a number with a unit
LogUnit([physical_unit, function_unit]) Logarithmic unit containing a physical one
MagUnit(*args, **kwargs) Logarithmic physical units expressed in magnitudes
Magnitude

Class Inheritance Diagram

Inheritance diagram of astropy.units.function.logarithmic.Decibel, astropy.units.function.logarithmic.DecibelUnit, astropy.units.function.logarithmic.Dex, astropy.units.function.logarithmic.DexUnit, astropy.units.function.core.FunctionQuantity, astropy.units.function.core.FunctionUnitBase, astropy.units.function.logarithmic.LogQuantity, astropy.units.function.logarithmic.LogUnit, astropy.units.function.logarithmic.MagUnit, astropy.units.function.logarithmic.Magnitude

Acknowledgments

This code is adapted from the pynbody units module written by Andrew Pontzen, who has granted the Astropy project permission to use the code under a BSD license.