Skip to main content

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>]

Release files for sicalc 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sicalc 0.2.2
File Size Uploaded
sicalc-0.2.2.tar.gz 7.5 kB Details

Release files / sicalc-0.2.2.tar.gz

Download URL sicalc-0.2.2.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7753cb317e7203da9c400317d264d274805bf8b45a927ad6fc5acc0eb7b8c83f
BLAKE2b-256 checksum
How to use checksums
861cbe7344d98c325e9cbe19253c9292c84a3a722d84a3a7cdfd50400246eeae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

0.2.2 This release

1 release file

0.2.1

1 release file

0.2

1 release file

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page