Prefix
The prefix
module defines standard metric and binary prefixes: yocto
through to yotta
and kibi
through to yobi
. There is also a function to generate a set of SI mass units (as this is a special case, with the kilogram being the conventional reference unit).
- si_mass_units(kg_unit)
Generate multiples and sub-multiples for SI mass units
kg_unit
must be defined, with namekilogram
and symbolkg
Example:
>>> context = Context( ('Mass','M') ) >>> SI = UnitRegister("SI",context) >>> kilogram = SI.unit( RatioScale(context['Mass'],'kilogram','kg') ) >>> prefix.si_mass_units(kilogram) >>> print( SI.Mass.gram.scale.name ) gram >>> print( repr(SI.Mass.gram) ) RegisteredUnit(KindOfQuantity('Mass','M'),'gram','g')
- metric_prefixes
A collection of all metric prefixes.
Useful for generating all related units by iteration:
>>> context = Context( ('Time','T') ) >>> second = SI.unit( RatioScale(context['Time'],'second','s') ) >>> for p_i in prefix.metric_prefixes: ... prefixed_scale = p_i(second.scale) ... print( "{0.name} ({0.symbol}): {0.prefix:.1E}".format(prefixed_scale) ) ... yoctosecond (ys): 1.00E-24 zeptosecond (zs): 1.00E-21 attosecond (as): 1.00E-18 femtosecond (fs): 1.00E-15 picosecond (ps): 1.00E-12 nanosecond (ns): 1.00E-09 microsecond (us): 1.00E-06 millisecond (ms): 1.00E-03 centisecond (cs): 1.00E-02 decisecond (ds): 1.00E-01 dekasecond (das): 1.00E+01 hectosecond (hs): 1.00E+02 kilosecond (ks): 1.00E+03 megasecond (Ms): 1.00E+06 gigasecond (Gs): 1.00E+09 terasecond (Ts): 1.00E+12 petasecond (Ps): 1.00E+15 exasecond (Es): 1.00E+18 zettasecond (Zs): 1.00E+21 yottasecond (Ys): 1.00E+24
- binary_prefixes
A collection of binary prefixes.
Useful for generating all related units by iteration:
>>> byte_scale = RatioScale('Data','byte','b') >>> for p_i in prefix.binary_prefixes: ... prefixed_scale = p_i(byte_scale) ... print( "{0.name} ({0.symbol}): {0.prefix}".format(prefixed_scale) ) ... kibibyte (kib): 1048 mebibyte (Mib): 1098304 gibibyte (Gib): 1151022592 tebibyte (Tib): 1206271676416 pebibyte (Pib): 1264172716883968 exbibyte (Eib): 1324853007294398464 zebibyte (Zib): 1388445951644529590272 yottabyte (Yib): 1455091357323467010605056