environmentalscience / essm

This package contains helpers to deal with physical variables and units.
https://environmentalscience.github.io/essm/
GNU General Public License v2.0
12 stars 5 forks source link

Respect desired unit in variable with expression. #51

Closed schymans closed 6 years ago

schymans commented 6 years ago

If we define a new variable based on other variables, we want to be able to prescribe the desired units rather than taking the base units derived from the embedded expression. Example:

    class local_definition(Variable):
        """Local definition."""
        unit = joule

        class local_variable(Variable):
            """Local variable."""
            unit = kilogram * meter ** 2 / second ** 2
            default = 2

        expr = 1.5 * local_variable

With the current PR, local_definition.definition.unit == joule instead of kilogram * meter ** 2 / second ** 2

schymans commented 6 years ago

I just found a problem with the new derive_unit(). Need to explore a bit more...

schymans commented 6 years ago

OK, solved the problem and added tests.