# nist
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
From the [National Institute of Standards and
Technology](https://www.nist.gov)’s [Office OF Weights and
Measures](https://www.nist.gov/pml/owm), one can find a handy list of
all the [metric
prefixes](https://www.nist.gov/pml/owm/metric-si-prefixes#:~:text=Prefix%20Total&text=Eight%20original%20SI%20prefixes%20were,from%20Greek%20and%20Latin%20numbers.):
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`](https://dsm-72.github.io/nist/unit.html#unit) which we could
subclass and use as follows:
``` python
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
``` sh
pip install nist
```
## Usage
### [`fact`](https://dsm-72.github.io/nist/fact.html#fact)
While each [`fact`](https://dsm-72.github.io/nist/fact.html#fact)
(factor) has `base: ClassVar[int] = 10`, `base` is actually an instance
variable.
``` python
>>> 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`](https://dsm-72.github.io/nist/fact.html#fact) is really just a
named and explicilty signed exponent:
``` python
>>> 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`](https://dsm-72.github.io/nist/fact.html#fact) uses `efmt`
for its representation by default `efmt` is True, but can be turned off
by setting `efmt` to False.
``` python
>>> (
(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:
``` python
>>> kilo().fstr, kilo(showbase=True).bstr, kilo(showbase=True).efmt
('F3P', '10^+3', 'e+3')
```
### [`unit`](https://dsm-72.github.io/nist/unit.html#unit)
The goal of the [`unit`](https://dsm-72.github.io/nist/unit.html#unit)
class is to make it easy to create units:
``` python
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:
``` python
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 |
Raw data
{
"_id": null,
"home_page": "https://github.com/dsm-72/nist",
"name": "nist",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": "",
"keywords": "nbdev jupyter notebook python byte bytes kilo tera giga unit dataclass strenum",
"author": "dsm-72",
"author_email": "sumner.magruder@yale.edu",
"download_url": "https://files.pythonhosted.org/packages/80/26/28ceb116d563abda23c67d413277fb0f21c83204825c123bd6dd7631ec2f/nist-0.0.2.tar.gz",
"platform": null,
"description": "# nist\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nFrom the [National Institute of Standards and\nTechnology](https://www.nist.gov)\u2019s [Office OF Weights and\nMeasures](https://www.nist.gov/pml/owm), one can find a handy list of\nall the [metric\nprefixes](https://www.nist.gov/pml/owm/metric-si-prefixes#:~:text=Prefix%20Total&text=Eight%20original%20SI%20prefixes%20were,from%20Greek%20and%20Latin%20numbers.):\ne.g.\n\n| Purpose | Name | Symbol | Factor | Name |\n|----------------------------------|----------------------------|--------|--------------|--------------|\n| larger quantities or whole units | quetta | Q | $$10^{30}$$ | nonillion |\n| | ronna | R | $$10^{27}$$ | octillion |\n| | yotta | Y | $$10^{24}$$ | septillion |\n| | \u2026 | \u2026 | \u2026 | \u2026 |\n| | hecto Example: hectare | h | $$10^{2}$$ | hundred |\n| | deka Example: dekameter | da | $$10^{1}$$ | ten |\n| | | | $$10^{o}$$ | one |\n| | deci Example: decimeter | da | $$10^{-1}$$ | tenth |\n| | centi Example: centigram | h | $$10^{-2}$$ | hundredth |\n| | \u2026 | \u2026 | \u2026 | \u2026 |\n| | yocto Example: yoctosecond | y | $$10^{-24}$$ | septillionth |\n| | ronto | r | $$10^{-27}$$ | octillionth |\n| smaller quantities or sub units | quecto | q | $$10^{-30}$$ | nonillionth |\n\nOh how nice it would be to have a class like\n[`unit`](https://dsm-72.github.io/nist/unit.html#unit) which we could\nsubclass and use as follows:\n\n``` python\nclass second(unit): \n name = 'second'\n\ns1 = second(1)\ns1, s1.kilo, s1.milli, s1.to(3), float(s1.to(3))\n(1.0 S, 0.001 KS, 1000.0 mS, 0.001 KS, 0.001)\n```\n\nah so easy to convert between and even have clean formatting.\n\n## Install\n\n``` sh\npip install nist\n```\n\n## Usage\n\n### [`fact`](https://dsm-72.github.io/nist/fact.html#fact)\n\nWhile each [`fact`](https://dsm-72.github.io/nist/fact.html#fact)\n(factor) has `base: ClassVar[int] = 10`, `base` is actually an instance\nvariable.\n\n``` python\n>>> float(kilo()), float(kilo(base=2)), float(kilo(base=5)), float(kilo(base=10))\n\n(1000.0, 8.0, 125.0, 1000.0)\n```\n\nIn case that behavior is not obvious\n[`fact`](https://dsm-72.github.io/nist/fact.html#fact) is really just a\nnamed and explicilty signed exponent:\n\n``` python\n>>> kb = kilo(base=2)\n>>> kb.abrv, kb.base, kb.expo, kb.sign, kb.ekey, float(kb)\n\n('kilo', 2, 3, 1, 3, 8.0)\n```\n\nEach [`fact`](https://dsm-72.github.io/nist/fact.html#fact) uses `efmt`\nfor its representation by default `efmt` is True, but can be turned off\nby setting `efmt` to False.\n\n``` python\n>>> (\n (decka(), hecto(), kilo(), mega(), giga(), tera()),\n (decka(showefmt=False), hecto(showefmt=False), kilo(showefmt=False), mega(showefmt=False), giga(showefmt=False), tera(showefmt=False))\n)\n\n((e+1, e+2, e+3, e+6, e+9, e+12), (F1P, F2P, F3P, F6P, F9P, F12P))\n```\n\nActually we have three formats to work with:\n\n``` python\n>>> kilo().fstr, kilo(showbase=True).bstr, kilo(showbase=True).efmt\n\n('F3P', '10^+3', 'e+3')\n```\n\n### [`unit`](https://dsm-72.github.io/nist/unit.html#unit)\n\nThe goal of the [`unit`](https://dsm-72.github.io/nist/unit.html#unit)\nclass is to make it easy to create units:\n\n``` python\nclass second(unit): \n name = 'second'\n\n>>> s1 = second(1)\n>>> s1, s1.kilo, s1.milli, s1.to(3), float(s1.to(3)), s1.shownumb\n\n\n(1.0 S, 0.001 KS, 1000.0 mS, 0.001 KS, 0.001, True)\n```\n\nWe can also explore all the different ways of viewing formats:\n\n``` python\nimport pandas as pd\n\nresults = list()\nfactors = (tera, decka, deci, centi, milli, pico)\nfor fcls in factors:\n for flt in (1, 20, 0.03):\n for factrepr in {'abrv', 'name', 'symb'}:\n for shownumb in (True, False):\n for abrvunit in (True, False):\n res = fmtunit(\n org = flt, flt=flt / float(fcls()), unt = unit, fct = fcls,\n factrepr=factrepr, shownumb=shownumb, abrvunit=abrvunit,\n unitname='second', factname=None, ndig=3\n )\n \n results.append(dict(\n fname=fcls.name, flt=flt, res=res, org = flt / float(fcls()),\n shownumb=shownumb, abrvunit=abrvunit, factrepr=factrepr\n ))\n\ndf = pd.DataFrame(results).sort_values(by=['fname', 'res'])\ndf.head()\n```\n\n| | fname | flt | res | org | shownumb | abrvunit | factrepr |\n|----:|:----------|-----:|:-------------|----:|:---------|:---------|:---------|\n| 134 | hundredth | 0.03 | 0.03 S | 3 | False | True | name |\n| 138 | hundredth | 0.03 | 0.03 S | 3 | False | True | abrv |\n| 142 | hundredth | 0.03 | 0.03 S | 3 | False | True | symb |\n| 143 | hundredth | 0.03 | 0.03 S | 3 | False | False | symb |\n| 135 | hundredth | 0.03 | 0.03 seconds | 3 | False | False | name |\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "si type metric",
"version": "0.0.2",
"project_urls": {
"Homepage": "https://github.com/dsm-72/nist"
},
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python",
"byte",
"bytes",
"kilo",
"tera",
"giga",
"unit",
"dataclass",
"strenum"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4a162711b10fa14b5f102da511c13ebb4ae1cb6ab9d43e7f772b4e7f64751603",
"md5": "7955f03273d5ffdbc7942be75ccc3a99",
"sha256": "2c462589ca4cce41940bf5340a0bd4e10f193cbbddf429291d5e2a0c207feb8d"
},
"downloads": -1,
"filename": "nist-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7955f03273d5ffdbc7942be75ccc3a99",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 19594,
"upload_time": "2023-10-08T17:14:48",
"upload_time_iso_8601": "2023-10-08T17:14:48.495956Z",
"url": "https://files.pythonhosted.org/packages/4a/16/2711b10fa14b5f102da511c13ebb4ae1cb6ab9d43e7f772b4e7f64751603/nist-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "802628ceb116d563abda23c67d413277fb0f21c83204825c123bd6dd7631ec2f",
"md5": "f07d9d4d6e076bc8b9c5f47d708c607e",
"sha256": "02656b95981f88ba17157a9141788309ff3aaf0f0502db132a14fe18817b5219"
},
"downloads": -1,
"filename": "nist-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "f07d9d4d6e076bc8b9c5f47d708c607e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 18126,
"upload_time": "2023-10-08T17:14:49",
"upload_time_iso_8601": "2023-10-08T17:14:49.820514Z",
"url": "https://files.pythonhosted.org/packages/80/26/28ceb116d563abda23c67d413277fb0f21c83204825c123bd6dd7631ec2f/nist-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-08 17:14:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dsm-72",
"github_project": "nist",
"github_not_found": true,
"lcname": "nist"
}