SITypes Wrappers
The SITypes module provides Python wrappers for physical units, dimensions, and scalar quantities with automatic dimensional analysis and unit conversion. This system eliminates unit conversion errors and enables confident scientific computing with built-in dimensional safety.
Overview
Eliminate Unit Conversion Errors
The Scalar class combines a numerical value with a physical unit, enabling type-safe scientific computing with automatic dimensional analysis and unit conversion. This is the primary class for working with physical quantities.
Traditional scientific computing is error-prone:
# Traditional approach (ERROR-PRONE!)
distance_m = 1000 # meters? feet? who knows?
time_s = 3600 # seconds? minutes?
speed = distance_m / time_s # Units completely lost!
With Scalar, units are tracked automatically:
# Safe approach with Scalar
distance = Scalar("1000 m") # Clearly 1000 meters
time = Scalar("1 h") # Clearly 1 hour
speed = distance / time # Units calculated automatically!
print(speed)
# Output: 277.778 m/s
# Convert to any compatible unit instantly
speed_kmh = speed.to("km/h")
print(speed_kmh)
# Output: 1000.0 km/h
speed_mph = speed.to("mph")
print(speed_mph)
# Output: 621.371 mph
Key Benefits
Dimensional Safety: Prevents adding incompatible quantities (length + time)
Automatic Unit Derivation: Multiplication/division creates correct derived units
Effortless Conversions: Convert between any compatible units instantly
Scientific Accuracy: Built on precise SI definitions and constants
Complex Number Support: Full support for engineering applications
Mathematical Functions: Complete function library (trig, log, exp, roots) that preserves units
Chemical Database: Built-in atomic weights, isotopic properties, and NMR parameters
Available Mathematical Functions
The following mathematical functions can be used within Scalar expressions. These functions enable complex scientific calculations while maintaining dimensional analysis:
Trigonometric Functions
Function |
Description |
|---|---|
|
Sine of x (x in radians or degrees with °) |
|
Cosine of x (x in radians or degrees with °) |
|
Tangent of x (x in radians or degrees with °) |
|
Inverse sine of x (returns radians) |
|
Inverse cosine of x (returns radians) |
|
Inverse tangent of x (returns radians) |
Hyperbolic Functions
Function |
Description |
|---|---|
|
Hyperbolic sine of x |
|
Hyperbolic cosine of x |
|
Hyperbolic tangent of x |
|
Inverse hyperbolic sine of x |
|
Inverse hyperbolic cosine of x |
|
Inverse hyperbolic tangent of x |
Exponential and Logarithmic Functions
Function |
Description |
|---|---|
|
Exponential function (e^x) |
|
Natural logarithm (base e) |
|
Base 10 logarithm |
|
Base 2 logarithm |
Root Functions
Function |
Description |
|---|---|
|
Square root of x |
|
Cube root of x |
|
Quartic (fourth) root of x |
Complex Number Functions
Function |
Description |
|---|---|
|
Complex conjugate of x |
|
Real part of complex number x |
|
Imaginary part of complex number x |
|
Argument (phase angle) of complex number x |
Chemical and Physical Constants
Built-in database of atomic, isotopic, and NMR properties accessible in string expressions:
Function |
Description |
|---|---|
|
Atomic weight of element (e.g., |
|
Formula weight of chemical compound (e.g., |
|
Natural abundance of isotope (e.g., |
Nuclear Magnetic Resonance (NMR) Properties
Function |
Description |
|---|---|
|
Gyromagnetic ratio of isotope (e.g., |
|
Nuclear magnetic dipole moment (e.g., |
|
Nuclear electric quadrupole moment (e.g., |
|
Reduced gyromagnetic ratio for NMR (e.g., |
|
Nuclear spin quantum number (e.g., |
Mathematical Constants
Constant |
Description |
|---|---|
|
Pi (3.14159…) |
|
Euler’s number (2.71828…) |
Physical Constants
SITypes includes a comprehensive database of fundamental physical constants. Simply use the suggested symbol in string expressions - no need to remember values or units:
Symbol |
Constant |
Value in Coherent Derived SI Units |
|---|---|---|
|
Avogadro constant |
6.022140857E+23 (1/mol) |
|
Bohr magneton |
9.274009992054043E-24 m²·A |
|
Boltzmann constant |
1.38064852E-23 m²·kg/(s²·K) |
|
Characteristic impedance of vacuum |
376.7303134617707 m²·kg/(s³·A²) |
|
Compton wavelength |
2.42631023609262E-12 m |
|
Electric constant |
8.854187817620413E-12 s⁴·A²/(m³·kg) |
|
Electron g factor |
-2.00231930436182 m²·A/(m²·A) |
|
Electron magnetic moment |
-9.28476462E-24 m²·A |
|
Electron mass |
9.10938356E-31 kg |
|
Elementary charge |
1.6021766208E-19 s·A |
|
Fine structure constant |
0.007297352566206478 m⁵·kg·s⁴·A²/(m⁵·kg·s⁴·A²) |
|
Gas constant |
8.314459861448581 m²·kg/(s²·K·mol) |
|
Newton gravitational constant |
6.67408E-11 m³/(kg·s²) |
|
Gravity acceleration |
9.80665 m/s² |
|
Magnetic constant |
1.256637061435917E-06 m·kg/(s²·A²) |
|
Magnetic flux quantum |
2.067833831170082E-15 m²·kg/(s²·A) |
|
Muon g factor |
-2.0023318418 m²·A/(m²·A) |
|
Muon magnetic moment |
-4.49044826E-26 m²·A |
|
Muon mass |
1.883531594E-28 kg |
|
Neutron g factor |
-3.82608545 m²·A/(m²·A) |
|
Neutron magnetic moment |
-9.662365E-27 m²·A |
|
Neutron mass |
1.674927471E-27 kg |
|
Nuclear magneton |
5.050783698211084E-27 m²·A |
|
Planck constant |
6.62607004E-34 m²·kg/s |
|
Proton g factor |
5.585694702 m²·A/(m²·A) |
|
Proton magnetic moment |
1.4106067873E-26 m²·A |
|
Proton mass |
1.672621898E-27 kg |
|
Reduced Planck constant |
1.054571800139113E-34 m³·kg/(m·s) |
|
Rydberg constant |
10973731.5705508 (1/m) |
|
Speed of light |
299792458 m/s |
|
Stefan-Boltzmann constant |
5.670367E-08 m²·kg/(m²·s³·K⁴) |
|
Wien wavelength displacement constant |
0.0028977729 m·K |
Usage Examples:
# Use any physical constant directly in expressions
kinetic_energy = Scalar("0.5 * m_e * (c_0 * 0.1)^2") # Relativistic energy
gas_pressure = Scalar("0.1 mol * R * 298 K / 0.001 m^3") # Ideal gas law
bohr_radius = Scalar("hbar^2 / (m_e * q_e^2 * k_e)") # Atomic physics
# No need to remember: R = 8.314 J/(mol·K) - just use "R"!
# No need to remember: c = 299792458 m/s - just use "c_0"!
Unit Operations
Function |
Description |
|---|---|
|
Simplify derived units to their most basic form |
Classes
Module Reference
The detailed API documentation for each class is available in the following pages:
Scalar - Scalar class with units and dimensional analysis
Unit - Unit class for physical units
- Dimensionality - Dimensionality class for dimensional analysis
- undoc-members:
- show-inheritance: