hgrecco / pint

Operate and manipulate physical quantities in Python
http://pint.readthedocs.org/
Other
2.38k stars 465 forks source link

base units as default behaviour #1810

Open mhechthz opened 1 year ago

mhechthz commented 1 year ago

Would it be possible to get base units as default behaviour, to avoid setting it manually?

I have something like this (from metallurgy):

Unit.define('kgpt = kilogram / tonne')
slag_per_tonne = 20 * Unit.kgpt
steel          = 200 * Unit.tonne
total_slag     = (slag_per_tonne * steel).to_base_units()
print("total slag =",total_slag)

--> total slag = 4000.0 kilogram

I get without base_units() a unit kpts* metric_ton. This is right, but is slightly annoying. I would prefer a mode that always calculates the most basic available units.

P.S.: I totally love this library :-)

andrewgsavage commented 1 year ago

https://pint.readthedocs.io/en/latest/getting/tutorial.html#simplifying-units you can try using ureg.default_preferred_units which was added recently.

When the registry option for that I also noticed there were no auto to_base_units or 'to_compact' options. There should be a bit of thoguht on how to go about the order to apply the different options and what order to apply them.