prophys.units#
Physical units and dimensional checking.
Frame and UncertainAttribute carry a unit string. This module turns
those labels into checkable quantities, so a metre frame is never silently
combined with a kilometre field, and an attribute declared in "kW" is
never calibrated against observations in "MW" without conversion.
A Unit is a symbol, a Dimension (the seven SI base
exponents), and a scale factor to the SI base. So km is
(length=1, scale=1000), kW is (mass=1, length=2, time=-3,
scale=1000), and m/s is a compound of the two. parse() builds
one from a string, accepting SI prefixes and the usual *, / and
^ composition.
Two rules follow:
Compatible units share a dimension and can be converted between (
convert()).Incompatible units cannot be combined at all, and the attempt raises
UnitErrorwhen the model is built rather than producing a number.
Checking happens in Python when the model is built, never inside the JAX trace, so it costs nothing at run time, the same discipline Frame compatibility already follows.
Units the SI does not define (currency, counts, arbitrary index scales) are
supported as dimensionless tagged units: two different tags never
convert into each other, so EUR and USD stay distinct while both
remain dimensionless.
Classes
Exponents of the seven SI base dimensions. |
|
A unit of measurement: a symbol, a dimension, and a scale to SI. |
Functions
Parse a unit expression such as |
|
Convert value from unit from_ to unit to. |
|
Return whether two units share a dimension and a tag, and so convert into each other. |
|
Raise |
|
Return the multiplier taking a value from unit from_ into unit to. |
|
Add a unit to the registry under its symbol and any aliases. |
Exceptions
Raised when two quantities' units are incompatible, or a unit string cannot be parsed. |
Constants and objects
The dimension of a pure number. |