Skip to main content

A powerful class for physical unit and dimensional analysis in engineering applications.

Project description

🔬 Python Dimensional Analysis (Unit Class)A powerful, standalone Python class (Unit) for representing physical quantities with dimensions, enabling arithmetic operations while automatically handling metric prefixes and verifying dimensional consistency.

This library is ideal for students, engineers, and researchers who need reliable tracking of units (like N, m, J, s) and their corresponding prefixes (k, M, m, µ) during complex calculations.

✨ Key Features:

  • Dimensional Consistency Check: Automatically prevents illegal operations, such as adding Newtons (N) to meters (m).
  • Metric Prefix Handling: Seamlessly convert between prefixes (e.g., 1 kN + 500 N works and returns 1.5 kN).
  • Auto-Scaling (.auto_scale()): Intelligently adjusts the displayed prefix to keep the numerical value in a readable range (e.g., 12000 N becomes 12 kN or 0.005 A becomes 5 mA).
  • Full Operator Overloading: Supports standard arithmetic: +, -, *, /, and exponentiation (**).
  • Complex Unit Simplification: Automatically combines and cancels units in multiplication and division (e.g., N * m / s^2).

📦 Quick StartThe class is defined entirely in Unit.py. Simply import and begin calculating.

  1. InstallationIf published, installation would look like this:
pip install unit-dimensional-analysis
  1. Real-World Usage (Structural Engineering Example)This demonstrates calculating the total design force and checking a column's resistance, handling conversions between units like $\text{kN/cm}^2$ and $\text{kN/kg}$ automatically.from Unit import Unit

Define input data

N_Ed = Unit(750, "", "kN", "")          # Design Axial Force: 750 kN
f_y = Unit(23.5, "", "kN", "cm*cm")     # Steel Yield Strength: 23.5 kN/cm^2
H = Unit(540, "", "cm", "")             # Column Height: 540 cm

Cross-section area (A) and linear mass (G)

profil_slupa = {
    "A": Unit(164, "", "cm*cm", ""),
    "G": Unit(83.2, "", "kg", "m"),     # 83.2 kg/m
}


# 1. Calculate Self-Weight Force (N_self_weight)
# g_accel is needed to convert mass/length [kg/m] to force/length [kN/m]
g_accel = Unit(9.81, "m", "kN", "kg") # (9.81 m/s^2 is used to match kN/kg)

# Linear weight: [kg/m] * [m/s^2] * [factor] -> [N/m]
g_kslup = profil_slupa["G"] * g_accel

# Total self-weight force (in base units)
H_m = Unit(H.value / 100, "", "m", "") # Convert height to meters
N_self_weight = g_kslup * H_m * 1.35
print(f"Force from self-weight: {N_self_weight}")

# 2. Total Design Force (Demonstrates Addition with Different Prefixes)
# 750 [kN] + 5.95 [N]
N_Edmax = N_Ed + N_self_weight
print(f"\nN_Ed,max (Automatically Scaled): {N_Edmax.auto_scale()}")

# 3. Cross-section Compression Resistance (N_cRd)
# Resistance = Area * Yield Strength
N_cRd = profil_slupa["A"] * f_y / 1.0
print(f"Resistance N_cRd (Automatically Scaled): {N_cRd.auto_scale()}")

🛠️ Running the ExampleThe included if name == "main": block demonstrates the library's features.python Unit.py

🔮 Future Roadmap

  • Implement a Unit.from_string("100 kN/m^2") parser for easier instantiation.
  • Add support for common non-metric units (e.g., "in", "ft", "psi", "lbf").
  • Add the capability to define and use Aliases (e.g., treating N*m as J).👨‍💻

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

unit_analysis_package-1.0.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unit_analysis_package-1.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file unit_analysis_package-1.0.1.tar.gz.

File metadata

  • Download URL: unit_analysis_package-1.0.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for unit_analysis_package-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b910ff6cce7a64e9fcf71620e7b5b1506d90bb41ebfd9da436ad800fdfcadabf
MD5 f692b187f79d63d89e93ff37232b915a
BLAKE2b-256 98cca21b788dde53f789882f54635549ec4478ac4d47264ba37c05afb5fbb5df

See more details on using hashes here.

File details

Details for the file unit_analysis_package-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for unit_analysis_package-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1731914974914fdf123efff23327d0383f3d5f2ef95c6f4835c5454149f76e7
MD5 3b327ef68570b5de9ee4c60ff9f876df
BLAKE2b-256 62c3509224006d5df281b5cd200e4c36980abbf8987b21c659e5536951d9e74d

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