Units (astronat.units)

Reference/API

astronat.units Package

Astropy Units. Extended.

provides full drop-in replacement for astropy units.

Functions

quantity_return_(res[, unit, to_value, …])

Control function return of Quantity.

from_amuse(quantity)

Convert AMUSE quantity to astropy quantity.

hms_str_to_unit(hms[, empty_to_, copy])

Change a hms string to Astropy deg units.

quantity_io([function, unit, to_value, …])

Decorator for validating the units of arguments to functions.

Classes

QuantityInputOutput(function, unit, …)

Decorator for validating the units of arguments to functions.

Class Inheritance Diagram

Inheritance diagram of astronat.units.decorators.QuantityInputOutput

astronat.units.composite Module

Composite Astropy units.

Available Units

Unit

Description

Represents

Aliases

SI Prefixes

km_s

kilometer per second composite unit

\(\mathrm{\frac{km}{s}}\)

kmps

No

km_skpc

kilometer per second per kiloparsec composite unit

\(\mathrm{\frac{km}{kpc\,s}}\)

kmpspkpc

No

km_sMpc

kilometer per second per Megaparsec composite unit

\(\mathrm{\frac{km}{Mpc\,s}}\)

kmpspMpc, hubble, Hubble

No

m_s

meter per second composite unit

\(\mathrm{\frac{m}{s}}\)

mps

No

mas_yr

milli-arcseconds / year composite unit

\(\mathrm{\frac{mas}{yr}}\)

maspyr

No

astronat.units.amuse Module

Astropy units, extended for AMUSE compatibility.

These units are also available in the units namespace.

Not all AMUSE units are compatible with Astropy since some unit names are already present in Astropy. These units are:

  • ms (meters per second), which in Astropy means milliseconds

  • myr (million years), which in Astropy means milliyear

This module prioritizes Astropy compatibility, so uses the Astropy versions. For full AMUSE definitions in astropy units, the full_amuse should be used.

Available Units

Unit

Description

Represents

Aliases

SI Prefixes

A

ampere: base unit of electric current in SI

ampere, amp

No

amu

atomic mass unit, AMUSE compatibility

\(\mathrm{u}\)

No

arcmin

arc minute: angular measurement

\(\mathrm{0.016666667\,{}^{\circ}}\)

arcminute

No

arcsec

arc second: angular measurement

\(\mathrm{0.00027777778\,{}^{\circ}}\)

arcsecond

No

AU

astronomical unit: approximately the mean Earth–Sun distance.

\(\mathrm{1.4959787 \times 10^{11}\,m}\)

au, astronomical_unit

No

AUd

AU per day, AMUSE compatibility

\(\mathrm{1.4959787 \times 10^{11}\,\frac{m}{d}}\)

No

C

coulomb: electric charge

\(\mathrm{A\,s}\)

coulomb

No

cd

candela: base unit of luminous intensity in SI

candela

No

cm

centimeter (cm)

\(\mathrm{cm}\)

centimeter

No

deg

degree: angular measurement 1/360 of full rotation

\(\mathrm{0.017453293\,rad}\)

degree

No

e

electron charge, AMUSE compatibility

\(\mathrm{1.6021766 \times 10^{-19}\,C}\)

No

E_h

Hartree energy, AMUSE compatibility

\(\mathrm{2\,R_{\infty}}\)

Hartree_energy

No

erg

erg: CGS unit of energy

\(\mathrm{\frac{cm^{2}\,g}{s^{2}}}\)

No

eV

Electron Volt

\(\mathrm{1.6021766 \times 10^{-19}\,J}\)

electronvolt

Yes

F

Farad: electrical capacitance

\(\mathrm{\frac{C}{V}}\)

Farad, farad

No

g

gram (g)

\(\mathrm{0.001\,kg}\)

gram

No

gyr

billion years, AMUSE compatibility.

\(\mathrm{Gyr}\)

No

Hz

Frequency

\(\mathrm{\frac{1}{s}}\)

Hertz, hertz

Yes

J

Joule: energy

\(\mathrm{N\,m}\)

Joule, joule

No

julianyr

julian year, AMUSE compatibility

\(\mathrm{365.25\,d}\)

No

K

Kelvin: temperature with a null point at absolute zero.

Kelvin

No

kelvin

Kelvin, AMUSE compatibility

\(\mathrm{K}\)

No

kg

kilogram: base unit of mass in SI.

kilogram

No

kms

kilometer per seconds, AMUSE compatibility

\(\mathrm{\frac{km}{s}}\)

No

LSun

solar luminosity, AMUSE compatibility

\(\mathrm{L_{\odot}}\)

No

ly

light year, AMUSE compatibility

\(\mathrm{lyr}\)

No

m

meter: base unit of length in SI

meter

No

MEarth

Jupiter mass, AMUSE compatibility

\(\mathrm{M_{\oplus}}\)

No

metallicity

metallicity: base unit of metallicity in AMUSE

Yes

MJupiter

Jupiter mass, AMUSE compatibility

\(\mathrm{M_{\rm J}}\)

No

mol

mole: amount of a chemical substance in SI.

mole

No

MSun

solar mass, AMUSE compatibility

\(\mathrm{M_{\odot}}\)

No

N

Newton: force

\(\mathrm{\frac{kg\,m}{s^{2}}}\)

Newton, newton

No

object_key

object_key: base particle key unit in AMUSE

Yes

Pa

Pascal: pressure

\(\mathrm{\frac{J}{m^{3}}}\)

Pascal, pascal

No

pc

parsec: approximately 3.26 light-years.

\(\mathrm{3.0856776 \times 10^{16}\,m}\)

parsec

Yes

%

percent: one hundredth of unity, factor 0.01

\(\mathrm{0.01\,}\)

pct

No

pi

pi radians, AMUSE compatibility

\(\mathrm{3.1415927\,rad}\)

No

rad

radian: angular measurement of the ratio between the length on an arc and its radius

radian

No

REarth

Jupiter radius, AMUSE compatibility

\(\mathrm{R_{\oplus}}\)

No

rev

revolutions, AMUSE compatibility

\(\mathrm{6.2831853\,rad}\)

No

RJupiter

Jupiter radius, AMUSE compatibility

\(\mathrm{R_{\rm J}}\)

No

RSun

solar radius, AMUSE compatibility

\(\mathrm{R_{\odot}}\)

No

Ry

Rydberg: Energy of a photon whose wavenumber is the Rydberg constant

\(\mathrm{13.605693\,eV}\)

rydberg

No

s

second: base unit of time in SI.

second

No

S

Siemens: electrical conductance

\(\mathrm{\frac{A}{V}}\)

Siemens, siemens

No

sr

steradian: unit of solid angle in SI

\(\mathrm{rad^{2}}\)

steradian

No

stellar_type

stellar_type: base stellar type unit in AMUSE

Yes

string

string: base string unit in AMUSE

Yes

T

Tesla: magnetic flux density

\(\mathrm{\frac{Wb}{m^{2}}}\)

Tesla, tesla

No

V

Volt: electric potential or electromotive force

\(\mathrm{\frac{J}{C}}\)

Volt, volt

No

W

Watt: power

\(\mathrm{\frac{J}{s}}\)

Watt, watt

No

Wb

Weber: magnetic flux

\(\mathrm{V\,s}\)

Weber, weber

No

yr

year (yr)

\(\mathrm{365.25\,d}\)

year

Yes

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.

allclose(a, b[, rtol, atol, equal_nan])

Whether two arrays are element-wise equal within a tolerance.

beam_angular_area(beam_area)

Convert between the beam unit, which is commonly used to express the area of a radio telescope resolution element, and an area on the sky.

brightness_temperature(frequency[, beam_area])

Defines the conversion between Jy/sr 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.

isclose(a, b[, rtol, atol, equal_nan])

Return a boolean array where two arrays are element-wise equal within a tolerance.

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.

molar_mass_amu()

Returns the equivalence between amu and molar mass.

parallax()

Returns a list of equivalence pairs that handle the conversion between parallax angle and distance.

pixel_scale(pixscale)

Convert between pixel distances (in units of pix) and other units, given a particular pixscale.

plate_scale(platescale)

Convert between lengths (to be interpreted as lengths in the focal plane) and angular units with a specified platescale.

quantity_input([func])

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, Rankine 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.

thermodynamic_temperature(frequency[, T_cmb])

Defines the conversion between Jy/sr and “thermodynamic temperature”, \(T_{CMB}\), in Kelvins.

with_H0([H0])

Convert between quantities with little-h and the equivalent physical units.

zero_point_flux(flux0)

An equivalency for converting linear flux units (“maggys”) defined relative to a standard source into a standardized system.

Classes

CompositeUnit(scale, bases, powers[, …])

Create a composite unit using expressions of previously defined units.

Decibel(value[, unit, dtype, copy, order, …])

DecibelUnit([physical_unit, function_unit])

Logarithmic physical units expressed in dB

Dex(value[, unit, dtype, copy, order, …])

DexUnit([physical_unit, function_unit])

Logarithmic physical units expressed in magnitudes

FunctionQuantity(value[, unit, dtype, copy, …])

A representation of a (scaled) function of a number with a unit.

FunctionUnitBase([physical_unit, function_unit])

Abstract base class for function units.

IrreducibleUnit(st[, doc, format, namespace])

Irreducible units are the units that all other units are defined in terms of.

LogQuantity(value[, unit, dtype, copy, …])

A representation of a (scaled) logarithm of a number with a unit

LogUnit([physical_unit, function_unit])

Logarithmic unit containing a physical one

MagUnit([physical_unit, function_unit])

Logarithmic physical units expressed in magnitudes

Magnitude(value[, unit, dtype, copy, order, …])

NamedUnit(st[, doc, format, namespace])

The base class of units that have a name.

PrefixUnit(s[, represents, format, …])

A unit that is simply a SI-prefixed version of another unit.

Quantity(value[, unit, dtype, copy, order, …])

A Quantity represents a number with some associated unit.

QuantityInfo([bound])

Container for meta information like name, description, format.

QuantityInfoBase([bound])

SpecificTypeQuantity(value[, unit, dtype, …])

Superclass for Quantities of specific physical type.

Unit(s[, represents, format, namespace, …])

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.

UnitTypeError

Used specifically for errors in setting to units not allowed by a class.

UnitsError

The base class for unit-specific exceptions.

UnitsWarning

The base class for unit-specific warnings.

UnrecognizedUnit(st[, doc, format, namespace])

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.quantity.QuantityInfo, astropy.units.quantity.QuantityInfoBase, astropy.units.quantity.SpecificTypeQuantity, astropy.units.core.Unit, astropy.units.core.UnitBase, astropy.units.core.UnitConversionError, astropy.units.core.UnitTypeError, astropy.units.core.UnitsError, astropy.units.core.UnitsWarning, astropy.units.core.UnrecognizedUnit