Quantity¶
Unit-safe computations with quantities.
Introduction¶
What is a quantity?¶
“The value of a quantity is generally expressed as the product of a number and a unit. The unit is simply a particular example of the quantity concerned which is used as a reference, and the number is the ratio of the value of the quantity to the unit.” (Bureau International des Poids et Mesures: The International System of Units, 8th edition, 2006)
Basic types of quantities are defined “by convention”, they do not depend on other types of quantities, for example Length, Mass or Duration.
Derived types of quantities, on the opposite, are defined as products of other types of quantities raised by some exponent.
Examples:
- Volume = Length ** 3
- Velocity = Length ** 1 * Duration ** -1
- Acceleration = Length ** 1 * Duration ** -2
- Force = Mass ** 1 * Acceleration ** 1
Each type of quantity may have one special unit which is used as a reference for the definition of all other units, for example Meter, Kilogram and Second. The other units are then defined by their relation to the reference unit.
If a type of quantity is derived from types of quantities that all have a reference unit, then the reference unit of that type is defined by a formula that follows the formula defining the type of quantity.
Examples:
- Velocity -> Meter per Second = Meter ** 1 * Second ** -1
- Acceleration -> Meter per Second squared = Meter ** 1 * Second ** -2
- Force -> Newton = Kilogram ** 1 * Meter ** 1 * Second ** -2
“Systems of measure”¶
There may be different systems which define quantities, their units and the relations between these units in a different way.
This is not directly supported by this module. For each type of quantity there can be only no or exactly one reference unit. But, if you have units from different systems for the same type of quantity, you can define these units and provide mechanisms to convert between them (see Converters).
Defining a quantity class¶
A basic type of quantity is declared just by sub-classing Quantity:
>>> class Length(Quantity):
... pass
...
In addition to the new quantity class the meta-class of Quantity creates a corresponding class for the units automatically. It can be referenced via the quantity class:
>>> Length.Unit
<class 'quantity.quantity.LengthUnit'>
But, as long as there is no unit defined for that class, you can not create any instance for the new quantity class:
>>> l = Length(1)
ValueError: A unit must be given.
If there is a reference unit, the simplest way to define it is giving a name and a symbol for it as class variables. The meta-class of Quantity will then create a unit automatically:
>>> class Length(Quantity):
... refUnitName = 'Meter'
... refUnitSymbol = 'm'
...
>>> Length.refUnit
Length.Unit('m')
Now, this unit can be given to create a quantity:
>>> METER = Length.refUnit
>>> print(Length(15, METER))
15 m
If no unit is given, the reference unit is used:
>>> print(Length(15))
15 m
Other units can be derived from the reference unit (or another unit), giving a definition by multiplying a scaling factor with that unit:
>>> MILLIMETER = Length.Unit('mm', 'Millimeter', Decimal('0.001') * METER)
>>> MILLIMETER
Length.Unit('mm')
>>> KILOMETER = Length.Unit('km', 'Kilometer', 1000 * METER)
>>> KILOMETER
Length.Unit('km')
>>> CENTIMETER = Length.Unit('cm', 'Centimeter', 10 * MILLIMETER)
>>> CENTIMETER
Length.Unit('cm')
Using one unit as a reference and defining all other units by giving a scaling factor is only possible if the units have the same scale. Otherwise, units have to be instantiated via the coresponding Unit sub-class without giving a definition.
>>> class Temperature(Quantity):
... pass
...
>>> CELSIUS = Temperature.Unit('°C', 'Degree Celsius')
>>> FAHRENHEIT = Temperature.Unit('°F', 'Degree Fahrenheit')
>>> KELVIN = Temperature.Unit('K', 'Kelvin')
Derived types of quantities are declared by giving a definition based on more basic types of quantities:
>>> class Volume(Quantity):
... defineAs = Length ** 3
... refUnitName = 'Cubic Meter'
...
>>> class Duration(Quantity):
... refUnitName = 'Second'
... refUnitSymbol = 's'
...
>>> class Velocity(Quantity):
... defineAs = Length / Duration
... refUnitName = 'Meter per Second'
...
If no symbol for the reference unit is given with the class declaration, a symbol is generated from the definition, as long as all types of quantities in that definition have a reference unit.
>>> print(Volume.refUnit.symbol)
m³
>>> print(Velocity.refUnit.symbol)
m/s
Instantiating quantities¶
The simplest way to create an instance of a Quantity subclass is to call the class giving an amount and a unit. If the unit is omitted, the quantity’s reference unit is used (if one is defined).
>>> Length(15, MILLIMETER)
Length(Decimal(15), Length.Unit(u'mm'))
>>> Length(15)
Length(Decimal(15))
Alternatively, the two-args infix operator ‘^’ can be used to combine an amount and a unit:
>>> 17.5 ^ KILOMETER
Length(Decimal('17.5'), Length.Unit(u'km'))
Also, it’s possible to create a Quantity instance from a string representation:
>>> Length('17.5 km')
Length(Decimal('17.5'), Length.Unit(u'km'))
If a unit is given in addition, the resulting quantity is converted accordingly:
>>> Length('17 m', KILOMETER)
Length(Decimal('0.017'), Length.Unit(u'km'))
Instead of calling a subclass, the class Quantity can be used as a factory function ...
>>> Quantity(15, MILLIMETER)
Length(Decimal(15), Length.Unit(u'mm'))
>>> Quantity('17.5 km')
Length(Decimal('17.5'), Length.Unit(u'km'))
... as long as a unit is given:
>>> Quantity(17.5)
ValueError: A unit must be given.
Converting between units¶
A quantity can be converted to a quantity using a different unit by calling the method Quantity.convert():
>>> l5cm = Length(Decimal(5), CENTIMETER)
>>> l5cm.convert(MILLIMETER)
Length(Decimal('50'), Length.Unit('mm'))
>>> l5cm.convert(KILOMETER)
Length(Decimal('0.00005'), Length.Unit('km'))
To get just the amount of a quantity in another unit, that unit can be called with the quantity as parameter:
>>> MILLIMETER(l5cm)
Decimal('50')
>>> KILOMETER(l5cm)
Decimal('0.00005')
These kinds of conversion are automatically enabled for types of quantities with reference units. For other types of quantities there is no default way of converting between units.
>>> t27c = Temperature(Decimal(27), CELSIUS)
>>> t27c.convert(FAHRENHEIT)
quantity.quantity.IncompatibleUnitsError: Can't convert 'Degree Celsius'
to 'Degree Fahrenheit'
Converters¶
For types of quantities that do not have a reference unit, one or more callables can be registered as converters.
>>> def fahrenheit2celsius(qty, toUnit):
... if qty.unit is FAHRENHEIT and toUnit is CELSIUS:
... return (qty.amount - 32) / Decimal('1.8')
... return None
...
>>> def celsius2fahrenheit(qty, toUnit):
... if qty.unit is CELSIUS and toUnit is FAHRENHEIT:
... return qty.amount * Decimal('1.8') + 32
... return None
...
>>> Temperature.Unit.registerConverter(celsius2fahrenheit)
>>> Temperature.Unit.registerConverter(fahrenheit2celsius)
>>> list(Temperature.Unit.registeredConverters())
[<function celsius2fahrenheit at 0x7fab71bfef50>,
<function fahrenheit2celsius at 0x7fab71bf7cf8>]
For the signature of the callables used as converters see Converter.
>>> t27c.convert(FAHRENHEIT)
Temperature(Decimal('80.6'), Temperature.Unit('°F'))
>>> t27c.convert(FAHRENHEIT).convert(CELSIUS)
Temperature(Decimal('27'), Temperature.Unit('°C'))
Alternatively, an instance of TableConverter can be created and registered as converter.
The example given above can be implemented as follows:
>>> tempConv = TableConverter({(CELSIUS, FAHRENHEIT):
(Decimal('1.8'), 32)})
>>> Temperature.Unit.registerConverter(tempConv)
>>> t27c = Temperature(Decimal(27), CELSIUS)
>>> t27c.convert(FAHRENHEIT)
Temperature(Decimal('80.6'), Temperature.Unit(u'°F'))
It is suffient to define the conversion in one direction, because a reversed conversion is used automatically:
>>> t27c.convert(FAHRENHEIT).convert(CELSIUS)
Temperature(Decimal(27), Temperature.Unit(u'°C'))
Unit-safe computations¶
Comparison¶
Quantities can be compared to other quantities using all comparison operators defined for numbers:
>>> Length(27) > Length(9)
True
>>> Length(27) >= Length(91)
False
>>> Length(27) < Length(9)
False
>>> Length(27) <= Length(91)
True
>>> Length(27) == Length(27)
True
>>> Length(27) != Length(91)
True
Different units are taken in to account automatically, as long as they are compatible, i. e. a conversion is available:
>>> Length(27, METER) <= Length(91, CENTIMETER)
False
>>> Temperature(20, CELSIUS) > Temperature(20, FAHRENHEIT)
True
>>> Temperature(20, CELSIUS) > Temperature(20, KELVIN)
IncompatibleUnitsError: Can't convert 'Kelvin' to 'Degree Celsius'
Testing instances of different quantity types for equality always returns false:
>>> Length(20) == Mass(20)
False
>>> Length(20) != Mass(20)
True
All other comparison operators raise an IncompatibleUnitsError in this case.
Addition and subtraction¶
Quantities can be added to or subtracted from other quantities ...
>>> Length(27) + Length(9)
Length(Decimal(36))
>>> Length(27) - Length(91)
Length(Decimal(-64))
... as long as they are instances of the same quantity type:
>>> Length(27) + Duration(9)
IncompatibleUnitsError: Can't add a 'Length' and a 'Duration'
When quantities with different units are added or subtracted, the values are converted to the unit of the first, if possible ...:
>>> Length(27) + Length(12, CENTIMETER)
Length(Decimal('27.12'))
>>> Length(12, CENTIMETER) + Length(17, METER)
Length(Decimal('1712'), Length.Unit('cm'))
>>> Temperature(20, CELSIUS) - Temperature(50, FAHRENHEIT)
Temperature(Decimal('10'), Temperature.Unit(u'°C'))
... but an exception is raised, if not:
>>> Temperature(20, CELSIUS) - Temperature(281, KELVIN)
IncompatibleUnitsError: Can't convert 'Kelvin' to 'Degree Celsius'
Multiplication and division¶
Quantities can be multiplied or divided by scalars, preserving the unit ...:
>>> 7.5 * Length(3, CENTIMETER)
Length(Decimal('22.5'), Length.Unit(u'cm'))
>>> Duration(66, MINUTE) / 11
Duration(Decimal(6), Duration.Unit(u'min'))
Quantities can be multiplied or divided by other quantities ...:
>>> Length(15, METER) / Duration(3, SECOND)
Velocity(Decimal(5))
... as long as the resulting type of quantity is defined ...:
>>> Duration(4, SECOND) * Length(7)
UndefinedResultError: Undefined result: Duration * Length
>>> Length(12, KILOMETER) / Duration(2, MINUTE) / Duration(50, SECOND)
UndefinedResultError: Undefined result: Velocity / Duration
>>> class Acceleration(Quantity):
... defineAs = Length / Duration ** 2
... refUnitName = 'Meter per Second squared'
...
>>> Length(12, KILOMETER) / Duration(2, MINUTE) / Duration(50, SECOND)
Acceleration(Decimal(2))
... or the result is a scalar:
>>> Duration(2, MINUTE) / Duration(50, SECOND)
Decimal('2.4')
When cascading operations, all intermediate results have to be defined:
>>> Length(6, KILOMETER) * Length(13, METER) * Length(250, METER)
UndefinedResultError: Undefined result: Length * Length
>>> class Area(Quantity):
... defineAs = Length ** 2
... refUnitName = 'Square Meter'
...
>>> Length(6, KILOMETER) * Length(13, METER) * Length(250, METER)
Volume(Decimal(19500000, 3))
Exponentiation¶
Quantities can be raised by an exponent, as long as the exponent is an Integral number and the resulting quantity is defined:
>>> (5 ^ METER) ** 2
Area(Decimal(25))
>>> (5 ^ METER) ** 2.5
TypeError: unsupported operand type(s) for ** or pow(): 'Length' and
'float'
>>> (5 ^ METER) ** -2
UndefinedResultError: Undefined result: Length ** -2
Rounding¶
The amount of a quantity can be rounded by using the standard round function:
>>> round(Length(Decimal('17.375'), MILLIMETER), 1)
Length(Decimal('17.4'), Length.Unit('mm'))
Note
This only applies to Python 3.x !!! In Python 2.x the standard round function tries to convert its first operand to a float and thus raises an exception when called with a quantity. But, as Quantity defines a Quantity.__round__() method, this method can be called directly.
Formatting as string¶
Quantity supports the standard str and unicode (Python 2.x only) functions. Both return a string representation of the quantity’s amount followed by a blank and the quantity’s units symbol.
Note
While the str function in Python 3.x and the unicode function in Python 2.x return the result as a unicode string, the str function in Python 2.x returns an utf8-encoded bytes string.
In addition, Quantity supports the standard format function. The format specifier should use two keys: ‘a’ for the amount and ‘u’ for the unit, where ‘a’ can be followed by a valid format spec for numbers and ‘u’ by a valid format spec for strings. If no format specifier is given, ‘{a} {u}’ is used.
>>> v = Volume('19.36')
>>> format(v)
u'19.36 m³'
>>> format(v, '{a:*>10.2f} {u:<3}')
u'*****19.36 m³ '
Classes¶
- class quantity.Quantity¶
Base class used to define types of quantities.
Instances of Quantity can be created in two ways, by providing a numerical amount and - optionally - a unit or by providing a string representation of a quantity.
1. Form
Parameters: - amount – the numerical part of the quantity
- unit – the quantity’s unit (optional)
amount must be of type number.Real or be convertable to a decimalfp.Decimal. unit must be an instance of the Unit sub-class corresponding to the Quantity sub-class. If no unit is given, the reference unit of the Quantity sub-class is used (if defined, otherwise a ValueError is raised).
Returns: instance of called Quantity sub-class or instance of the sub-class corresponding to given unit if Quantity is called
Raises: 2. Form
Parameters: - qStr – unicode string representation of a quantity
- unit – the quantity’s unit (optional)
qStr must contain a numerical value and a unit symbol, separated atleast by one blank. Any surrounding white space is ignored. If unit is given in addition, the resulting quantity’s unit is set to this unit and its amount is converted accordingly.
Returns: instance of Quantity sub-class corresponding to symbol in qRepr
Raises: - TypeError – amount is not a Real or Decimal number and can not be converted to a Decimal number
- ValueError – no unit given and the Quantity sub-class doesn’t define a reference unit
- TypeError – unit is not an instance of the Unit sub-class corresponding to the Quantity sub-class
- TypeError – a byte string is given that can not be decoded using the standard encoding
- ValueError – given string does not represent a Quantity
- IncompatibleUnitsError – the unit derived from the symbol given in qStr is not compatible to given unit
- amount¶
The quantity’s amount, i.e. the numerical part of the quantity.
- unit¶
Return the unit of the quantity.
- __abs__()¶
abs(self) -> self.Quantity(abs(self.amount), self.unit)
- __add__(other)¶
self + other
- __div__(other)¶
self / other
- __eq__(other)¶
self == other
- __format__(fmtSpec=u'')¶
Convert to string (according to format specifier).
The specifier must be a standard format specifier in the form described in PEP 3101. It should use two keys: ‘a’ for self.amount and ‘u’ for self.unit, where ‘a’ can be followed by a valid format spec for numbers and ‘u’ by a valid format spec for strings.
- __ge__(other)¶
self >= other
- __gt__(other)¶
self > other
- __hash__()¶
hash(self)
- __le__(other)¶
self <= other
- __lt__(other)¶
self < other
- __mul__(other)¶
self * other
- __neg__()¶
-self -> self.Quantity(-self.amount, self.unit)
- __pos__()¶
+self
- __pow__(exp)¶
self ** exp
- __radd__(other)¶
self + other
- __rdiv__(other)¶
other / self
- __repr__()¶
repr(self)
- __rmul__(other)¶
self * other
- __round__(precision=0)¶
round(self)
Returns a copy of self with its amount rounded to the given precision.
Note: this method is called by the standard round function only in Python 3.x!
- __rsub__(other)¶
other - self
- __rtruediv__(other)¶
other / self
- __str__()¶
str(self)
- __sub__(other)¶
self - other
- __truediv__(other)¶
self / other
- convert(toUnit)¶
Return quantity q where q == self and q.unit is toUnit.
Parameters: toUnit (Unit) – unit to be converted to Returns: resulting quantity (of same type) Return type: Quantity Raises: IncompatibleUnitsError – self can’t be converted to unit toUnit.
- definition¶
The quantity’s or units definition.
- normalizedDefinition¶
The quantity’s or units normalized definition.
The normalized definition defines the quantity or unit in terms of base units only.
- class quantity.Unit¶
Base class used to define types of quantity units.
- classmethod registeredUnits()¶
Return an iterator over the units registered in cls.
- classmethod registerConverter(conv)¶
Add converter conv to the list of converters registered in cls.
Does nothing if converter is already registered.
- classmethod removeConverter(conv)¶
Remove converter conv from the list of converters registered in cls.
Raises ValueError if the converter is not present.
- classmethod registeredConverters()¶
Return an iterator over the converters registered in cls.
- definition¶
Return the definition of the unit.
- symbol¶
Return the units symbol, a unique string representation of the unit.
Used for the functions str, repr, format, hash and the unit registry.
- name¶
Return the units name.
If the unit was not given a name, its symbol is returned.
- isRefUnit()¶
Return True if the unit is a reference unit.
- isBaseUnit()¶
Return True if the unit is a base unit, i. e. it’s not derived from another unit.
- isDerivedUnit()¶
Return True if the unit is derived from another unit.
- __eq__(other)¶
self == other
- __call__(qty)¶
Return number f so that type(qty)(f, self) == qty.
Raises IncompatibleUnitsError if conversion not possible.
- __ge__(other)¶
self >= other
- __gt__(other)¶
self > other
- __le__(other)¶
self <= other
- __lt__(other)¶
self < other
- normalizedDefinition¶
The quantity’s or units normalized definition.
The normalized definition defines the quantity or unit in terms of base units only.
- class quantity.Converter¶
Convert a quantity’s amount to the equivalent amount for another unit.
A quantity converter can be any callable with a signature like conv(qty, toUnit) -> number f so that type(qty)(f, toUnit) == qty.
Must return None if conversion can not be done.
- class quantity.TableConverter(convTable)¶
Converter using a conversion table.
Parameters: convTable (dict or list) – the mapping used to initialize the conversion table Each item of the conversion table defines a conversion from one unit to another unit and consists of four elements:
- fromUnit: unit of the quantity to be converted
- toUnit: target unit of the conversion
- factor: factor to be applied to the quantity’s amount
- offset: an amount added after applying the factor
When a dict is given as convTable, each key / value pair must map a tuple (fromUnit, toUnit) to a tuple (factor, offset).
When a list is given as convTable, each item must be a tuple (fromUnit, toUnit, factor, offset).
factor and offset must be set so that for an amount in terms of fromUnit the eqivalent amount in terms of toUnit is:
result = amount * factor + offset
An instance of TableConverter can be called with a Quantity sub-class’ instance qty and a Unit sub-class’ instance toUnit as parameters. It looks-up the pair (qty.unit, toUnit) for a factor and an offset and returns the resulting amount according to the formula given above.
If there is no item for the pair (qty.unit, toUnit), it tries to find a reverse mapping by looking-up the pair (toUnit, qty.unit), and, if it finds one, it returns a result by applying a reversed formula:
result = (amount - offset) / factor
That means, for each pair of units it is sufficient to define a conversion in one direction.
An instance of TableConverter can be directly registered as a converter by calling the Unit.registerConverter() method of a Unit class.
- __call__(qty, toUnit)¶
Return f so that type(qty)(f, toUnit) == qty.
If there is no mapping from qty.unit to toUnit or vice versa defined in the conversion table, None is returned.
Functions¶
Exceptions¶
- class quantity.QuantityError¶
Base class for quantity exceptions.
- class quantity.IncompatibleUnitsError(msg, operand1, operand2)¶
Exception raised when operands do not have compatible units.
- class quantity.UndefinedResultError(op, operand1, operand2)¶
Exception raised when operation results in an undefined quantity.
Submodules¶
quantity.predefined¶
Defines commonly used quantities.
Length¶
Reference unit: Metre (‘m’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘m’ |
---|---|---|---|
µm | Micrometre | 0.000001·m | 0.000001 |
mm | Millimetre | 0.001·m | 0.001 |
cm | Centimetre | 0.01·m | 0.01 |
in | Inch | 2.54·cm | 0.0254 |
dm | Decimetre | 0.1·m | 0.1 |
ft | Foot | 12·in | 0.3048 |
yd | Yard | 3·ft | 0.9144 |
ch | Chain | 22·yd | 20.1168 |
fur | Furlog | 10·ch | 201.1680 |
km | Kilometre | 1000·m | 1000 |
mi | Mile | 8·fur | 1609.3440 |
Mass¶
Reference unit: Kilogram (‘kg’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘kg’ |
---|---|---|---|
mg | Milligram | 0.000001·kg | 0.000001 |
ct | Carat | 0.2·g | 0.0002 |
g | Gram | 0.001·kg | 0.001 |
oz | Ounce | 0.0625·lb | 0.028349523125 |
lb | Pound | 0.45359237·kg | 0.45359237 |
st | Stone | 14·lb | 6.35029318 |
t | Tonne | 1000·kg | 1000 |
Duration¶
Reference unit: Second (‘s’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘s’ |
---|---|---|---|
min | Minute | 60·s | 60 |
h | Hour | 60·min | 3600 |
d | Day | 24·h | 86400 |
Area¶
Definition: Length²
Reference unit: Square Metre (‘m²’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘m²’ |
---|---|---|---|
mm² | Square Millimetre | mm² | 0.000001 |
cm² | Square Centimetre | cm² | 0.0001 |
in² | Square Inch | in² | 0.00064516 |
dm² | Square Decimetre | dm² | 0.01 |
ft² | Square Foot | ft² | 0.09290304 |
yd² | Square Yard | yd² | 0.83612736 |
a | Are | 100·m² | 100 |
ac | Acre | 4840·yd² | 4046.85642240 |
ha | Hectare | 100·a | 10000 |
km² | Square Kilometre | km² | 1000000 |
mi² | Square Mile | mi² | 2589988.11033600 |
Volume¶
Definition: Length³
Reference unit: Cubic Metre (‘m³’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘m³’ |
---|---|---|---|
mm³ | Cubic Millimetre | mm³ | 0.000000001 |
ml | Millilitre | 0.001·l | 0.000001 |
cm³ | Cubic Centimetre | cm³ | 0.000001 |
cl | Centilitre | 0.01·l | 0.00001 |
in³ | Cubic Inch | in³ | 0.000016387064 |
dl | Decilitre | 0.1·l | 0.0001 |
l | Litre | 0.001·m³ | 0.001 |
dm³ | Cubic Decimetre | dm³ | 0.001 |
ft³ | Cubic Foot | ft³ | 0.028316846592 |
yd³ | Cubic Yard | yd³ | 0.764554857984 |
km³ | Cubic Kilometre | km³ | 1000000000 |
Velocity¶
Definition: Length/Duration
Reference unit: Metre per Second (‘m/s’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘m/s’ |
---|---|---|---|
km/h | Kilometre per hour | km/h | 5/18 |
ft/s | Foot per Second | ft/s | 0.3048 |
mph | Mile per Hour | mi/h | 0.44704 |
Acceleration¶
Definition: Length/Duration²
Reference unit: Metre per Second squared (‘m/s²’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘m/s²’ |
---|---|---|---|
mps² | Mile per Second squared | mi/s² | 1609.3440 |
Force¶
Definition: Mass·Acceleration
Reference unit: Newton (‘N’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘N’ |
---|---|---|---|
J/m | Joule per Metre | J/m | 1 |
Energy¶
Definition: Length·Force
Reference unit: Joule (‘J’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘J’ |
---|---|---|---|
Ws | Watt Second | s·W | 1 |
kWh | Kilowatt Hour | h·kW | 3600000 |
Power¶
Definition: Energy/Duration
Reference unit: Watt (‘W’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘W’ |
---|---|---|---|
mW | Milliwatt | 0.001·W | 0.001 |
kW | Kilowatt | 1000·W | 1000 |
MW | Megawatt | 1000000·W | 1000000 |
GW | Gigawatt | 1000000000·W | 1000000000 |
TW | Terawatt | 1000000000000·W | 1000000000000 |
DataVolume¶
Reference unit: Byte (‘B’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘B’ |
---|---|---|---|
b | Bit | 1·B/8 | 0.125 |
kb | Kilobit | 1000·b | 125 |
Kib | Kibibit | 1024·b | 128 |
kB | Kilobyte | 1000·B | 1000 |
KiB | Kibibyte | 1024·B | 1024 |
Mb | Megabit | 1000000·b | 125000 |
Mib | Mebibit | 1048576·b | 131072 |
MB | Megabyte | 1000000·B | 1000000 |
MiB | Mebibyte | 1048576·B | 1048576 |
Gb | Gigabit | 1000000000·b | 125000000 |
Gib | Gibibit | 1073741824·b | 134217728 |
GB | Gigabyte | 1000000000·B | 1000000000 |
GiB | Gibibyte | 1073741824·B | 1073741824 |
Tb | Terabit | 1000000000000·b | 125000000000 |
Tib | Tebibit | 1099511627776·b | 137438953472 |
TB | Terabyte | 1000000000000·B | 1000000000000 |
TiB | Tebibyte | 1099511627776·B | 1099511627776 |
DataThroughput¶
Definition: DataVolume/Duration
Reference unit: Byte per Second (‘B/s’)
Predefined units:
Symbol | Name | Definition | Equivalent in ‘B/s’ |
---|---|---|---|
b/s | Bit per Second | b/s | 0.125 |
kb/s | Kilobit per Second | 1000·b/s | 125 |
Kib/s | Kibibit per Second | 1024·b/s | 128 |
kB/s | Kilobyte per Second | 1000·B/s | 1000 |
KiB/s | Kibibyte per Second | 1024·B/s | 1024 |
Mb/s | Megabit per Second | 1000000·b/s | 125000 |
Mib/s | Mebibit per Second | 1048576·b/s | 131072 |
MB/s | Megabyte per Second | 1000000·B/s | 1000000 |
MiB/s | Mebibyte per Second | 1048576·B/s | 1048576 |
Gb/s | Gigabit per Second | 1000000000·b/s | 125000000 |
Gib/s | Gibibit per Second | 1073741824·b/s | 134217728 |
GB/s | Gigabyte per Second | 1000000000·B/s | 1000000000 |
GiB/s | Gibibyte per Second | 1073741824·B/s | 1073741824 |
Tb/s | Terabit per Second | 1000000000000·b/s | 125000000000 |
Tib/s | Tebibit per Second | 1099511627776·b/s | 137438953472 |
TB/s | Terabyte per Second | 1000000000000·B/s | 1000000000000 |
TiB/s | Tebibyte per Second | 1099511627776·B/s | 1099511627776 |
Temperature¶
Predefined units:
Symbol | Name | Equivalents |
---|---|---|
°C | Degree Celsius | 0 °C = 32 °F = 273,25 K |
°F | Degree Fahrenheit | 0 °F ≅ -17.778 °C ≅ 255.372 K |
K | Kelvin | 0 K = -273,25 °C = -459.67 °F |
Temperature units are converted using the following formulas:
from \ to | Celsius | Fahrenheit | Kelvin |
---|---|---|---|
Celsius | [°F] = [°C] * 9/5 + 32 | [K] = [°C] + 273.15 | |
Fahrenheit | [°C] = ([°F] - 32) * 5/9 | [K] = ([°F] + 459.67) * 5/9 | |
Kelvin | [°C] = [K] - 273.15 | [°F] = [K] * 9/5 - 459.67 |