Ask Your Question
2

Convert derived SI units to base units

asked 2013-06-20 02:10:16 -0500

stan gravatar image

How can I convert SI units involving temperature (kelvin) to their base units?

Example using units of heat capacity:

# Temperature units multiplied by other units cannot be converted
blah = units.energy.joule/units.temperature.kelvin
blah.convert()

Traceback (click to the left of this block for traceback)

...

ValueError: Cannot convert

I need this output:

units.energy.joule.convert()/units.temperature.kelvin.convert()

kilogram*meter^2/(kelvin*second^2)

There is a discussion of this issue at the link below, but there should be a function to convert to base units in the absence of numerical values. Link: [https://groups.google.com/forum/#!sea...]

Does anyone know how to do this?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2013-06-22 10:00:49 -0500

Eviatar Bach gravatar image

updated 2013-07-02 17:07:43 -0500

This should be a built-in function, indeed. Here's a solution in the meanwhile:

def convert(expr):
     op = expr.operator()
     ops = expr.operands()
     if op:
        if len(ops) == 2:
            return op(*map(convert, ops))
        else:
            return op(convert(ops[0]), reduce(op, map(convert, ops[1:])))
     else:
        return expr.convert() if hasattr(expr, 'convert') else expr

Then:

sage: blah = units.energy.joule/units.temperature.kelvin
sage: convert(blah)
kilogram*meter^2/(kelvin*second^2)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-06-20 02:10:16 -0500

Seen: 423 times

Last updated: Jul 02 '13