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

pipeline status coverage report

D-SI Parser

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

Instalaltion

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 weather 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 weather 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 pers and the combinig 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')
scalfactor,baseUnit=mps.isScalablyEqualTo(kmh)
print("The unit "+str(mps)+" is equal to "+str(kmh)+"with a factor of ",scalfactor," 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.1.tar.gz (38.7 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.1-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dsiunits-2.2.1.tar.gz
  • Upload date:
  • Size: 38.7 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.1.tar.gz
Algorithm Hash digest
SHA256 cd26aca01ececb3b080fd4e6bd319db8bbfdec12b03c906d6197299fdad81866
MD5 8e07bab7755840ff5c632e9cc1af1cdc
BLAKE2b-256 fe4bda05dbca8744956c58663b84a883eeffd2c4f5aea123184d4340fc1f897a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dsiunits-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 31.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9cdd7308261f3bc41e1f9867d7db115ab027142b6b6beb7edeb7a6930f71425
MD5 ad63bf0eb2acc677ac90a06742b665d0
BLAKE2b-256 ca1b9505695ad8e5ae6b4259fb51fe6890e2b8bb231138ea68125be3c8c879e2

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