metrum.units
This is a collection of unit of measurement.
Each unit is defined by a variable (e.g. m, mm, kg, s, etc.), which is supposed to be used as shown in the following example:
height = 180*cm # cm = 0.01*m, therefore height holds 0.18 (m)
weight = 250*g # g = 0.001*kg, therefore weigth is now 0.25 (kg)
width = 10*usc_in # usc_in = 0.0254*m, therefor width is now 0.254 (m)
By using the units contained in this module as shown above, you can achieve two beneficial results:
- Make your code more readable, by explicitily indicating the units of measure
- Express all the quatities in a consistent set of reference units (e.g. all distances are in metre, all weights in kg, all times in s, etc.)
The reference units to which every other unit is coverted are shown in the following table, of which the first 7 are SI base units and the rest are SI derived units.
| Quantity | Unit | Var. Name | Var. Value |
|---|---|---|---|
| Time | second | s | 1.0 |
| Length | metre | m | 1.0 |
| Mass | kilogram | kg | 1.0 |
| Electric current | ampere | A | 1.0 |
| Temperature | kelvin | K | 1.0 |
| Amount of substance | mole | mol | 1.0 |
| Luminous intensity | candela | cd | 1.0 |
| Plane angle | radian | rad | m/m |
| Solid angle | steradian | sr | m2/m2 |
| Frequency | hertz | Hz | 1/s |
| Force | newton | N | kgm/s*2 |
| Pressure | pascal | Pa | N/m**2 |
| Energy | joule | J | N*m |
| Power | watt | W | J/s |
| Electric charge | coulomb | C | A*s |
| Electric potential diff. | volt | V | W/A |
| Capacitance | farad | F | C/V |
| Electric resistance | ohm | ohm | V/A |
| Electric conductance | siemens | S | A/V |
| Magnetic flux | weber | Wb | V*s |
| Magnetic flux density | tesla | T | Wb/m**2 |
| Inductance | henry | H | Wb/A |
| ! Luminous flux | lumen | lm | cd*sr |
| Illuminance | lux | lx | lm/m**2 |
| Activity referred to | becquerel | Bq | 1/s |
| Absorbed dose | gray | Gy | J/kg |
| Dose equivalent | sievert | Sv | J/kg |
| Catalytic activity | katal | kat | mol/s |
For each reference variable U in the previous table, the following additional 12 variables are defined as well:
- pico-unit : pU = 1e-12*U
- nano-unit : nU = 1e-9*U
- micro-unit: uU = 1e-6*U
- milli-unit: mU = 1e-3*U
- centi-unit: cU = 1e-2*U
- deci-unit : dU = 1e-1*U
- deca-unit : daU = 1e+1*U
- hetto-unit: hU = 1e+2*U
- kilo-unit : kU = 1e+3*U
- mega-unit : MU = 1e+6*U
- giga-unit : GU = 1e+9*U
- tera-unit : TU = 1e+12*U
Finally, the following special units are defined.
| Quantity | Unit | Var. Name | Var. Value |
|---|---|---|---|
| Time | minute | min | 60*s |
| Time | hour | h | 60*min |
| Time | day | d | 24*h |
| Length | astronomical unit | au | 149597870700*m |
| Length | US Customary inch | usc_in | 2.54*cm |
| Length | US Customary twip | usc_twip | 1/1440*usc_in |
| Length | US Customary thou | usc_mil | 1/1000*usc_in |
| Length | US Customary pica | usc_P | 1/6*usc_in |
| Length | US Customary point | usc_p | 1/72*usc_in |
| Length | US Customary foot | usc_ft | 12*usc_in |
| Length | US Customary yard | usc_yd | 3*usc_ft |
| Length | US Customary mile | usc_mi | 1760*usc_yd |
| Length | US Customary league | usc_lea | 3*usc_mi |
| Mass | tonne | t | 1000*kg |
| Mass | dalton | Da | 1.66053e-27*kg |
| Mass | US Customary grain | usc_gr | 64.79891*mg |
| Mass | US Customary dram | usc_dr | 1.771845*g |
| Mass | US Customary ounche | usc_oz | 16*usc_dr |
| Mass | US Customary pound | usc_lb | 16*usc_oz |
| Mass | US Customary cwt | usc_cwt | 100*usc_lb |
| Mass | US Customary lcwt | usc_lgcwt | 112*usc_lb |
| Mass | US Customary ton | usc_ton | 20*usc_cwt |
| Mass | US Customary lton | usc_lgton | 20*usc_lgcwt |
| Area | hectare | ha | 10000m*2 |
| Volume | litre | L | 1dm*3 |
| Volume | US Customary drop | usc_drop | 51.3429e-6*L |
| Volume | US Customary minim | usc_min | 1.2*usc_drop |
| Volume | US Customary grH2O | usc_grH2O | 1.1*usc_min |
| Volume | US Customary fldr | usc_fldr | 60*usc_min |
| Volume | US Customary tsp | usc_tsp | 80*usc_min |
| Volume | US Customary tbsp | usc_tbsp | 3*usc_tsp |
| Volume | US Customary floz | usc_floz | 2*usc_tbsp |
| Volume | US Customary shot | usc_jig | 1.5*usc_floz |
| Volume | US Customary gill | usc_gi | 4*usc_floz |
| Volume | US Customary cup | usc_c | 2*usc_gi |
| Volume | US Customary pint | usc_pt | 2*usc_c |
| Volume | US Customary quart | usc_qt | 2*usc_pt |
| Volume | US Customary pottle | usc_pot | 2*usc_qt |
| Volume | US Customary gallon | usc_gal | 4*usc_qt |
| Volume | US Customary barrel | usc_bbl | 31.6*usc_gal |
| Volume | US Customary obarrel | usc_obbl | 42*usc_gal |
| Volume | US Customary hgsh | usc_hogshead | 2*usc_bbl |
| Plane angle | degree | deg | pi/180*rad |
| Energy | electronvolt | eV | 1.60217e-19*J |
SIUnit
USCustomaryUnit
Unit
Bases: float
Unit of measure
This class is just a float with an extra attribute that holds the unit name. The value of the unit instance represents a conversion factor to the basic unit, so that a number can be converted to the basic unit as follows:
value = 12.5*unit