Unit

class simtk.unit.unit.Unit(base_or_scaled_units)

Physical unit such as meter or ampere.

__init__(base_or_scaled_units)

Create a new Unit.

Parameters:
  • self (Unit) – The newly created Unit.
  • base_or_scaled_units (dict) – Keys are BaseUnits or ScaledUnits. Values are exponents (numbers).

Methods

__init__(base_or_scaled_units) Create a new Unit.
conversion_factor_to(other) Returns conversion factor for computing all of the common dimensions between self and other from self base units to other base units.
create_unit(scale, name, symbol) Convenience method for creating a new simple unit from another simple unit.
get_conversion_factor_to_base_units() There may be ScaleUnit components to this Unit.
get_name() Returns a unit name (string) for this Unit, composed of its various BaseUnit symbols.
get_symbol() Returns a unit symbol (string) for this Unit, composed of its various BaseUnit symbols.
in_unit_system(system) Returns a new Unit with the same dimensions as this one, expressed in a particular unit system.
is_compatible(other) Returns True if two Units share the same dimension.
is_dimensionless() Returns True if this Unit has no dimensions.
iter_all_base_units() Yields (BaseUnit, exponent) tuples comprising this unit, including those BaseUnits found within ScaledUnits.
iter_base_dimensions() Yields (BaseDimension, exponent) tuples comprising this unit.
iter_base_or_scaled_units()
iter_scaled_units()
iter_top_base_units() Yields (BaseUnit, exponent) tuples in this Unit, excluding those within BaseUnits.
sqrt() Returns square root of a unit.
create_unit(scale, name, symbol)

Convenience method for creating a new simple unit from another simple unit. Both units must consist of a single BaseUnit.

iter_base_dimensions()

Yields (BaseDimension, exponent) tuples comprising this unit.

iter_all_base_units()

Yields (BaseUnit, exponent) tuples comprising this unit, including those BaseUnits found within ScaledUnits.

There might be multiple BaseUnits with the same dimension.

iter_top_base_units()

Yields (BaseUnit, exponent) tuples in this Unit, excluding those within BaseUnits.

get_conversion_factor_to_base_units()

There may be ScaleUnit components to this Unit. Returns conversion factor to the set of BaseUnits returned by iter_all_base_units().

Units comprised of only BaseUnits return 1.0

__lt__(other)

Compare two Units.

Raises a TypeError if the units have different dimensions.

Returns True if self < other, False otherwise.

__hash__()

Compute a hash code for this object.

__truediv__(other)

Divide a Unit by another object.

Returns a composite Unit if other is another Unit.

Returns a Quantity otherwise. UNLESS other is a Quantity AND the resulting unit type is dimensionless, in which case the underlying value type of the Quantity is returned.

__div__(other)

Divide a Unit by another object.

Returns a composite Unit if other is another Unit.

Returns a Quantity otherwise. UNLESS other is a Quantity AND the resulting unit type is dimensionless, in which case the underlying value type of the Quantity is returned.

__pow__(exponent)

Raise a Unit to a power.

Returns a new Unit with different exponents on the BaseUnits.

sqrt()

Returns square root of a unit.

Raises ArithmeticError if component exponents are not even. This behavior can be changed if you present a reasonable real life case to me.

__str__()

Returns the human-readable name of this unit

__repr__()

Returns a unit name (string) for this Unit, composed of its various BaseUnit symbols. e.g. ‘kilogram meter**2 second**-1’

is_compatible(other)

Returns True if two Units share the same dimension. Returns False otherwise.

is_dimensionless()

Returns True if this Unit has no dimensions. Returns False otherwise.

conversion_factor_to(other)

Returns conversion factor for computing all of the common dimensions between self and other from self base units to other base units.

The two units need not share all of the same dimensions. In case they do not, the conversion factor applies only to the BaseUnits of self that correspond to different BaseUnits in other.

This method requires strict compatibility between the two units.

in_unit_system(system)

Returns a new Unit with the same dimensions as this one, expressed in a particular unit system.

Strips off any ScaledUnits in the Unit, leaving only BaseUnits.

Parameters:system (a dictionary of (BaseDimension, BaseUnit) pairs) –
get_symbol()

Returns a unit symbol (string) for this Unit, composed of its various BaseUnit symbols. e.g. ‘kg m**2 s**-1’

get_name()

Returns a unit name (string) for this Unit, composed of its various BaseUnit symbols. e.g. ‘kilogram meter**2 secon**-1’.