Skip to main content

si type metric

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nist-0.0.2.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nist-0.0.2-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file nist-0.0.2.tar.gz.

File metadata

  • Download URL: nist-0.0.2.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for nist-0.0.2.tar.gz
Algorithm Hash digest
SHA256 02656b95981f88ba17157a9141788309ff3aaf0f0502db132a14fe18817b5219
MD5 f07d9d4d6e076bc8b9c5f47d708c607e
BLAKE2b-256 802628ceb116d563abda23c67d413277fb0f21c83204825c123bd6dd7631ec2f

See more details on using hashes here.

File details

Details for the file nist-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: nist-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for nist-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2c462589ca4cce41940bf5340a0bd4e10f193cbbddf429291d5e2a0c207feb8d
MD5 7955f03273d5ffdbc7942be75ccc3a99
BLAKE2b-256 4a162711b10fa14b5f102da511c13ebb4ae1cb6ab9d43e7f772b4e7f64751603

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page