Units#
Units are measures of dimensions: metres for length, seconds for time, joules for energy. unxt.units provides two functions, both re-exported on the top-level unxt namespace.
Function |
Purpose |
|---|---|
|
Construct a unit. |
|
Return the unit of an object, or |
Both are multiple-dispatch functions; the registered signatures are listed in the API reference.
>>> import unxt as u
>>> u.unit
<multiple-dispatch function unit (...)>
>>> u.unit_of
<multiple-dispatch function unit_of (...)>
unit#
Accepts a string or an existing unit object; the unit backend is astropy.units, so the returned object is an astropy Unit.
>>> m = u.unit('m') # from a str
>>> m
Unit("m")
>>> u.unit(m) # from a unit object
Unit("m")
Units compose arithmetically:
>>> u.unit("km") / u.unit("h")
Unit("km / h")
unit_of#
Returns the unit of an object. Objects that carry no unit โ strings, for example โ return None.
>>> print(u.unit_of("m")) # strings have no units
None
>>> u.unit_of(m) # from a unit object
Unit("m")
>>> q = u.Q(5, 'm') # from a Quantity
>>> u.unit_of(q)
Unit("m")
See also#
Unit systems โ collections of base units used together.
Dimensions โ the physical nature a unit measures.