Skip to content

Feedback on the conversion and dimensionality functionality #3

@pelson

Description

@pelson

Following the discussion in SciTools/cf-units#446 (comment), it would be good to get some feedback on how the implementation here for dimensionality and conversion works out for you @ocefpaf.

The README.md has some info, but for your is_convertible and is_dimensionless cases you can use the following:

from pyudunits2 import UnitSystem

ut_system = UnitSystem.from_udunits2_xml()

unit1 = ut_system.unit('km/h')
unit2 = ut_system.unit('meters per second')

assert unit1.is_convertible_to(unit2)
assert not unit1.is_convertible_to(ut_system.unit('m'))

And:

assert ut_system.unit('radians mg/kilogram').is_dimensionless()

There is an example in the README if you want to do actual conversions, rather than just knowing if conversions are possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions