TLDR: I'd like to have pint
quantities, that are in a certain (derived) dimension, to be converted into a pre-set unit by default.
Details:
I deal with 5 dimensions, as specified below. Note that [power] (usually in MW) and [price] (usually in Eur/MWh) are the derived dimensions.
# units.txt
# Base dimensions and their units
hour = [time] = h = hr
megawatthour = [energy] = MWh
euro = [currency] = Eur = €
# Derived dimensions and their units
[power] = [energy] / [time]
megawatt = megawatthour / hour = MW
[price] = [currency] / [energy]
euro_per_MWh = euro / megawatthour = Eur/MWh
My question: is it possible to specify that calculated quantities with dimension [power] are by default to be converted to MW?
Here's an example:
import pint
ureg = pint.UnitRegistry("units.txt",)
ureg.default_format = ".0f~P"
energy = 100 * ureg.MWh
time = 4 * ureg.h
revenue = 4000 * ureg.euro
price = revenue / energy
power = energy / time
print(energy, time, revenue, price, power)
# 100 MWh 4 h 4000 Eur 40 Eur/MWh 25 MWh/h
Here, the power is expressed in MWh/h, because of the way it is calculated, and I can 'convert' it to MW by calling power.to('MW')
. Is it possible to automatically do this every time a quantity in this dimension is calculated?
Note that doing a blanket .to_base_units()
on all quantities reverts it back to MWh/h.
Remarks:
- I don't want to use [power] as a base dimension. It moves the problem to the price anyway.
- I'm aware of prefixes; I just left them out here to keep the example as short as possible.