Skip to main content

This is a Python module for handling the SI units as objects in Python, parsing them from strings and converting them to Latex and Unicode, as well as performing math operations and calculating scale factors.

Project description

D-SI Parser

This library converts D-SI unit strings to Latex. And is able to perform math operations *, / and power with the D-SI units as well as checken weather teh can be converted into each other with scalar multiplication

Installation

pip install dsiUnits

Usage

The Constructor dsiUnit(str) will parse the string and create a dsiUnit object. The dsiUnit object has the following methods:

  • toLatex(): returns the Latex representation of the unit
  • toUTF8(): returns the UTF8 representation of the unit
  • isScalablyEqualTo(other): checks whether the unit is equal to another unit with scalar multiplication

And following magic functions:

  • __mul__(other): "*" multiplies the unit with another unit or a scalar

  • __truediv__(other): "/" divides the unit by another unit or a scalar

  • __pow__(other): "**" raises the unit to the power of another unit or a scalar

  • __eq__(other): "==" checks whether the unit is equal to another unit

  • __str__: "str()" returns the string representation of the unit

  • __repr__: returns the string representation of the unit

  • toBaseUnitTree(): returns the base unit tree of the unit

  • reduceFraction(): reduces the fraction of the unit by resolving all \per and combining same units by exponent addition

  • sortTree(): sorts the base unit tree of the unit

from dsiUnits import dsiUnit

unit = dsiUnit('\metre\second\tothe{-1}')
latexStr=unit.toLatex()
print(latexStr)
from dsiUnits import dsiUnit

mps = dsiUnit(r'\metre\second\tothe{-1}')
kmh = dsiUnit(r'\kilo\metre\per\hour')
scaleFactor, baseUnit = mps.isScalablyEqualTo(kmh)
print("The unit "+str(mps)+" is equal to "+str(kmh)+" with a factor of "+scaleFactor+" and base unit "+str(baseUnit))

For more usage examples see the Example Notebook, as well as the pytest file.

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

dsiunits-2.2.3.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dsiunits-2.2.3-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file dsiunits-2.2.3.tar.gz.

File metadata

  • Download URL: dsiunits-2.2.3.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for dsiunits-2.2.3.tar.gz
Algorithm Hash digest
SHA256 345890b878decee1b575fb87dea83b8d856b9450252fcb4a28a4b7ef7e4d0d99
MD5 ebcfd76cc01d650b32d116a74ed42e62
BLAKE2b-256 8040d5b7ab4530c71fc594f21d964e8b94a8ce9c422623e86cc1169836fdba5a

See more details on using hashes here.

File details

Details for the file dsiunits-2.2.3-py3-none-any.whl.

File metadata

  • Download URL: dsiunits-2.2.3-py3-none-any.whl
  • Upload date:
  • Size: 32.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for dsiunits-2.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ba5331136aec08a33fac4ca70732d0f16cf6390e62d4811d7a1063df9617f162
MD5 8dd0a81146a2d0aac5354be02df492ed
BLAKE2b-256 44ac1afd4afb428a3e8f4509511ec5f01e3cfe72d95ea522e0f8cd8c14a3ad85

See more details on using hashes here.

Supported by

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