astropy/astropy — pull request #572 by astrofrog (2012-12-18 15:27:12+00:00)
Title: Alternative astropy.constants API

This implements a simple API for astropy.constants that doesn't separate the SI and cgs constants explicitly. Instead, EM constants have different versions indicated by suffices (``e_si``, ``e_esu``, ``e_gaussian``) and these cannot be converted to ``cgs`` or ``SI`` via the attribute notation:

```
In [1]: from astropy.constants import G

In [2]: from astropy import units as u

In [3]: F = G * 3. * u.M_sun * 2. * u.kg / (3 * u.au) ** 2

In [4]: print F
4.44922666667e-11 m3 solMass / (AU2 s2)

In [5]: print F.to(u.N)
0.00395448857203 N

In [6]: from astropy.constants import e_gauss

In [7]: F = e_gauss**2 / (3. * u.cm)**2

In [8]: print F
2.56341928041e-20 Fr2 / (cm2)

In [9]: print F.to(u.N)
2.56341928041e-25 N

In [10]: e_gauss.cgs
ERROR: TypeError: Cannot convert EM constants to cgs because there are different systems for E.M constants within the c.g.s system (ESU, Gaussian, etc.). Instead, directly use the constant with the appropriate suffix (e.g. e_esu, e_gaussian, etc.). [astropy.constants.constant]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Volumes/Raptor/ in ()
----> 1 e_gauss.cgs

/Volumes/Raptor/Library/Python/2.7/lib/python/site-packages/astropy/constants/constant.pyc in cgs(self)
56 @property
57 def cgs(self):
---> 58 raise TypeError("Cannot convert EM constants to cgs because there "
59 "are different systems for E.M constants within the "
60 "c.g.s system (ESU, Gaussian, etc.). Instead, "

TypeError: Cannot convert EM constants to cgs because there are different systems for E.M constants within the c.g.s system (ESU, Gaussian, etc.). Instead, directly use the constant with the appropriate suffix (e.g. e_esu, e_gaussian, etc.).

In [11]: e_gauss.si
ERROR: TypeError: Cannot convert EM constants to S.I. Instead, directly use the constant with the ``_si`` suffix (e.g. e_si). [astropy.constants.constant]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Volumes/Raptor/ in ()
----> 1 e_gauss.si

/Volumes/Raptor/Library/Python/2.7/lib/python/site-packages/astropy/constants/constant.pyc in si(self)
64 @property
65 def si(self):
---> 66 raise TypeError("Cannot convert EM constants to S.I. Instead, "
67 "directly use the constant with the ``_si`` "
68 "suffix (e.g. e_si).")

TypeError: Cannot convert EM constants to S.I. Instead, directly use the constant with the ``_si`` suffix (e.g. e_si).

In [12]: G.si
Out[12]:

In [13]: G.cgs
Out[13]:
```