Skip to main content

a tool for dimensional analysis: a "Unit CONverter"

Project description

ucon

Pronounced: yoo · cahn

tests publish

Background

Numbers are particularly helpful when describing quantities of some thing (say, 42 ice cream cones 🍦). They are also useful when describing characteristics of a thing such as it's weight or volume. Being able to describe a thing by measurements of its defining features and even monitoring said features over time, is foundational to developing an understanding of how the thing works in the world. "Units" is the general term for those quantifying descriptors that characterize an object. Specific units include those like grams for weight, liter for volume, and even the jiffy for time. With means to refer to an object's physical characteristics, their extent can be communicated using a scale to answer the question: "how many of a given unit accurately describe that aspect of the object?".

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>

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

ucon-0.2.2.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file ucon-0.2.2.tar.gz.

File metadata

  • Download URL: ucon-0.2.2.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for ucon-0.2.2.tar.gz
Algorithm Hash digest
SHA256 c65141f5b04cf8115f7d55338c0149093054f2ce3e3541a89b1ce51ac943ac38
MD5 7b993565b0c6a0c2aece8fad0c059b9a
BLAKE2b-256 b25afa9e38880dd6109199c2a30861cfb91ecceddcef1f8f0b34cfbbe35c1450

See more details on using hashes here.

Supported by

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