A simple unit converter for chemical engineers
Project description
z-units
A simple unit-converter for chemical engineers
Features
- Gauge pressure units (MPag, kPag, psig, ...) with configurable atmospheric pressure
- Standard volume units (Sm³, Nm³) with configurable STP conditions
- Friendly to HYSYS users
- Rich formatting options
Installation
pip install z-units
Quickstart
>>> from z_unit import quantity as q
>>> f = q.MolarFlow(3)
>>> f
<MolarFlow(3, 'kmol/s')>
>>> f.value, f.unit
(3, <Unit('kmol/s')>)
>>> f.to('kmol/h')
<MolarFlow(10800.0, 'kmol/h')>
>>> q.Length(100, 'cm') == q.Length(1000, 'mm')
True
>>> q.Temperature('100C')
<Temperature(1, 'C')>
>>> q.Pressure(15, 'psi').to('MPag')
<Pressure(0.0020963594, 'MPag')>
>>> from z_unit import convert
>>> convert(1, 'm', 'ft')
<Length(3.2808399, 'ft')>
Advanced Features
Gauge Pressure Handling
The atmospheric pressure reference (default: 101325 Pa) can be configured globally:
>>> from z_unit.environment import get_env
# Before
>>> q.Pressure(100, 'kPa').to('kPag')
<Pressure(-1.325, 'kPag')>
# Set to 100 kPa
# atmospheric_pressure in Pa
>>> env = get_env()
>>> env.atmospheric_pressure = 100e3
# After
>>> q.Pressure(100, 'kPa').to('kPag')
<Pressure(0.0, 'kPag')>
Standard Volume Units
Standard temperature and pressure (STP) conditions can be configured for standard volume conversions:
>>> from z_unit.environment import get_env
# Default STP: 20°C, 101325 Pa
>>> q.Substance(100, 'Nm³').to('Sm³')
<Substance(107.321984, 'Sm³')>
# Change to 15°C, set value in K
>>> get_env().standard_temperature = 273.15 + 15
>>> q.Substance(100, 'Nm³').to('Sm³')
<Substance(105.491488, 'Sm³')>
Unit Formatting
Multiple formatting styles are supported:
>>> x = q.MolarEntropy(100)
# Only value
>>> f"{x}"
'100'
# Quick style (simplified)
>>> f"{x:q}"
'100 kJ/kmol-C'
# Python style (full)
>>> f"{x:p}"
'100 kJ/(kmol*C)'
Predefined Quantities
- Length (m, km, cm, mm, ft, in, ...)
- Area (m², km², ...)
- Volume (m³, L, mL, ...)
- Time (s, min, h, ...)
- Mass (kg, g, lb, ...)
- Force (N, kN, ...)
- Substance (mol, kmol, ...)
- Energy (J, kJ, kWh, ...)
- Velocity (m/s, km/h, ...)
- Temperature (K, °C, °F)
- DeltaTemperature (K, °C, °F)
- Pressure (Pa, kPa, MPa, bar, psi, ...) including gauge variants
- VolumeFlow (m³/s, L/min, ...)
- StandardGasFlow (Nm³/h, Sm³/h, ...)
- MolarFlow (mol/s, kmol/h, ...)
- MassFlow (kg/s, t/h, ...)
- Density (kg/m³, g/cm³, ...)
- MolarDensity (mol/m³, kmol/m³)
- HeatCapacity (J/(kg·K), kJ/(kg·K))
- MolarHeatCapacity (J/(mol·K), kJ/(kmol·K))
- Entropy (J/(kg·K), kJ/(kg·K))
- MolarEntropy (J/(mol·K), kJ/(kmol·K))
- ThermalConductivity (W/(m·K))
- Viscosity (Pa·s, cP)
- KinematicViscosity (m²/s, cSt)
- SurfaceTension (N/m)
- Dimensionless (-, %)
Environment Configuration
Global environment parameters can be configured:
>>> from z_unit.environment import get_env
# Set atmospheric pressure
>>> get_env().atmospheric_pressure = 100e3 # 100 kPa
# Set standard conditions
>>> get_env().standard_temperature = 273.15 # 0°C
>>> get_env().standard_pressure = 101325 # 1 atm
# Reset to defaults
>>> get_env().reset()
About
As a chemical engineer, the Gauge-Pressure units are very useful to me. Unfortunately those units are not supported in some popular modules, so I reinvent the wheel.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file z_units-0.1.8.tar.gz.
File metadata
- Download URL: z_units-0.1.8.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.22.4 CPython/3.13.2 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92395896e00538e44492f8696b2d67689d80118bab05f666e9b4db4bf5c02d23
|
|
| MD5 |
063e2e59b96a66faed7f66a4d6a947f9
|
|
| BLAKE2b-256 |
1dafff7a97e333f43e6af745d964224b24c8f9ed2d9552db2a578d439465d19b
|
File details
Details for the file z_units-0.1.8-py3-none-any.whl.
File metadata
- Download URL: z_units-0.1.8-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.22.4 CPython/3.13.2 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf3a8df7727511abbaaf210edee849a496bfe28790f11ca5f9b82a4d3cbc9352
|
|
| MD5 |
f7f0c1c8efc5ad0b05925df0a1805c3e
|
|
| BLAKE2b-256 |
88a9af27f89c52f0f1773d7e0a4a918fed280b1c41fe64bd4803c6797a4d32e7
|