pyteeauc - An Object-Oriented Unit Conversion Repository
Abstract
Documentation of tool development at DLR for an object-oriented unit conversion repository for techno-economic analyses (TEA) and life cycle assessments (LCA).
Full text
pyteeauc - An Object-Oriented Unit Conversion Repository pyteeauc provides a object-oriented, lightweight, extensible unit-conversion and calculation layer built on top of pint. It introduces custom value objects to standardize how quantities are represented and manipulated across the codebase, and includes domain-specific unit definitions and translations for Aspen Plus® and Brightway unit formats to SI units. Key Features Unified quantity abstraction in value and unit format to provide a consistent interface across the codebase Domain-specific unit translation from heterogeneous unit formats into SIcompatible units Custom unit definitions and aliases Support for scalar and vectorized values Encapsulates pint usage behind a stable API Requirements The required publicly available libraries are listed below. Usage Unit translation Before converting units, the domain-specific units should be translated into SIcompatible units. • • • • • dependencies = [ "numpy>=1.24.3", "pint>=0.23", "pydantic>=2.6.2", "PyYAML>=6.0", "pytest>=7.3.1" ] requires-python =">=3.10"
Unit calculation and conversion with abstracted ValueUnit objects The ValueUnit object simplifies mathematical operations with other ValueUnit object’s and scalars. The object possesses a function for unit conversion to a target unit and unit reduction, which is especially useful after mathematical operations. License BSD 3-Clause License Copyright (c) 2025, DLR-TT-TEA / Julia Weyand, Simon Maier All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, from pyteeauc import unit_conversion as uc # To translate Aspen Plus to SI unit unit = uc.translate_aspen_to_si_unit('cum') # To translate Brightway to SI unit unit = uc.translate_bw_to_si_unit('ton kilometer') from pyteeauc import value_unit as vu value_unit = vu.ValueUnit(50,'MW') # Convert one unit into a target unit converted_value_unit = value_unit.get_value_for_target_unit('kWh/h') value_unit = vu.ValueUnit(231,'kg/h') * vu.ValueUnit(40,'MJ/kg') # Reduce unit from extended to simplified format after mathematical operation with other ValueUnit, e.g., kg/h*MJ/kg to MJ/h reduced_value_unit = value_unit.get_reduced_unit() 1. 2. 3.
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.