astropy/astropy — pull request #2798 by mdboom (2014-07-25 19:54:49+00:00)
Title: Originally valid FITS unit cannot be formatted

In FITS, ``count`` is a valid unit. But:

```
In [32]: c = u.Unit('count', format='fits')

In [33]: c.to_string(format='fits')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 c.to_string(format='fits')

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/units/core.pyc in to_string(self, format)
570 """
571 f = unit_format.get_format(format)
--> 572 return f.to_string(self)
573
574 def __format__(self, format_spec):

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/units/format/fits.pyc in to_string(self, unit)
126
127 # Remove units that aren't known to the format
--> 128 unit = utils.decompose_to_known_units(unit, self._get_unit_name)
129
130 if isinstance(unit, core.CompositeUnit):

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/units/format/utils.pyc in decompose_to_known_units(unit, func)
104 elif isinstance(unit, core.NamedUnit):
105 try:
--> 106 func(unit)
107 except ValueError:
108 if isinstance(unit, core.Unit):

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/units/format/fits.pyc in _get_unit_name(self, unit)
112 if name not in self._units:
113 raise ValueError(
--> 114 "Unit {0!r} is not part of the FITS standard".format(name))
115
116 if name in self._deprecated_units:

ValueError: Unit u'ct' is not part of the FITS standard
```

Maybe ``to_string`` should check if any of the aliases would be valid instead? (``count`` is an alias of ``ct``).

cc @mdboom