nist
From the National Institute of Standards and Technology’s Office OF Weights and Measures, one can find a handy list of all the metric prefixes: e.g.
| Purpose | Name | Symbol | Factor | Name |
|---|---|---|---|---|
| larger quantities or whole units | quetta | Q | $$10^{30}$$ | nonillion |
| ronna | R | $$10^{27}$$ | octillion | |
| yotta | Y | $$10^{24}$$ | septillion | |
| … | … | … | … | |
| hecto Example: hectare | h | $$10^{2}$$ | hundred | |
| deka Example: dekameter | da | $$10^{1}$$ | ten | |
| $$10^{o}$$ | one | |||
| deci Example: decimeter | da | $$10^{-1}$$ | tenth | |
| centi Example: centigram | h | $$10^{-2}$$ | hundredth | |
| … | … | … | … | |
| yocto Example: yoctosecond | y | $$10^{-24}$$ | septillionth | |
| ronto | r | $$10^{-27}$$ | octillionth | |
| smaller quantities or sub units | quecto | q | $$10^{-30}$$ | nonillionth |
Oh how nice it would be to have a class like
unit which we could
subclass and use as follows:
class second(unit):
name = 'second'
s1 = second(1)
s1, s1.kilo, s1.milli, s1.to(3), float(s1.to(3))
(1.0 S, 0.001 KS, 1000.0 mS, 0.001 KS, 0.001)
ah so easy to convert between and even have clean formatting.
Install
pip install nist
Usage
fact
While each fact
(factor) has base: ClassVar[int] = 10, base is actually an instance
variable.
>>> float(kilo()), float(kilo(base=2)), float(kilo(base=5)), float(kilo(base=10))
(1000.0, 8.0, 125.0, 1000.0)
In case that behavior is not obvious
fact is really just a
named and explicilty signed exponent:
>>> kb = kilo(base=2)
>>> kb.abrv, kb.base, kb.expo, kb.sign, kb.ekey, float(kb)
('kilo', 2, 3, 1, 3, 8.0)
Each fact uses efmt
for its representation by default efmt is True, but can be turned off
by setting efmt to False.
>>> (
(decka(), hecto(), kilo(), mega(), giga(), tera()),
(decka(showefmt=False), hecto(showefmt=False), kilo(showefmt=False), mega(showefmt=False), giga(showefmt=False), tera(showefmt=False))
)
((e+1, e+2, e+3, e+6, e+9, e+12), (F1P, F2P, F3P, F6P, F9P, F12P))
Actually we have three formats to work with:
>>> kilo().fstr, kilo(showbase=True).bstr, kilo(showbase=True).efmt
('F3P', '10^+3', 'e+3')
unit
The goal of the unit
class is to make it easy to create units:
class second(unit):
name = 'second'
>>> s1 = second(1)
>>> s1, s1.kilo, s1.milli, s1.to(3), float(s1.to(3)), s1.shownumb
(1.0 S, 0.001 KS, 1000.0 mS, 0.001 KS, 0.001, True)
We can also explore all the different ways of viewing formats:
import pandas as pd
results = list()
factors = (tera, decka, deci, centi, milli, pico)
for fcls in factors:
for flt in (1, 20, 0.03):
for factrepr in {'abrv', 'name', 'symb'}:
for shownumb in (True, False):
for abrvunit in (True, False):
res = fmtunit(
org = flt, flt=flt / float(fcls()), unt = unit, fct = fcls,
factrepr=factrepr, shownumb=shownumb, abrvunit=abrvunit,
unitname='second', factname=None, ndig=3
)
results.append(dict(
fname=fcls.name, flt=flt, res=res, org = flt / float(fcls()),
shownumb=shownumb, abrvunit=abrvunit, factrepr=factrepr
))
df = pd.DataFrame(results).sort_values(by=['fname', 'res'])
df.head()
| fname | flt | res | org | shownumb | abrvunit | factrepr | |
|---|---|---|---|---|---|---|---|
| 134 | hundredth | 0.03 | 0.03 S | 3 | False | True | name |
| 138 | hundredth | 0.03 | 0.03 S | 3 | False | True | abrv |
| 142 | hundredth | 0.03 | 0.03 S | 3 | False | True | symb |
| 143 | hundredth | 0.03 | 0.03 S | 3 | False | False | symb |
| 135 | hundredth | 0.03 | 0.03 seconds | 3 | False | False | name |
Metadata
Release files for nist 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nist-0.0.3.tar.gz | 18.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nist-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.7 kB
Release files / nist-0.0.3.tar.gz
| Download URL | nist-0.0.3.tar.gz |
|---|---|
| Size | 18.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33f4f361c90afc16944adb38c03c211c89c31dbabaa919ebdac1b6f29d61b225
|
|
BLAKE2b-256 checksum How to use checksums |
7835f2eba7ef271961eff00be323a145a29117213ecf8b8d7db479ab50b7d508
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / nist-0.0.3-py3-none-any.whl
| Download URL | nist-0.0.3-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94801177bcbda1953207e72be3ae3188dd1e45d2d2affbf3e9d769a5da64643d
|
|
BLAKE2b-256 checksum How to use checksums |
3863d0649ad297c62c321fae34cef5e5023314188fe47b0fc130eb3b7ce7ff43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|