astropy/astropy — pull request #1911 by mdboom (2013-12-19 14:49:51+00:00)
Title: units: units in fits file does not parse

I'm am trying to read a fits file from HST/COS, downloaded from MAST today.
All the flux units in the fits file fail to parse.
```
WARNING: UnitsWarning: 'erg /s /cm**2 /angstrom' did not parse as unit format 'fits': Syntax error parsing unit string 'erg /s /cm**2 /angstrom' [astropy.units.core]
```
One problem seems to be that no unit with more than one '/' is accepted, although the fits standard allows for this (even if it is discouraged).
From http://www.aanda.org/articles/aa/full_html/2010/16/aa15362-10/aa15362-10.html :

The IAU style manual forbids the use of more than one slash (“/”) character in a units string. However, since normal mathematical precedence rules apply in this context, more than one slash may be used but is discouraged.

Here is the error:

```
In [59]: u.Unit('erg/cm**2/s', format='fits')
ERROR: ValueError: 'erg/cm**2/s' did not parse as unit format 'fits': Syntax error parsing unit string 'erg/cm**2/s' [astropy.units.core]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 u.Unit('erg/cm**2/s', format='fits')

/data/guenther/anaconda/lib/python2.7/site-packages/astropy-0.4.dev6828-py2.7-linux-x86_64.egg/astropy/units/core.pyc in __call__(self, s, represents, format, namespace, doc, parse_strict)
1731 .format(s, format, str(e)))
1732 if parse_strict == 'raise':
-> 1733 raise ValueError(msg)
1734 elif parse_strict == 'warn':
1735 warnings.warn(msg, UnitsWarning)

ValueError: 'erg/cm**2/s' did not parse as unit format 'fits': Syntax error parsing unit string 'erg/cm**2/s'
```

The second problem is that `'angstrom'` is not recognized in the `fits` format, because it should be spelled `'Angstrom'`. While I recognize that it's technically correct to refuse parsing the unit in lower case for fits, there are plenty of HST files out there that use `'angstrom'` and there is no potential for confusion, so I suggest to accept this, even if not allowed by the definition of the standard.

```
In [62]: u.Unit('angstrom', format='fits')
ERROR: ValueError: 'angstrom' did not parse as unit format 'fits': At col 0, 'angstrom' is not a valid unit in string 'angstrom' [astropy.units.core]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 u.Unit('angstrom', format='fits')

/data/guenther/anaconda/lib/python2.7/site-packages/astropy-0.4.dev6828-py2.7-linux-x86_64.egg/astropy/units/core.pyc in __call__(self, s, represents, format, namespace, doc, parse_strict)
1731 .format(s, format, str(e)))
1732 if parse_strict == 'raise':
-> 1733 raise ValueError(msg)
1734 elif parse_strict == 'warn':
1735 warnings.warn(msg, UnitsWarning)

ValueError: 'angstrom' did not parse as unit format 'fits': At col 0, 'angstrom' is not a valid unit in string 'angstrom'

In [63]: u.Unit('angstrom')
Out[63]: Unit("Angstrom")
```

Note that I'll file this as a bug report with STScI well, but for the foreseeable future users will have to live with HST data files that do not conform to the standard, so we should support them.