You can create your own measures easily by subclassing either measurement.base.MeasureBase or measurement.base.BidimensionalMeasure.
If your measure is not a measure dependent upon another measure (e.g speed, distance/time) you can create new measurement by creating a subclass of measurement.base.MeasureBase.
A simple example is Weight:
from measurement.base import MeasureBase
class Weight(MeasureBase):
STANDARD_UNIT = 'g'
UNITS = {
'g': 1.0,
'tonne': 1000000.0,
'oz': 28.3495,
'lb': 453.592,
'stone': 6350.29,
'short_ton': 907185.0,
'long_ton': 1016000.0,
}
ALIAS = {
'gram': 'g',
'ton': 'short_ton',
'metric tonne': 'tonne',
'metric ton': 'tonne',
'ounce': 'oz',
'pound': 'lb',
'short ton': 'short_ton',
'long ton': 'long_ton',
}
SI_UNITS = ['g']
Important details:
In some situations, your conversions between units may not be simple enough to be accomplished by using simple conversions (e.g. temperature); for situations like that, you should use sympy to create expressions relating your measure’s standard unit and the unit you’re defining:
from sympy import S, Symbol
from measurement.base import MeasureBase
class Tempoerature(MeasureBase):
SU = Symbol('kelvin')
STANDARD_UNIT = 'k'
UNITS = {
'c': SU - S(273.15),
'f': (SU - S(273.15)) * S('9/5') + 32,
'k': 1.0
}
ALIAS = {
'celsius': 'c',
'fahrenheit': 'f',
'kelvin': 'k',
}
Important details: