Skip to main content

A package for SI units and uncertainty

Project description

siunitpy

SI-Unit-Py is a Python package for dealing with units.

This package implements NIST (National Institute of Standards and Technology) official unit definitions.

Moreover, it introduce uncertainty.

Installation

pip installable package: pypi: siunit

pip install siunitpy

Quickstart: module siunitpy.SI

import module siunitpy.SI to use 3 very useful classes: SI, si and prefix.

SI: common physical constants

use physical constants through class SI:

>>> from siunitpy.SI import SI
>>> SI.c
Constant(value=299792458, unit=m/s, uncertainty=0)
>>> print(SI.me)
9.1093837015e-31 ± 2.8e-40 kg
>>> print(SI.me * SI.c**2)
8.187105776823886e-14 ± 2.516514500463089e-23 J

constant class SI provide physical constants defined by (or derived from) SI unit system.

si: common SI units

use units through class si:

>>> from siunitpy.SI import si
>>> print(1 * si.kg * si.m / si.s**2)
1.0 N
>>> print(760 * si.mmHg.to("Pa"))
101325.0 Pa

prefix: unit prefix factor

class prefix contains prefix from quetta(Q, = 1e30) to quecto(q, = 1e-30), and byte prefix like ki(2^10, 1024), Mi(2^20), Gi(2^30)... It's just a number factor, not Quantity.

>>> from siunitpy.SI import prefix
>>> prefix.mega
1000000.0
>>> prefix.Pi  # 2**50
1125899906842624

Define Quantity

import siunit to define a Quantity object:

>>> from siunitpy import Quantity
>>> F = Quantity(1, 'kg.m/s2')
>>> L = Quantity(1, 'm', 1e-4)  # with uncertainty

where F is a Quantity object, and it has properties:

>>> F.value
1
>>> F.unit
Unit(kg·m/s², dim=(1, 1, -2, 0, 0, 0, 0), value=1)
>>> F.dimension
Dimension(L=1, M=1, T=-2, I=0, H=0, N=0, J=0)
>>> L.uncertainty
1e-4

objects in SI are also Quantity objects.

Quantity objects can make unit conversion and operate with number or Quantity:

>>> print(SI.me.to("keV/c2"))  # unit conversion
510.99894999616424 ± 1.5706848090652466e-07 keV/c²
>>> print(F / (1 * si.m)**2)
1.0 Pa

Especially, it provides temperature unit system:

>>> from siunitpy import degree
>>> print((100 * degree.F).to(degree.C.unit))
37.77777777777778 °C

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

siunitpy-0.0.2.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

siunitpy-0.0.2-py3-none-any.whl (45.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for siunitpy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 357f8cbff0129d563117e51fba6d3773c54e7b3e6e777a0ab7371357d5752c50
MD5 5f8f01c89b70d4242a2f764d9c72976c
BLAKE2b-256 4ed65d24ca64aa3a5662599bff9134e1aab5c1e80696257af88e622388ac4d2b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for siunitpy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c0cfd37b04a2f419aa045f8bb2fc052acb89fc3568e662d6cdf79289aedd39f5
MD5 1f43ade05441f6f6d1efb2b477fc1ecf
BLAKE2b-256 5b15c416ad2062c5aa149fe760faad63546716af64295c0a66faa2b6bc1891d8

See more details on using hashes here.

Supported by

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