ucon
Pronounced: yoo · cahn
Background
Numbers are particularly helpful when describing quantities of some thing (say, 42 ice cream cones
Introduction
Since the metric scale is fairly ubiquitous and straightfowrward to count with (being base 10 and all..), ucon
uses the Metric System as the basis for measurement though binary prefixes are also supported.
The crux of this tiny library is to provide abstractions that simplify the answering of questions like:
"If given two milliliters of bromine (liquid Br2), how many grams of bromine does one have?"
To best answer this question, we turn to an age-old technique (dimensional analysis) which essentially allows for the solution to be written as a product of ratios.
2 mL bromine | 3.119 g bromine
--------------x----------------- #=> 6.238 g bromine
1 | 1 mL bromine
Setup
Ensure nox
is installed.
pip install nox
Run nox -s ucon
to install ucon
and run tests.
Usage
The above calculation can be achieved using types defined in the ucon
module.
two_milliliters_bromine = Number(unit=Units.liter, scale=Scale.milli, quantity=2)
bromine_density = Ratio(numerator=Number(unit=Units.gram, quantity=3.119)
denominator=Number(unit=Units.liter, scale=Scale.milli))
two_milliliters_bromine * bromine_density #=> <6.238 gram>
One can also arbitrarily change scale:
answer = two_milliliters_bromine * bromine_density #=> <6.238 gram>
answer.to(Scale.milli) #=> <6238.0 milligram>
answer.to(Scale.kibi) #=> <0.006091796875 kibigram>