astropy/astropy — pull request #370 by mdboom (2012-08-30 20:20:10+00:00)
Title: Units

Perry asked me to work on "astropy-ifying" his units code. This addresses many of the questions posted in the "proposed user interface for physical units" thread on the mailing list.

The most important change is to how equivalences are handled. They are no longer special unit classes in the unit tree (with all kinds of restrictions on how they must be combined), but instead are handled at conversion time given a set of equivalency pairs that describe how to hop the unit concept boundaries. The restriction that remains is that equivalencies (like other unit conversions) must be handled in their entirety. There is no "factoring" that goes on to apply an equivalency to just a part of a unit. I'd most appreciate feedback about how this works -- I think it's a lot easier to follow than what was there before, but that could be subjective.

This also introduces the concept of different formatter backends to handle the different string-based unit formats that are floating around. FITS, VOUnit and IAU style guide formats are already implemented. "Standards for astronomical units" (used by the current generation of VOTable) and OGIP will be followed on later.

Other features left to implement (but not precluded by the design) are

- handling the "function" operations in the FITS standard (log, ln, exp)

- unit factoring (partial pattern matching of units to simplify the expression)

There is remaining integration work to do, but I will save that for another PR. This includes:

- integrating the unit support of wcs and io.vo
- updating the constants module to declare units in a standard format
- updating the Table class to use this

and probably a bunch of other things, but I think there's enough here to comment on for now.