Convert Units¶
Particula Index / Particula / Util / Converting / Convert Units
Auto-generated documentation for particula.util.converting.convert_units module.
get_unit_conversion¶
Show source in convert_units.py:29
Convert a numeric value or unit expression from one unit to another using Pint.
For simple multiplicative units, if no value is provided, this function returns the conversion factor. For units with an offset (e.g., temperatures), or if a value is supplied, a fully converted numeric value is returned instead.
Arguments¶
- old : A string representing the current unit (e.g., "m", "degC").
- new : A string representing the target unit.
- value : An optional numeric value to convert. If omitted, returns the conversion factor between old and new.
Raises¶
- ImportError : If Pint is not installed. Install it using:
pip install pint
.
Returns¶
- A float representing either the conversion factor or the fully converted value in the target unit.
Examples¶
Example Multi-Unit Conversion
import particula as par
factor = par.get_unit_conversion("ug/m^3", "kg/m^3")
print(factor)
# 1e-9
Example Temperature Conversion
import particula as par
degF = par.get_unit_conversion("degC", "degF", value=25)
print(degF)
# ~77.0
References¶
- Pint documentation: https://pint.readthedocs.io/
Signature¶
def get_unit_conversion(old: str, new: str, value: Optional[float] = None) -> float: ...