单位和数量 (astropy.units

介绍

astropy.units 处理用物理量(如米、秒、赫兹等)定义、转换和执行算术运算。它还处理对数单位,如幅值和分贝。

astropy.units 不知道球面几何或六边形(小时,分,秒):如果你想处理天体坐标,请参阅 astropy.coordinates 包裹。

入门

的大多数用户 astropy.units 程序包将与 Quantity objects :值和单位的组合。创建 Quantity 将一个值乘以或除以一个内置单位。它适用于标量、序列和 numpy 数组。

实例

创建一个 Quantity 对象:

>>> from astropy import units as u
>>> 42.0 * u.meter  
<Quantity  42. 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>

您可以从 Quantity 使用单位和值成员:

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

从这个基本构建块开始,可以开始将不同单位的数量组合起来:

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

单位转换是使用 to() 方法,它返回一个新的 Quantity 以给定的单位:

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

也可以直接使用较低级别的单位,例如,创建自定义单位:

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

“抵消”的单位成为称为“无量纲单位”的特殊单位:

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

创建基本 dimensionless quantity ,将值乘以未标度的无量纲单位:

>>> q = 1.0 * u.dimensionless_unscaled
>>> q.unit
Unit(dimensionless)

astropy.units 能够将复合单位与已知单位进行匹配:

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

它可以在单位制之间转换,如SI或CGS:

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

单位 magdexdB 是特别的,是 logarithmic units ,其中值是给定单位的物理量的对数。这些可以与括号中的物理单位一起使用,以创建相应的对数量:

>>> -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.438067627303133 dex(cm / s2)>

astropy.units 也可以处理 equivalencies 比如波长和频率之间的关系。为了使用该特性,等价对象被传递给 to() 转换方法。例如,从波长到频率的转换通常不起作用:

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

但是通过传递一个等价列表,在本例中 spectral() ,它确实:

>>> (1000 * u.nm).to(u.Hz, equivalencies=u.spectral())  
<Quantity  2.99792458e+14 Hz>

数量和单位可以是 printed nicely to strings 使用 Format String Syntax . 格式说明符(如 0.03f )将使用字符串格式设置数量值:

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

值和单位也可以单独格式化。单位的格式说明符可用于选择单位格式化程序:

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

致谢

此代码最初基于 pynbody units模块由andrewpontzen编写,他已经授予Astropy项目使用BSD许可证下的代码的权限。

也见

性能提示

如果你要将单位附加到数组 Quantity 数组中的对象被复制的速度会减慢。此外,如果将一个数组乘以一个复合单位,则每次乘法都会复制该数组。因此,在以下情况下,将连续复制数组四次:

In [1]: array = np.random.random(10000000)

In [2]: %timeit array * u.m / u.s / u.kg / u.sr
92.5 ms ± 2.52 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

有几种方法可以加快速度。首先,在使用复合单元时,请确保先对整个单元求值,然后将其附加到数组。您可以使用圆括号来执行此操作,就像对任何其他操作一样:

In [3]: %timeit array * (u.m / u.s / u.kg / u.sr)
21.5 ms ± 886 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

在这种情况下,这已经将速度提高了4倍。如果在代码中多次使用复合单元,另一种方法是在代码顶部为该单元创建一个常量,然后再使用它:

In [4]: UNIT_MSKGSR = u.m / u.s / u.kg / u.sr

In [5]: %timeit array * UNIT_MSKGSR
22.2 ms ± 551 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

在本例中以及带括号的情况下,在创建 Quantity . 如果您想完全避免复制,可以使用 << 操作员将设备连接到阵列:

In [6]: %timeit array << u.m / u.s / u.kg / u.sr
47.1 µs ± 5.77 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

请注意,这些现在 微秒 ,所以这是2000倍的速度比原来的案件没有括号。请注意,使用时不需要括号 << since * and / have a higher precedence, so the unit will be evaluated first. When using `` <<```,请注意,由于未复制数据,更改原始数组也会更改 Quantity 对象。

请注意,对于复合单元,如果可以预先计算组合单元,您肯定会看到影响:

In [7]: %timeit array << UNIT_MSKGSR
6.51 µs ± 112 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

比原来的例子快了1000倍。看到了吗 创建和转换无副本的数量 有关 << 操作员。

参考/API

astropy.units.数量模块

此模块定义 Quantity 对象,它表示具有某些关联单位的数字。 Quantity 对象支持与普通数类似的操作,但将在内部处理单位转换。

功能

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

两个数组在一个公差内是否元素相等。

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

返回一个布尔数组,其中两个数组在一个公差内元素上相等。

Classes

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

A Quantity 表示具有某个关联单位的数字。

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

特定物理类型数量的超类。

QuantityInfoBase([bound])

QuantityInfo([bound])

用于存储诸如名称、描述、格式等元信息的容器。

类继承图

Inheritance diagram of astropy.units.quantity.Quantity, astropy.units.quantity.SpecificTypeQuantity, astropy.units.quantity.QuantityInfoBase, astropy.units.quantity.QuantityInfo

astropy.units 包

此子包包含用于定义和转换不同物理单元的类和函数。

此代码改编自 pynbody units模块由andrewpontzen编写,他已经授予Astropy项目使用BSD许可证下的代码的权限。

功能

add_enabled_aliases \(别名)

为设备添加别名。

add_enabled_equivalencies \(等价物)

添加到单位注册表中启用的等效项。

add_enabled_units \(单位)

添加到在单位注册表中启用的单位集。

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

两个数组在一个公差内是否元素相等。

beam_angular_area(beam_area)

beam 单位,通常用来表示射电望远镜分辨率元素的面积和天空中的面积。

brightness_temperature(frequency[, beam_area])

定义Jy/sr和“亮度温度”之间的转换, \(T_B\) ,在凯尔文。

def_physical_type(unit, name)

添加设备和相应物理类型之间的映射。

def_unit(s[, represents, doc, format, ...])

定义新单位的工厂函数。

dimensionless_angles \()

允许角度等于无量纲(1 rad=1 m/m=1)。

doppler_optical \(休息)

返回速度光学约定的等效对。

doppler_radio \(休息)

返回速率的无线电约定的等效对。

doppler_redshift \()

返回多普勒红移(无单位)和径向速度之间的等值。

doppler_relativistic \(休息)

返回速度的相对论性约定的等价对。

get_current_unit_registry \()

get_physical_type \(OBJ)

返回与一个单元(或另一个物理类型表示)对应的物理类型。

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

返回一个布尔数组,其中两个数组在一个公差内元素上相等。

logarithmic \()

允许将对数单位转换为无量纲分数

mass_energy \()

返回处理质量和能量之间转换的等价对列表。

molar_mass_amu \()

返回amu和摩尔质量之间的等效值。

parallax \()

返回处理视差角度和距离之间转换的等效对列表。

pixel_scale \(像素比例)

在像素距离之间转换(单位为 pix )以及其他单位 pixscale .

plate_scale \(平台刻度)

在长度(被解释为焦平面中的长度)和角度单位之间转换 platescale .

quantity_input([func])

用于验证函数参数单位的修饰符。

set_enabled_aliases \(别名)

设置设备的别名。

set_enabled_equivalencies \(等价物)

设置在单元注册表中启用的等效项。

set_enabled_units \(单位)

设置单位注册表中启用的单位。

spectral \()

返回处理光谱波长、波数、频率和能量等效的等效对的列表。

spectral_density(wav[, factor])

返回处理与波长和频率有关的光谱密度的等效对列表。

temperature \()

在这里转换开尔文、摄氏度、兰金和华氏度,因为单位和合成单位不能正确地进行加减运算。

temperature_energy \()

在开尔文和keV(eV)之间换算成相等的量。

thermodynamic_temperature(frequency[, T_cmb])

定义了Jy/sr和“热力学温度”之间的转换, \(T_{{CMB}}\) ,在凯尔文。

zero_point_flux \(磁通0)

将相对于标准源定义的线性通量单位(“maggys”)转换为标准化系统的等效性。

Classes

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

使用先前定义的单位表达式创建一个复合单位。

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

DecibelUnit([physical_unit, function_unit])

对数物理单位,单位为分贝

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

DexUnit([physical_unit, function_unit])

以量值表示的对数物理单位

Equivalency(equiv_list[, name, kwargs])

单位等价物的容器。

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

用单位表示一个数的(标度)函数。

FunctionUnitBase([physical_unit, function_unit])

函数单元的抽象基类。

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

不可约单位是所有其他单位的定义单位。

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

用单位表示一个数的(标度的)对数

LogUnit([physical_unit, function_unit])

包含物理单位的对数单位

MagUnit([physical_unit, function_unit])

以量值表示的对数物理单位

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

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

具有名称的单元的基类。

PhysicalType(unit, physical_types)

表示在尺寸上与一组单位兼容的物理类型。

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

一种单位,它只是另一个单位的SI前缀形式。

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

A Quantity 表示具有某个关联单位的数字。

QuantityInfo([bound])

用于存储诸如名称、描述、格式等元信息的容器。

QuantityInfoBase([bound])

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

特定物理类型数量的超类。

StructuredUnit(units[, names])

结构数量单位的容器。

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

主单元类。

UnitBase \()

单位的抽象基类。

UnitConversionError 

专门用于与单位之间转换或根据其他单位解释单位有关的错误。

UnitTypeError 

专门用于设置类不允许的单位时出现的错误。

UnitsError 

特定于单元的异常的基类。

UnitsWarning 

单元特定警告的基类。

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

不能正确解析的单元。

类继承图

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.equivalencies.Equivalency, 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.physical.PhysicalType, astropy.units.core.PrefixUnit, astropy.units.quantity.Quantity, astropy.units.quantity.QuantityInfo, astropy.units.quantity.QuantityInfoBase, astropy.units.quantity.SpecificTypeQuantity, astropy.units.structured.StructuredUnit, 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

astropy.units.format包裹

不同单位格式的集合。

功能

get_format([format])

按名称获取格式化程序。

Classes

Base(*args, **kwargs)

所有单元格式的抽象基类。

Generic(*args, **kwargs)

“通用”格式。

CDS(*args, **kwargs)

支持 Centre de Données astronomiques de Strasbourg Standards for Astronomical Catalogues 2.0 格式,并且 complete set of supported units

Console(*args, **kwargs)

仅输出格式,以便在控制台上显示漂亮的格式。

Fits(*args, **kwargs)

符合标准单位格式。

Latex(*args, **kwargs)

根据IAU风格指南输出LaTeX以显示设备。

LatexInline(*args, **kwargs)

输出 Latex 显示单位基于IAU风格的指导方针与负功率。

OGIP(*args, **kwargs)

支援部队 Office of Guest Investigator Programs (OGIP) FITS files .

Unicode(*args, **kwargs)

只输出格式,以便在控制台上使用Unicode字符显示漂亮的格式。

Unscaled(*args, **kwargs)

不显示单位刻度部分的格式,除此之外,它与 Generic 格式。

VOUnit(*args, **kwargs)

VO使用的单位的IVOA标准。

类继承图

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模块

此软件包定义了国际单位制。它们也可以在 astropy.units 命名空间。

可用单位

单位

描述

代表

别名

SI前缀

a

年(a)

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

annum

是的

A

安培:国际单位制电流的基本单位

ampere, amp

是的

Angstrom

ångström:10**-10米

\(\mathrm{0.1\,nm}\)

AA, angstrom

是的

arcmin

弧分:角度测量

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

arcminute

是的

arcsec

弧秒:角度测量

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

arcsecond

是的

Bq

贝克勒尔:放射性单位

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

becquerel

C

库仑:电荷

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

coulomb

是的

cd

坎德拉:以国际单位制表示的发光强度的基本单位

candela

是的

Ci

居里:放射性单位

\(\mathrm{3.7 \times 10^{10}\,Bq}\)

curie

d

天(d)

\(\mathrm{24\,h}\)

day

是的

deg

度:角度测量1/360全旋转

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

degree

是的

deg_C

摄氏度

Celsius

eV

电子伏特

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

electronvolt

是的

F

法拉德:电容

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

Farad, farad

是的

fortnight

两星期

\(\mathrm{2\,wk}\)

g

克(g)

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

gram

是的

h

小时(h)

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

hour, hr

是的

H

亨利:电感

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

Henry, henry

是的

hourangle

小时角:全圆24度角测量

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

Hz

频率

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

Hertz, hertz

是的

J

焦耳:能量

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

Joule, joule

是的

K

开尔文:零点在绝对零度的温度。

Kelvin

是的

kg

千克:国际单位制的基本质量单位。

kilogram

l

升:公制体积单位

\(\mathrm{1000\,cm^{3}}\)

L, liter

是的

lm

流明:光通量

\(\mathrm{cd\,sr}\)

lumen

是的

lx

勒克斯:发光度

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

lux

是的

m

米:长度的基本单位,国际单位制

meter

是的

mas

微弧秒:角度测量

\(\mathrm{0.001\,{}^{\prime\prime}}\)

micron

微米:微米的别名(um)

\(\mathrm{\mu m}\)

min

分钟(min)

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

minute

是的

mol

摩尔:化学物质在国际单位制中的数量。

mole

是的

N

牛顿:力

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

Newton, newton

是的

Ohm

欧姆:电阻

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

ohm

是的

Pa

帕斯卡:压力

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

Pascal, pascal

是的

%

百分比:百分之一,系数0.01

\(\mathrm{0.01\,}\)

pct

rad

弧度:用角度量度一段弧的长度与半径之比

radian

是的

s

第二:国际单位制的基本时间单位。

second

是的

S

西门子:电导

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

Siemens, siemens

是的

sday

恒星日(sday)是地球自转一周的时间。

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

sr

甾体:国际单位制的立体角单位

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

steradian

是的

t

公吨

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

tonne

T

磁通量密度

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

Tesla, tesla

是的

uas

微弧秒:角度测量

\(\mathrm{1 \times 10^{-6}\,{}^{\prime\prime}}\)

V

伏:电势或电动势

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

Volt, volt

是的

W

瓦特:功率

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

Watt, watt

是的

Wb

韦伯:磁通量

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

Weber, weber

是的

wk

周(周)

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

week

yr

年(年)

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

year

是的

astropy.units.cgs模块

这个包定义了CGS单元。它们也可以在顶层使用 astropy.units 命名空间。

可用单位

单位

描述

代表

别名

SI前缀

abC

abcoulomb:电荷的CGS(EMU)

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

abcoulomb

Ba

巴耶:CGS压力单位

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

Barye, barye

是的

Bi

比奥:CGS(EMU)电流单位

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

Biot, abA, abampere

C

库仑:电荷

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

coulomb

cd

坎德拉:以国际单位制表示的发光强度的基本单位

candela

cm

厘米(cm)

\(\mathrm{cm}\)

centimeter

D

德拜:电偶极矩的CGS单位

\(\mathrm{3.3333333 \times 10^{-30}\,C\,m}\)

Debye, debye

是的

deg_C

摄氏度

Celsius

dyn

dyne:CGS力单位

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

dyne

是的

erg

erg:CGS能量单位

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

是的

Fr

富兰克林:CGS(ESU)计费单位

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

Franklin, statcoulomb, statC, esu

g

克(g)

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

gram

G

高斯:磁场的CGS单位

\(\mathrm{0.0001\,T}\)

Gauss, gauss

是的

Gal

Gal:CGS加速度单位

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

gal

是的

K

开尔文:零点在绝对零度的温度。

Kelvin

k

凯瑟:波数的CGS单位

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

Kayser, kayser

是的

mol

摩尔:化学物质在国际单位制中的数量。

mole

Mx

麦克斯韦:CGS磁通量单位

\(\mathrm{1 \times 10^{-8}\,Wb}\)

Maxwell, maxwell

P

泊:动态粘度的CGS单位

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

poise

是的

rad

弧度:用角度量度一段弧的长度与半径之比

radian

s

第二:国际单位制的基本时间单位。

second

sr

甾体:国际单位制的立体角单位

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

steradian

St

斯托克斯:运动粘度的CGS单位

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

stokes

是的

statA

斯塔坦佩雷:CGS(ESU)电流单位

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

statampere

astropy.units.astrophys公司模块

这个软件包定义了天体物理学的特定单位。它们也可以在 astropy.units 命名空间。

可用单位

单位

描述

代表

别名

SI前缀

adu

阿杜

是的

AU

天文单位:近似地球-太阳的平均距离。

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

au, astronomical_unit

是的

beam

是的

bin

箱子

是的

chan

是的

ct

计数(ct)

count

是的

DN

DN(DN)

dn

earthMass

地球质量

\(\mathrm{5.9721679 \times 10^{24}\,kg}\)

M_earth, Mearth

earthRad

地球半径

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

R_earth, Rearth

electron

电子数

jupiterMass

木星质量

\(\mathrm{1.8981246 \times 10^{27}\,kg}\)

M_jup, Mjup, M_jupiter, Mjupiter

jupiterRad

木星半径

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

R_jup, Rjup, R_jupiter, Rjupiter

Jy

詹斯基:光谱通量密度

\(\mathrm{1 \times 10^{-26}\,\frac{W}{Hz\,m^{2}}}\)

Jansky, jansky

是的

lsec

光秒

\(\mathrm{2.9979246 \times 10^{8}\,m}\)

lightsecond

lyr

光年

\(\mathrm{9.4607305 \times 10^{15}\,m}\)

lightyear

是的

pc

帕塞克:大约3.26光年。

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

parsec

是的

ph

光子(ph)

photon

是的

R

瑞利:光子通量

\(\mathrm{7.9577472 \times 10^{8}\,\frac{ph}{s\,sr\,m^{2}}}\)

Rayleigh, rayleigh

是的

Ry

里德堡:波数为里德堡常数的光子的能量

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

rydberg

是的

solLum

太阳亮度

\(\mathrm{3.828 \times 10^{26}\,W}\)

L_sun, Lsun

solMass

太阳质量

\(\mathrm{1.9884099 \times 10^{30}\,kg}\)

M_sun, Msun

solRad

太阳半径

\(\mathrm{6.957 \times 10^{8}\,m}\)

R_sun, Rsun

Sun

太阳

Asterpy.units.misc模块

此程序包定义了其他单位。它们也可以在 astropy.units 命名空间。

可用单位

单位

描述

代表

别名

SI前缀

bar

巴:压力

\(\mathrm{100000\,Pa}\)

是的

barn

谷仓:HEP使用的面积单位

\(\mathrm{1 \times 10^{-28}\,m^{2}}\)

barn

是的

bit

b(位)

b

是的

byte

B(字节)

\(\mathrm{8\,bit}\)

B

是的

cycle

周期:角度测量,一个完整的旋转或旋转

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

cy

M_e

电子质量

\(\mathrm{9.1093837 \times 10^{-31}\,kg}\)

M_p

质子质量

\(\mathrm{1.6726219 \times 10^{-27}\,kg}\)

pix

像素(像素)

pixel

是的

spat

spat:球体的立体角,4pi sr

\(\mathrm{12.566371\,sr}\)

sp

Torr

现在定义的绝对气压单位是760/a

\(\mathrm{133.32237\,Pa}\)

torr

是的

u

统一原子质量单位

\(\mathrm{1.6605391 \times 10^{-27}\,kg}\)

Da, Dalton

是的

vox

体素

voxel

是的

astropy.units.function.函数.单元模块

这个包定义了也可以作为其他单元的函数使用的单元。如果被调用,它们的参数用于初始化相应的功能单元(例如。, u.mag(u.ct/u.s) ). 请注意,不能调用带前缀的版本,因为不清楚是什么,例如。, u.mmag(u.ct/u.s) 意味着。

可用单位

单位

描述

代表

别名

SI前缀

dB

分贝:每以10为基数的对数单位为10

\(\mathrm{0.1\,dex}\)

decibel

dex

Dex:以10为底的对数单位

mag

天文震级:每10个对数单位为2.5

\(\mathrm{-0.4\,dex}\)

是的

astropy.units.光度学模块

本模块定义幅值零点和相关光度控制量。

每个单元的描述中给出了相应的震级(实际定义见 logarithmic

可用单位

单位

描述

代表

别名

SI前缀

AB

AB magnitude零磁通密度(magnitude ABmag

\(\mathrm{3.6307805 \times 10^{-20}\,\frac{erg}{Hz\,s\,cm^{2}}}\)

ABflux

Bol

对应于绝对热计量震级0(量级)的光度 M_bol

\(\mathrm{3.0128 \times 10^{28}\,W}\)

L_bol

bol

对应于appparent热计量震级0(震级)的辐照度 m_bol

\(\mathrm{2.3975101 \times 10^{25}\,\frac{W}{pc^{2}}}\)

f_bol

mgy

磁通量的线性单位是对象。到将其连接到特定的校准单位系统上,应使用零点通量当量。

maggy

是的

ST

ST magnitude零磁通密度(magnitude STmag

\(\mathrm{3.6307805 \times 10^{-9}\,\frac{erg}{\mathring{A}\,s\,cm^{2}}}\)

STflux

功能

zero_point_flux \(磁通0)

将相对于标准源定义的线性通量单位(“maggys”)转换为标准化系统的等效性。

astropy.units.英制模块

这个软件包定义了常用的英制单位。它们在 astropy.units.imperial 命名空间,但不在顶层 astropy.units 命名空间,例如:

>>> import astropy.units as u
>>> mph = u.imperial.mile / u.hour
>>> mph
Unit("mi / h")

把他们包括在 compose 以及 find_equivalent_units DO::

>>> import astropy.units as u
>>> u.imperial.enable()  
可用单位

单位

描述

代表

别名

SI前缀

ac

国际英亩

\(\mathrm{43560\,ft^{2}}\)

acre

BTU

英制热量单位

\(\mathrm{1.0550559\,kJ}\)

btu

cal

热化学热量:前国际单位制的能量单位

\(\mathrm{4.184\,J}\)

calorie

cup

U、 美国。

\(\mathrm{0.5\,pint}\)

deg_F

华氏度

Fahrenheit

deg_R

朗肯标度:热力学温度的绝对标度

Rankine

foz

U、 美国。

\(\mathrm{0.125\,cup}\)

fluid_oz, fluid_ounce

ft

国际脚

\(\mathrm{12\,inch}\)

foot

fur

弗隆

\(\mathrm{660\,ft}\)

furlong

gallon

U、 美国。

\(\mathrm{3.7854118\,\mathcal{l}}\)

hp

电马力

\(\mathrm{745.69987\,W}\)

horsepower

inch

国际英寸

\(\mathrm{2.54\,cm}\)

kcal

卡路里:对卡路里的俗语定义

\(\mathrm{1000\,cal}\)

Cal, Calorie, kilocal, kilocalorie

kip

千磅:力

\(\mathrm{1000\,lbf}\)

kilopound

kn

航海速度单位:每小时1海里

\(\mathrm{\frac{nmi}{h}}\)

kt, knot, NMPH

lb

国际单位磅:质量

\(\mathrm{16\,oz}\)

lbm, pound

lbf

Pound:力

\(\mathrm{\frac{ft\,slug}{s^{2}}}\)

mi

国际英里

\(\mathrm{5280\,ft}\)

mile

mil

千分之一英寸

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

thou

nmi

海里

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

nauticalmile, NM

oz

国际重量级盎司:质量

\(\mathrm{28.349523\,g}\)

ounce

pint

U、 美国。

\(\mathrm{0.5\,quart}\)

psi

磅/平方英寸:压力

\(\mathrm{\frac{lbf}{inch^{2}}}\)

quart

U、 美国。

\(\mathrm{0.25\,gallon}\)

slug

弹头:质量

\(\mathrm{32.174049\,lb}\)

st

国际重量级宝石:质量

\(\mathrm{14\,lb}\)

stone

tbsp

U、 美国。

\(\mathrm{0.5\,foz}\)

tablespoon

ton

国际单位吨:质量

\(\mathrm{2000\,lb}\)

tsp

U、 美国。

\(\mathrm{0.33333333\,tbsp}\)

teaspoon

yd

国际货场

\(\mathrm{3\,ft}\)

yard

功能

enable \()

启用英制单位,使其显示在结果中 find_equivalent_unitscompose .

cds.astropy单位模块

此软件包定义了CDS格式中使用的单位,这两个单位都是在中定义的单位 Centre de Données astronomiques de Strasbourg Standards for Astronomical Catalogues 2.0 格式和 complete set of supported units 。VOTABLE直到1.2版都使用此格式。

这些单元在顶级中不可用 astropy.units 命名空间。要使用这些单位,必须导入 astropy.units.cds 模块:

>>> from astropy.units import cds
>>> q = 10. * cds.lyr  

把他们包括在 compose 以及 find_equivalent_units DO::

>>> from astropy.units import cds
>>> cds.enable()  
可用单位

单位

描述

代表

别名

SI前缀

%

百分比

\(\mathrm{\%}\)

---

无量纲无标度

\(\mathrm{}\)

-

\h

普朗克常数

\(\mathrm{6.6260701 \times 10^{-34}\,J\,s}\)

是的

A

安培

\(\mathrm{A}\)

是的

a

\(\mathrm{a}\)

是的

a0

玻尔半径

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

是的

AA

\(\mathrm{\mathring{A}}\)

Å, Angstrom, Angstroem

是的

al

光年

\(\mathrm{lyr}\)

是的

alpha

精细结构常数

\(\mathrm{0.0072973526\,}\)

是的

arcmin

弧分

\(\mathrm{{}^{\prime}}\)

arcm

是的

arcsec

弧秒

\(\mathrm{{}^{\prime\prime}}\)

arcs

是的

atm

气氛

\(\mathrm{101325\,Pa}\)

是的

AU

天文单位

\(\mathrm{AU}\)

au

是的

bar

酒吧

\(\mathrm{bar}\)

是的

barn

谷仓

\(\mathrm{barn}\)

是的

bit

一点

\(\mathrm{bit}\)

是的

byte

字节

\(\mathrm{byte}\)

是的

C

库仑

\(\mathrm{C}\)

是的

c

光速

\(\mathrm{2.9979246 \times 10^{8}\,\frac{m}{s}}\)

是的

cal

卡路里

\(\mathrm{4.1854\,J}\)

是的

cd

坎德拉

\(\mathrm{cd}\)

是的

Crab

蟹状(X射线)通量

是的

ct

计数

\(\mathrm{ct}\)

是的

D

德拜(偶极子)

\(\mathrm{D}\)

是的

d

朱利安节

\(\mathrm{d}\)

是的

deg

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

°, degree

是的

dyn

达因

\(\mathrm{dyn}\)

是的

e

电子电荷

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

是的

eps0

电常数

\(\mathrm{8.8541878 \times 10^{-12}\,\frac{F}{m}}\)

是的

erg

erg公司

\(\mathrm{erg}\)

是的

eV

电子伏特

\(\mathrm{eV}\)

是的

F

法拉德

\(\mathrm{F}\)

是的

G

引力常数

\(\mathrm{6.6743 \times 10^{-11}\,\frac{m^{3}}{kg\,s^{2}}}\)

是的

g

\(\mathrm{g}\)

是的

gauss

高斯

\(\mathrm{G}\)

是的

geoMass

地球质量

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

Mgeo

是的

H

亨利

\(\mathrm{H}\)

是的

h

小时

\(\mathrm{h}\)

是的

hr

小时

\(\mathrm{h}\)

是的

Hz

赫兹

\(\mathrm{Hz}\)

是的

inch

英寸

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

是的

J

焦耳

\(\mathrm{J}\)

是的

JD

朱利安节

\(\mathrm{d}\)

是的

jovMass

木星质量

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

Mjup

是的

Jy

詹斯基

\(\mathrm{Jy}\)

是的

K

开尔文

\(\mathrm{K}\)

是的

k

玻尔兹曼

\(\mathrm{1.380649 \times 10^{-23}\,\frac{J}{K}}\)

是的

l

\(\mathrm{\mathcal{l}}\)

是的

lm

流明

\(\mathrm{lm}\)

是的

Lsun

太阳光度

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

solLum

是的

lx

勒克斯

\(\mathrm{lx}\)

是的

lyr

光年

\(\mathrm{lyr}\)

是的

m

\(\mathrm{m}\)

是的

mag

震级

\(\mathrm{mag}\)

是的

mas

毫秒弧

\(\mathrm{marcsec}\)

me

电子质量

\(\mathrm{9.1093837 \times 10^{-31}\,kg}\)

是的

min

分钟

\(\mathrm{min}\)

是的

MJD

朱利安节

\(\mathrm{d}\)

是的

mmHg

毫米汞柱

\(\mathrm{133.32239\,Pa}\)

是的

mol

鼹鼠

\(\mathrm{mol}\)

是的

mp

质子质量

\(\mathrm{1.6726219 \times 10^{-27}\,kg}\)

是的

Msun

太阳质量

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

solMass

是的

mu0

磁常数

\(\mathrm{1.2566371 \times 10^{-6}\,\frac{N}{A^{2}}}\)

µ0

是的

muB

玻尔磁子

\(\mathrm{9.2740101 \times 10^{-24}\,\frac{J}{T}}\)

是的

N

牛顿

\(\mathrm{N}\)

是的

Ohm

欧姆

\(\mathrm{\Omega}\)

是的

Pa

帕斯卡

\(\mathrm{Pa}\)

是的

pc

帕秒

\(\mathrm{pc}\)

是的

ph

光子

\(\mathrm{ph}\)

是的

pi

π

\(\mathrm{3.1415927\,}\)

是的

pix

象素

\(\mathrm{pix}\)

是的

ppm

百万分之几

\(\mathrm{1 \times 10^{-6}\,}\)

是的

R

气体常数

\(\mathrm{8.3144626\,\frac{J}{K\,mol}}\)

是的

rad

弧度

\(\mathrm{rad}\)

是的

Rgeo

地球赤道半径

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

是的

Rjup

木星赤道半径

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

是的

Rsun

太阳半径

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

solRad

是的

Ry

里德堡

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

是的

S

西门子

\(\mathrm{S}\)

是的

s

第二

\(\mathrm{s}\)

sec

是的

sr

甾体

\(\mathrm{sr}\)

是的

Sun

太阳能装置

\(\mathrm{Sun}\)

是的

T

特斯拉

\(\mathrm{T}\)

是的

t

公吨

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

是的

u

原子质量

\(\mathrm{1.6605391 \times 10^{-27}\,kg}\)

是的

V

伏特

\(\mathrm{V}\)

是的

W

瓦特

\(\mathrm{W}\)

是的

Wb

韦伯

\(\mathrm{Wb}\)

是的

yr

\(\mathrm{a}\)

是的

µas

微秒弧

\(\mathrm{\mu arcsec}\)

功能

enable \()

启用CDS单元,使其显示在结果中 find_equivalent_unitscompose .

astropy.units.等效模块

一组标准的天文等价物。

功能

parallax \()

返回处理视差角度和距离之间转换的等效对列表。

spectral \()

返回处理光谱波长、波数、频率和能量等效的等效对的列表。

spectral_density(wav[, factor])

返回处理与波长和频率有关的光谱密度的等效对列表。

doppler_radio \(休息)

返回速率的无线电约定的等效对。

doppler_optical \(休息)

返回速度光学约定的等效对。

doppler_relativistic \(休息)

返回速度的相对论性约定的等价对。

doppler_redshift \()

返回多普勒红移(无单位)和径向速度之间的等值。

mass_energy \()

返回处理质量和能量之间转换的等价对列表。

brightness_temperature(frequency[, beam_area])

定义Jy/sr和“亮度温度”之间的转换, \(T_B\) ,在凯尔文。

thermodynamic_temperature(frequency[, T_cmb])

定义了Jy/sr和“热力学温度”之间的转换, \(T_{{CMB}}\) ,在凯尔文。

beam_angular_area(beam_area)

beam 单位,通常用来表示射电望远镜分辨率元素的面积和天空中的面积。

dimensionless_angles \()

允许角度等于无量纲(1 rad=1 m/m=1)。

logarithmic \()

允许将对数单位转换为无量纲分数

temperature \()

在这里转换开尔文、摄氏度、兰金和华氏度,因为单位和合成单位不能正确地进行加减运算。

temperature_energy \()

在开尔文和keV(eV)之间换算成相等的量。

molar_mass_amu \()

返回amu和摩尔质量之间的等效值。

pixel_scale \(像素比例)

在像素距离之间转换(单位为 pix )以及其他单位 pixscale .

plate_scale \(平台刻度)

在长度(被解释为焦平面中的长度)和角度单位之间转换 platescale .

Classes

Equivalency(equiv_list[, name, kwargs])

单位等价物的容器。

类继承图

Inheritance diagram of astropy.units.equivalencies.Equivalency

astropy.units.function.函数包裹

此子包包含用于定义和转换不同功能单位和数量的类和函数,即使用物理单位的某些功能的单位,例如震级和分贝。

Classes

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

DecibelUnit([physical_unit, function_unit])

对数物理单位,单位为分贝

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

DexUnit([physical_unit, function_unit])

以量值表示的对数物理单位

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

用单位表示一个数的(标度)函数。

FunctionUnitBase([physical_unit, function_unit])

函数单元的抽象基类。

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

用单位表示一个数的(标度的)对数

LogUnit([physical_unit, function_unit])

包含物理单位的对数单位

MagUnit([physical_unit, function_unit])

以量值表示的对数物理单位

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

类继承图

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

astropy.units.function.函数.对数模

Classes

LogUnit([physical_unit, function_unit])

包含物理单位的对数单位

MagUnit([physical_unit, function_unit])

以量值表示的对数物理单位

DexUnit([physical_unit, function_unit])

以量值表示的对数物理单位

DecibelUnit([physical_unit, function_unit])

对数物理单位,单位为分贝

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

用单位表示一个数的(标度的)对数

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

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

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

变量

STmag 

ST震级:STmag=-21.1对应于1 erg/s/cm2/A

ABmag 

AB幅值:ABmag=-48.6对应于1 erg/s/cm2/Hz

M_bol 

绝对热辐射量值:M_bol=0对应于L_bol0=3.0128e+28 J/s

m_bol 

表观热辐射量值:m_bol=0对应于f_bol0=2.51802e-08 kg/s3

类继承图

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

astropy.units.已弃用模块

此包定义了不推荐使用的单元。

这些单元在顶级中不可用 astropy.units 命名空间。要使用这些单位,必须导入 astropy.units.deprecated 模块:

>>> from astropy.units import deprecated
>>> q = 10. * deprecated.emu  

把他们包括在 compose 以及 find_equivalent_units DO::

>>> from astropy.units import deprecated
>>> deprecated.enable()  
可用单位

单位

描述

代表

别名

SI前缀

emu

比奥:CGS(EMU)电流单位

\(\mathrm{Bi}\)

前缀 earthMass

地球质量前缀

\(\mathrm{5.9721679 \times 10^{24}\,kg}\)

M_earth, Mearth

只有

前缀 earthRad

地球半径前缀

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

R_earth, Rearth

只有

前缀 jupiterMass

木星质量前缀

\(\mathrm{1.8981246 \times 10^{27}\,kg}\)

M_jup, Mjup, M_jupiter, Mjupiter

只有

前缀 jupiterRad

木星半径前缀

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

R_jup, Rjup, R_jupiter, Rjupiter

只有

功能

enable \()

启用不推荐使用的单位,以便它们出现在 find_equivalent_unitscompose .

astropy.units.需要模块

此软件包定义了VOUnit标准要求的SI前缀单位,但这些单位在实践中很少使用,并且容易导致混淆(例如 msolMass 百万太阳质量)。它们在一个独立的模块中 astropy.units.deprecated 因为它们需要在默认情况下为 astropy.units 解析兼容的VOUnit字符串。因此,例如。, Unit('msolMass') 将只是工作,但要直接访问单元,请使用 astropy.units.required_by_vounit.msolMass 而不是无前缀单元可能使用的更典型的习惯用法, astropy.units.solMass .

可用单位

单位

描述

代表

别名

SI前缀

前缀 solLum

日光亮度前缀

\(\mathrm{3.828 \times 10^{26}\,W}\)

L_sun, Lsun

只有

前缀 solMass

太阳质量前缀

\(\mathrm{1.9884099 \times 10^{30}\,kg}\)

M_sun, Msun

只有

前缀 solRad

太阳半径前缀

\(\mathrm{6.957 \times 10^{8}\,m}\)

R_sun, Rsun

只有