7.1. PyMetrology
¶
This module implements units.
Shortcuts are defined to build unit values easily :
Theses unit value constructors accept int, float, object that can be converted to float,
UnitValue
instance and an iterable on these types.
A shortcut is defined to check an unit value match a particular unit, e.g. as_V()
. Theses
shortcuts return the value if the unit match else it raises the exception UnitError.
A shortcut is defined to access each unit, e.g. U_V()
, U_A()
, U_s()
, U_Hz()
,
U_Ω()
, U_F()
, U_H.()
, as well as for prefixes e.g. U_mV()
.
Some shortcuts have Unicode and ASCII variants:
- For micro, we have the prefix μ and u.
- For Ohm, we have
u_Ω()
andu_Ohm()
.
Some examples of usage:
foo = kilo(1) # unit less
resistance_unit = U_Ω
resistance1 = u_kΩ(1)
resistance1 = u_kOhm(1) # ASCII variant
resistance1 = 1@u_kΩ # using Python 3.5 syntax
resistance1 = 1 @u_kΩ # space doesn't matter
resistance1 = 1 @ u_kΩ #
resistance2 = as_Ω(resistance1) # check unit
resistances = u_kΩ(range(1, 11)) # same as [u_kΩ(x) for x in range(1, 11)]
resistances = range(1, 11)@u_kΩ # using Python 3.5 syntax
capacitance = u_uF(200)
inductance = u_mH(1)
temperature = u_Degree(25)
voltage = resistance1 * u_mA(1) # compute unit
frequency = u_ms(20).frequency
period = u_Hz(50).period
pulsation = frequency.pulsation
pulsation = period.pulsation
-
class
PyMetrology.
FrequencyValue
(prefixed_unit, value)[source]¶ Bases:
PyMetrology.Unit.UnitValue
,PyMetrology.Unit.FrequencyMixin
-
class
PyMetrology.
PeriodValue
(prefixed_unit, value)[source]¶ Bases:
PyMetrology.Unit.UnitValue
,PyMetrology.Unit.PeriodMixin
-
PyMetrology.
atto
(value)¶
-
PyMetrology.
deca
(value)¶
-
PyMetrology.
exa
(value)¶
-
PyMetrology.
femto
(value)¶
-
PyMetrology.
giga
(value)¶
-
PyMetrology.
hecto
(value)¶
-
PyMetrology.
kilo
(value)¶
-
PyMetrology.
mega
(value)¶
-
PyMetrology.
micro
(value)¶
-
PyMetrology.
milli
(value)¶
-
PyMetrology.
nano
(value)¶
-
PyMetrology.
peta
(value)¶
-
PyMetrology.
pico
(value)¶
-
PyMetrology.
tera
(value)¶
-
PyMetrology.
yocto
(value)¶
-
PyMetrology.
yotta
(value)¶
-
PyMetrology.
zepto
(value)¶
-
PyMetrology.
zetta
(value)¶