Get all units of a particular dimensionality with pint
Asked Answered
H

1

6

With pint, how can I filter the units in pint.UnitRegistry by dimensionality? For example, how could I get all units of mass type or of volume type?

Heavensent answered 17/8, 2018 at 2:1 Comment(0)
U
7

I believe you're looking for the get_compatible_units method.

>>> ureg = pint.UnitRegistry()

>>> ureg.get_compatible_units('[mass]')
frozenset({<Unit('electron_mass')>,
           <Unit('atomic_mass_unit')>,
           # .... many more
           <Unit('UK_ton')>,
           <Unit('long_ton')>})
Unalienable answered 17/8, 2018 at 2:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.