Skip to main content

SI units and quantities library

Project description

PyPi Package Build Status Code Coverage

siquant is a simple pure python 3 library to make dimensional analysis painless.

Getting Started

Dimensional Analysis

>>> from siquant.systems import si
>>> force = 100 * si.kilonewtons
>>> moment_arm = 50 * si.meters
>>> torque = force * moment_arm
>>> torque.quantity
5000
>>> str(torque.units)
'1000*kg**1*m**2*s**-2'
>>> torque.get_as(si.newtons * si.meters)
5000000.0
>>> torque.get_as(si.newtons)
Traceback (most recent call last):
  ...
siquant.exceptions.UnitMismatchError: ...

>>> torque = torque.cvt_to(si.newtons * si.meters)
>>> torque.quantity
5000000.0
>>> str(torque.units)
'1*kg**1*m**2*s**-2'

Validation

>>> from siquant.dimensions import force, area, stress
>>> from siquant.systems import si

>>> def normal_stress(force_q, area_q):
...     assert force_q.is_of(force)
...     assert area_q.is_of(area)
...     return force_q / area_q

>>> stress_q = normal_stress(1 * si.newtons, 1 * si.meters ** 2)
>>> stress_q.is_of(stress)
True
>>> stress_q.is_of(area)
False

Sometimes you might want to check for dimensions that aren’t provided by default.

>>> from siquant.dimensions import SIDimensions
>>> from siquant.systems import si

>>> new_dim = SIDimensions(kg=1, m=1, s=1, k=1, a=1, mol=1, cd=1)
>>> dist_q = 1 * si.meters
>>> dist_q.is_of(new_dim)
False

Normalization

>>> from siquant import ScalarQuantity
>>> from siquant.systems import si

>>> meters_cvt = ScalarQuantity.As(si.meters)

>>> dist_q = meters_cvt(1000 * si.millimeters)
>>> dist_q.quantity
1

>>> dist_q = meters_cvt(1000 * si.meters)
>>> dist_q.quantity
1000

>>> dist_q = meters_cvt(1000)
>>> dist_q.quantity
1000

New Units

SIUnit can be created directly by factory:

>>> from siquant.units import SIUnit
>>> fathom = SIUnit.Unit(1.8288, m=1)
SIUnit(1.8288, (0, 1, 0, 0, 0, 0, 0))

Alternatively they can be derived:

>>> from siquant.systems import si
>>> rpm = si.unity / si.minutes
>>> rpm
SIUnit(0.016667, (0, 0, -1, 0, 0, 0, 0))

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

siquant-3.0.5.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

siquant-3.0.5-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file siquant-3.0.5.tar.gz.

File metadata

  • Download URL: siquant-3.0.5.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for siquant-3.0.5.tar.gz
Algorithm Hash digest
SHA256 d8150072b43ec1f604ef0ab35807946be3c30f71da0515657fdb8c7079d17ebe
MD5 b3411feb099dd6aa3e979ebecb0adca0
BLAKE2b-256 9b07bb486e5080e4997ffa5f2f79209e1cc36337b4b5b5fc6e62cdb6dd8502ee

See more details on using hashes here.

File details

Details for the file siquant-3.0.5-py3-none-any.whl.

File metadata

  • Download URL: siquant-3.0.5-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for siquant-3.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7efc36503c09186b259290a456373a0b605c0b4244fa02352821cc702fa3eb85
MD5 a9b336afad49e9aa14e68a682cf2fd31
BLAKE2b-256 f8820353dc6cd951e58e3e82e9190942031cf0cc94186a8b6832e44283b4ba9f

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