astropy/astropy — pull request #1715 by mdboom (2013-10-31 21:20:27+00:00)
Title: Low hanging optimizations in units and coordinates

This is a follow on to #1714.

This does some low-hanging optimizations to units and coordinates. I used the `test_fk4_no_e_fk5` test as a benchmark, and got it from 2.44s to 1.62s on my machine.

In `angles.py`, we convert from whatever unit the angle is in to degrees only once in the validation routines. This reveals a shortcoming of `Quantities` in general -- that it's very easy to write code where same conversion is done multiple times. The performance hit is not so much in the actual multiplication of values, but all of the work that must be done to determine *if* the conversion is possible, and what the scaling factor is. In any event, I'm not sure we should necessarily make that change -- it makes things a whole lot less idiomatic -- but it's interesting how important to the overall runtime they end up being.

In `core.py`, the changes primarily have to deal with not error-checking the arguments to the `CompositeUnit` constructor if we've already verified they are good as-is. Also, it avoids creating `CompositeUnit` objects in some more cases.

In `quantity.py`, we were using the full-blown unit string parser to handle the convenience conversion methods, e.g. `angle.degree`. Since a Python attribute can't really contain punctuation etc. anyway, this can all boil down to a dictionary lookup instead.