Get unit and not base unit

37 Views Asked by At

I am trying to get a more meaningful unit name when converting between unit systems.

In a separate file (custom_en.txt), I have defined a new unit system:

@system Nmm using international
    millimeter
    kilogram
    second
@end

I define a quantity of 1MPa:

import pint

UR = pint.UnitRegistry(system="SI", auto_reduce_dimensions=True)
UR.load_definitions("custom_en.txt")

q = 1.0 * UR.megapascal

I can express it in SI:

>>>UR.default_system = "SI"
>>>print("SI: " + str(q.to_base_units()))
SI: 1000000.0 kilogram / meter / second ** 2

in MKS:

>>>UR.default_system = "mks"
>>>print("mks: " + str(q.to_base_units()))
mks: 1000000.0 kilogram / meter / second ** 2

or in Nmm:

>>>UR.default_system = "Nmm"
>>>print("Nmm: " + str(q.to_base_units()))
Nmm: 1000.0 kilogram / millimeter / second ** 2

However, I would like to be able to represent them as:

SI: 1000000.0 pascal
mks: 1000000.0 pascal
Nmm: 1.0 megapascal

Do you know how can I achieve it?

Using pint: 0.22 on PYTHON: 3.9.18

0

There are 0 best solutions below