Bases: object
Abstract base class for units.
Most of the arithmetic operations on units are defined in this base class.
Should not be instantiated by users directly.
Attributes Summary
physical_type | Return the physical type on the unit. |
Methods Summary
is_dimensionless() | Returns True if this unit translates into a scalar quantity without a unit. |
get_converter(other[, equivalencies]) | Return the conversion function to convert values from self to the specified unit. |
to(other[, value, equivalencies]) | Return the converted values in the specified unit. |
simplify() | Compresses a possibly composite unit down to a single instance. |
is_equivalent(other[, equivalencies]) | Returns True if this unit is equivalent to other. |
find_equivalent_units([equivalencies]) | Return a list of all the units that are the same type as the specified unit. |
to_string([format]) | Output the unit in the given format as a string. |
decompose() | Return a unit object composed of only irreducible units. |
in_units(other[, value, equivalencies]) | Alias for to for backward compatibility with pynbody. |
Attributes Documentation
Return the physical type on the unit.
Examples
>>> u.m.physical_type
'length'
Methods Documentation
Returns True if this unit translates into a scalar quantity without a unit.
Examples
>>> ((2 * u.m) / (3 * u.m)).is_dimensionless()
True
>>> (2 * u.m).is_dimensionless()
False
Return the conversion function to convert values from self to the specified unit.
Parameters : | other : unit object or string
equivalencies : list of equivalence pairs, optional
|
---|---|
Returns : | func : callable
|
Raises : | UnitsException :
|
Return the converted values in the specified unit.
Parameters : | other : unit object or string
value : scalar int or float, or sequence that can be converted to array, optional
equivalencies : list of equivalence pairs, optional
|
---|---|
Returns : | values : scalar or array
|
Raises : | UnitException :
|
Compresses a possibly composite unit down to a single instance.
Returns True if this unit is equivalent to other.
Parameters : | other : unit object or string
equivalencies : list of equivalence pairs, optional
|
---|---|
Returns : | bool : |
Return a list of all the units that are the same type as the specified unit.
Parameters : | u : Unit instance or string
equivalencies : list of equivalence pairs, optional
|
---|---|
Returns : | units : list of UnitBase
|
Output the unit in the given format as a string.
Parameters : | format : astropy.format.Base instance or str
|
---|
Return a unit object composed of only irreducible units.
Parameters : | None : |
---|---|
Returns : | unit : CompositeUnit object
|
Alias for to for backward compatibility with pynbody.