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
aliases | Returns the alias (long) names for this unit. |
bases | Return the bases of the unit. |
cgs | Returns a copy of the current Unit instance with CGS units. |
name | Returns the canonical (short) name associated with this unit. |
names | Returns all of the names associated with this unit. |
physical_type | Return the physical type on the unit. |
powers | Return the powers of the unit. |
scale | Return the scale of the unit. |
si | Returns a copy of the current Unit instance in SI units. |
Methods Summary
compose([equivalencies, units, max_depth, ...]) | Return the simplest possible composite unit(s) that represent the given unit. |
decompose([bases]) | Return a unit object composed of only irreducible units. |
find_equivalent_units([equivalencies, ...]) | Return a list of all the units that are the same type as the specified unit. |
get_converter(other[, equivalencies]) | Return the conversion function to convert values from self to the specified unit. |
in_units(other[, value, equivalencies]) | Alias for to for backward compatibility with pynbody. |
is_equivalent(other[, equivalencies]) | Returns True if this unit is equivalent to other. |
is_unity() | Returns True if the unit is unscaled and dimensionless. |
to(other[, value, equivalencies]) | Return the converted values in the specified unit. |
to_string([format]) | Output the unit in the given format as a string. |
to_system(system) | Converts this unit into ones belonging to the given system. |
Attributes Documentation
Return the physical type on the unit.
Examples
>>> from astropy import units as u
>>> print(u.m.physical_type)
length
Methods Documentation
Return the simplest possible composite unit(s) that represent the given unit. Since there may be multiple equally simple compositions of the unit, a list of units is always returned.
Parameters: | equivalencies : list of equivalence pairs, optional
units : set of units to compose to, optional
max_depth : int, optional
include_prefix_units : bool, optional
|
---|---|
Returns: | units : list of CompositeUnit
|
Return a unit object composed of only irreducible units.
Parameters: | bases : sequence of UnitBase, optional
|
---|---|
Returns: | unit : CompositeUnit object
|
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
units : set of units to search in, optional
include_prefix_units : bool, optional
|
---|---|
Returns: | units : list of UnitBase
|
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: | UnitsError :
|
Alias for to for backward compatibility with pynbody.
Returns True if this unit is equivalent to other.
Parameters: | other : unit object or string or tuple
equivalencies : list of equivalence pairs, optional
|
---|---|
Returns: | bool : |
Returns True if the unit is unscaled and dimensionless.
Return the converted values in the specified unit.
Parameters: | other : unit object or string
value : scalar int or float, or sequence convertable to array, optional
equivalencies : list of equivalence pairs, optional
|
---|---|
Returns: | values : scalar or array
|
Raises: | UnitsError :
|
Output the unit in the given format as a string.
Parameters: | format : astropy.format.Base instance or str
|
---|
Converts this unit into ones belonging to the given system. Since more than one result may be possible, a list is always returned.
Parameters: | system : module
|
---|---|
Returns: | units : list of CompositeUnit
|