Skip to main content

No project description provided

Project description

Sicalc

Some tools to make physic class easier by handling the SI Units.

Installation

The installation works simply via pip:

pip install sicalc

Usage

Simply import the units you need and calculate with them! A number (float/int) will be associated with the unit by multiplication giving an instance of ValueWithUnit. By the multiplication of two of those instances we get a new ValueWithUnit-instance which keeps track of the multiplied units.

from sicalc.units import m, s
velocity = 20_000 * m / s
t = 60*s
distance = velocity * t
print(distance) # --> <1.20000E+06, m>

The common unit prefixes are defined aswell.

from sicalc.units import m, s, kilo
km = kilo*m
velocity = 20 * km / s
t = 60*s
distance = velocity * t
print(distance) # --> <1.20000E+06, m>

Most constants are defined by the package too:

from sicalc.units import s
from sicalc.constants import c
print(5*s*c)

When adding two values, make sure those are of the same unit.

from sicalc.units import m, s, kg, N
F1 = 5*N
F2 = kg*m/s**2
P = kg*m/s
F = F1 + F2 # correct
F + P # wrong, will give an Exception :(

Using functions like math.sqrt wont work. Therefor common functions are provided in sicalc.func. Note that these functions check unit behaviour too:

from sicalc.units import m
from sicalc.func import sqrt, ln
d1 = 2*m
d2 = 3*m

# will work
print(ln(d1/d2)) # --> The parameter of ln must not have a unit
print(sqrt(d1*d2)) # --> The parameter of sqrt requires, that all power of units are dividable by 2, e.g. m**2, m**4, kg*kg/(s*s)

# wont work
print(ln(d1)) # --> ln cant handle a unit
print(sqrt(d1)) # --> What should be the square-root of the unit "meter"??

numpy support

Numpy arrays seem to work as values too. Note that not all functions are tested yet.

from sicalc.units import m, s
import numpy as np
d = np.array([1, 2, 3])*m
t = np.array([4, 5, 6])*s
v = d/t
print(v)
# Output: [<250.00000E-03, m^1*s^-1> <400.00000E-03, m^1*s^-1>
 <500.00000E-03, m^1*s^-1>]

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

sicalc-0.2.2.tar.gz (7.5 kB view details)

Uploaded Source

File details

Details for the file sicalc-0.2.2.tar.gz.

File metadata

  • Download URL: sicalc-0.2.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for sicalc-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7753cb317e7203da9c400317d264d274805bf8b45a927ad6fc5acc0eb7b8c83f
MD5 a1098140987570e11c5b5d3dcda0de80
BLAKE2b-256 861cbe7344d98c325e9cbe19253c9292c84a3a722d84a3a7cdfd50400246eeae

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