set_enabled_units#

astropy.units.set_enabled_units(units)[源代码]#

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

使用时会搜索这些单位 UnitBase.find_equivalent_units 例如。

它可以永久使用,也可以作为上下文管理器使用 with 语句(见下面的示例)。

参数:
units : listsequencedict ,或 modulePYTHON:PYTHON:SEQUENCE、PYTHON:DICT或PYTHON:MODULE的列表

这是一个列表,其中可以找到单元(序列、指令或模块),或单元本身。整个集合将被“启用”,以便通过以下方法进行搜索 UnitBase.find_equivalent_unitsUnitBase.compose .

实例

>>> from astropy import units as u
>>> with u.set_enabled_units([u.pc]):
...     u.m.find_equivalent_units()
...
  Primary name | Unit definition | Aliases
[
  pc           | 3.08568e+16 m   | parsec  ,
]
>>> u.m.find_equivalent_units()
  Primary name | Unit definition | Aliases
[
  AU           | 1.49598e+11 m   | au, astronomical_unit            ,
  Angstrom     | 1e-10 m         | AA, angstrom                     ,
  cm           | 0.01 m          | centimeter                       ,
  earthRad     | 6.3781e+06 m    | R_earth, Rearth                  ,
  jupiterRad   | 7.1492e+07 m    | R_jup, Rjup, R_jupiter, Rjupiter ,
  lsec         | 2.99792e+08 m   | lightsecond                      ,
  lyr          | 9.46073e+15 m   | lightyear                        ,
  m            | irreducible     | meter                            ,
  micron       | 1e-06 m         |                                  ,
  pc           | 3.08568e+16 m   | parsec                           ,
  solRad       | 6.957e+08 m     | R_sun, Rsun                      ,
]