Skip to main content

Perform operations on SI units

Project description

image image image

SI Units

This is a library used to symbolically manipulate SI units. It comprises a BaseUnit type, used for base SI units like kilogram, meter etc, a DerivedUnit type, for units derived from them, and a Composite type, for when numerical coefficients are included. Python version 3.7 or greater is required. There are no dependencies.

This library is useful for dimensional analysis. It relies on the concept that SI units are all composed of varying exponents of 7 base units. We can think of all other units as linear combinations of base units.

You can perform normal multiplication, division, and power operations on units provided by this lib, and between them and ints and floats. You can check equality, based on the resulting combination of base units.

Install

pip install siunits

In Linux, you may need to use something like pip3 install siunits, or python3.7 -m pip install siunits.

Examples

A base unit:

import siunits as u

u.kg
>>> kilogram (kg), mass

A derived unit:

u.v
>>> volt (V), [kg: 1, m: 2, s: -3, A: -1]

Multiplication:

u.kg * u.s
>>> kilogram·second (kg·s), [kg: 1, s: 1]

Division:

u.j / u.m**2
>>> joule / meter² (kg·s⁻²), [kg: 1, s: -2]

u.s**2 / u.kg**3
>>> second²·kilogram⁻³ (s²·kg⁻³), [s: 2, kg: -3]

With numerical coefficients:

2*u.a**2 * 3*u.v**2
>>> 6kg²·m⁴·s⁻⁶

Equality testing is based on composition of base units:

u.w == u.v * u.a == u.kg * u.m**2 / u.s**3
>>> True

Todo

  • Infer composite types that match a given custom (eg multiplied) unit
  • Apply arithmetic to quantities as well (eg energy, work etc), and display them
  • Addition and subtraction

Scope

This project doesn't aim to provide conversions with other unit systems, like cgs and imperial, nor does it provide physical constants. For these tasks, try scipy.constants.

Why add another unit library?

The clean symbolic manipulation this library provides doesn't appear to exist in any existing one.

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

siunits-0.0.6.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

siunits-0.0.6-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file siunits-0.0.6.tar.gz.

File metadata

  • Download URL: siunits-0.0.6.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for siunits-0.0.6.tar.gz
Algorithm Hash digest
SHA256 649f4910f2eb47c2c5a2b4387c76a99bb241f21947728497aa22ed7b4d9a82fd
MD5 04217ef1d6a1d8d06b9407a91dba50b4
BLAKE2b-256 4758afc8be69af36f425b99f87aeb62723bda4e93d25a6bf167e799e409fc516

See more details on using hashes here.

File details

Details for the file siunits-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: siunits-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for siunits-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 962146ed26387b768696a619444c459bf04d3951ab3c4228906df87cd298f05e
MD5 329320ae207c448e880a865779a3d1f4
BLAKE2b-256 2266ee4a14b29263feee3629dcc00b72755a9b48336f77b73244deda807389af

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