Unit
- class Unit
Description
A concrete amount of quantity to measure the values of quantities of the same kind.
This provides distinction between, e.g.
kmandm.Format specification is:
:r- print unit reference, e.g. non-prefixed unit:b- print unit in base units:n- print unit name, including any prefix
By default, prints the unit symbol with optional prefix, or its expression if the unit is unnamed.
Inheritance:
Children
Members defined in
Unit(22 members)RFactor to scale the quantity by relative to type.
RWhether this unit can be prefixed.
RWhether this unit is prefixed.
RQuantity metadata of this unit.
RName given to this unit.
RPrefix associated with this unit.
RUnit this is a (named) reference of.
RSymbol given to this unit.
RValue of the type when this is equal to 0.0.
Convert this unit to prefixable.
Expression of this units as its base units.
Whether
otherunit is convertible to this, i.e. whether their types are equal.Convert absolute base
valueto this unit’s absolute numerical representation.Convert base
valuerelative to some origin to this unit’s numerical representation relative to the same origin.Find or create a new base unit for
kind.Get a dimensionless unit
oneFind or create a new prefixed unit.
Convert absolute
valueto absolute base units numerically.Convert
valuerelative to some origin to base units relative to the same origin numerically.Attributes
- property factor: float
Factor to scale the quantity by relative to type.
For base units, this will be equal to 1.0.
- property is_prefixable: bool
Whether this unit can be prefixed.
Only named units without a prefix can be prefixed.
- property kind: syside.experimental.units.Kind
Quantity metadata of this unit.
- property prefix: syside.experimental.units.Prefix | None
Prefix associated with this unit.
- property reference_unit: syside.experimental.units.Unit | None
Unit this is a (named) reference of.
- property symbol: str | None
Symbol given to this unit.
This is what is used in quantity formatting. Note that this does not include prefix.
Methods
- as_prefixable() syside.experimental.units.PrefixableUnit
Convert this unit to prefixable.
Raises
ValueErrorif this unit cannot be prefixed.
- base() list[tuple[syside.experimental.units.Unit, fractions.Fraction]]
Expression of this units as its base units.
- convertible_from(arg: syside.experimental.units.Unit, /) bool
Whether
otherunit is convertible to this, i.e. whether their types are equal.
- from_absolute_base(arg: float, /) float
Convert absolute base
valueto this unit’s absolute numerical representation.
- from_relative_base(arg: float, /) float
Convert base
valuerelative to some origin to this unit’s numerical representation relative to the same origin.
- static named(name: str, symbol: str, kind: syside.experimental.units.Kind, space_before_symbol: bool = True) syside.experimental.units.PrefixableUnit
Find or create a new base unit for
kind.
- static named(name: str, symbol: str, relative: tuple[str, float], kind: syside.experimental.units.Kind, space_before_symbol: bool = True) syside.experimental.units.PrefixableUnit
Find or create a new base unit for
kindwith a custom magnitude and type symbol.This is useful in cases where some root unit is not used as a base unit in the actual system of units, e.g.
gramandkilogram-relativeis(kg, 1e-3). This allows using print derived units in type representation without actually cyclically depending on them. We only require additional symbol to be used in place of actual symbol for consistent readability in formatted output, i.e. we do not want to printgwhen printing a unit type with mass dimensions. Additionally, this allows printing any quantity in its base units without having to resolve a new base unit by just normalizing value to base units.
- static named(name: str, symbol: str, magnitude: float, reference: syside.experimental.units.Unit, space_before_symbol: bool = True) syside.experimental.units.PrefixableUnit
Find or create a new unit scaled to
reference.
- static named(name: str, symbol: str, magnitude: float, expression: Sequence[tuple[syside.experimental.units.Unit, fractions.Fraction | int]], kind: syside.experimental.units.Kind) syside.experimental.units.PrefixableUnit
Find or create a derived unit with a new
expressionfor a givenkind.Raises
ValueErrorifexpressionis incompatible withkind.
- static named(name: str, symbol: str, magnitude: float, expression: Sequence[tuple[syside.experimental.units.Unit, fractions.Fraction | int]]) syside.experimental.units.PrefixableUnit
Find or create a new derived unit with a given
expression.
- static one() syside.experimental.units.Unit
Get a dimensionless unit
one
- static prefixed(arg0: syside.experimental.units.Prefix, arg1: syside.experimental.units.PrefixableUnit, /) syside.experimental.units.Unit
Find or create a new prefixed unit.