get_physical_type

astropy.units.get_physical_type(obj)[源代码]

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

参数
obj :类似数量的或 PhysicalType -喜欢类数量或

(隐式或显式)具有相应物理类型的对象。该对象可以是单元、 Quantity ,一个可以转换为 Quantity (如数字或数组)、包含物理类型名称的字符串或 PhysicalType 实例。

返回
PhysicalType

设备物理类型的表示。

实例

物理类型可以从单元或 Quantity

>>> import astropy.units as u
>>> u.get_physical_type(u.meter ** -2)
PhysicalType('column density')
>>> u.get_physical_type(0.62 * u.barn * u.Mpc)
PhysicalType('volume')

物理类型也可以通过提供 str 包含物理类型名称的。

>>> u.get_physical_type("energy")
PhysicalType({'energy', 'torque', 'work'})

数字和数字数组对应于无量纲的物理类型。

>>> u.get_physical_type(1)
PhysicalType('dimensionless')