Measurement#
Units provide a basis and context to parameter inputs. Some common initializations for units can be found in energia.library.components, namely si_units which are subset of SI Units and misc_units which include some US Customary Units
Using library initializations#
from energia import Model, si_units, misc_units
m = Model(init=[si_units, misc_units])
For bespoke units#
It is important to only provide one base unit for each type. For example, to define all units of weights:
1. Define a base Unit#
from energia import Model, Unit
m = Model()
m.kg = Unit(label='kilogram')
2. Define the rest of weight units in relation to m.kg#
m.ton = 1000 * m.kg
m.g = 0.001 * m.kg
Comparison#
The relation between different units can be checked:
m.g.howmany(m.ton)
1e-06
In the above example, m.ton and m.g are compared based on the common basis m.kg.
Having independent measures for the same category could be fine as long as you are careful during implementation and there no query that involves a comparison. Generally, comparing two units with no common basis throws an ValueError.
m.m = Unit(label='meter')
# m.m.howmany(m.kg) # will give an error