Extracting the SI prefix#
ubermagutil
provides convenience methods for determining the prefix of a value, such as pico, micro, mega, etc. The prefixes are:
[1]:
import ubermagutil.units as uu
uu.si_prefixes
[1]:
OrderedDict([('y', 1e-24),
('z', 1e-21),
('a', 1e-18),
('f', 1e-15),
('p', 1e-12),
('n', 1e-09),
('u', 1e-06),
('m', 0.001),
('', 1),
('k', 1000.0),
('M', 1000000.0),
('G', 1000000000.0),
('T', 1000000000000.0),
('P', 1000000000000000.0),
('E', 1e+18),
('Z', 1e+21),
('Y', 1e+24)])
From a single value, prefix can be extracted using si_multiplier
:
[2]:
uu.si_multiplier(5e-12)
[2]:
1e-12
[3]:
uu.si_multiplier(-3e6)
[3]:
1000000.0
Similarly, for a list of values, the largest prefix can be determined using si_max_multiplier
:
[4]:
uu.si_max_multiplier([2e-3, 2e-6, 6e-9])
[4]:
0.001