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
File details
Details for the file sicalc-0.2.1.tar.gz
.
File metadata
- Download URL: sicalc-0.2.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5c964c586de3898f5c2bbb924a2cd9104bc80e5d40a98ff59434b2239e1f2c3 |
|
MD5 | e8981825d22b2cec1933cfb3478b32a2 |
|
BLAKE2b-256 | 0f68d4cd8a1f0ca5d2250532395bcb9e42593b2b438a1b1c6278324eaca759e6 |