astropy/astropy — pull request #2092 by barentsen (2014-02-13 20:44:11+00:00)
Title: Add a `fitshead` script to display FITS headers

I propose adding a `fitshead` script to astropy for the purpose of conveniently printing the header(s) of a FITS file to the standard output.

The proposed script is similar to existing tools such as `fitshead.csh` (Starlink) or `gethead` (WCSTools), but those tools are rarely installed on an astronomer's computer by default these days. I believe that the use-case of inspecting the headers of a FITS file is *very* common and warrants a command-line script; allowing it to be used in combination with `grep`, `sed`, etc...

Proposed usage:
```
$ fitshead -h
usage: fitshead [-h] [-e hdu] filename [filename ...]

Print the header(s) of a FITS file. By default, all HDU extensions are shown.

positional arguments:
filename path to one or more FITS files to display

optional arguments:
-h, --help show this help message and exit
-e hdu, --ext hdu specify the hdu extension number
```

Default behaviour:
```
$ fitshead astropy/io/fits/tests/data/table.fits
# HDU 0 in astropy/io/fits/tests/data/table.fits:
SIMPLE = T / conforms to FITS standard
BITPIX = 8 / array data type
NAXIS = 0 / number of array dimensions
EXTEND = T
END

# HDU 1 in astropy/io/fits/tests/data/table.fits:
XTENSION= 'BINTABLE' / binary table extension
BITPIX = 8 / array data type
NAXIS = 2 / number of array dimensions
NAXIS1 = 24 / length of dimension 1
NAXIS2 = 3 / length of dimension 2
PCOUNT = 0 / number of group parameters
GCOUNT = 1 / number of groups
TFIELDS = 2 / number of table fields
TTYPE1 = 'target '
TFORM1 = '20A '
TTYPE2 = 'V_mag '
TFORM2 = 'E '
END
```

Displaying a single extension:
```
$ fitshead -e1 astropy/io/fits/tests/data/table.fits
# HDU 1 in astropy/io/fits/tests/data/table.fits:
XTENSION= 'BINTABLE' / binary table extension
BITPIX = 8 / array data type
NAXIS = 2 / number of array dimensions
NAXIS1 = 24 / length of dimension 1
NAXIS2 = 3 / length of dimension 2
PCOUNT = 0 / number of group parameters
GCOUNT = 1 / number of groups
TFIELDS = 2 / number of table fields
TTYPE1 = 'target '
TFORM1 = '20A '
TTYPE2 = 'V_mag '
TFORM2 = 'E '
END
```

A user-friendly error message is displayed when things go wrong:
```
$fitshead -e 999 astropy/io/fits/tests/data/table.fits
ERROR: Extension #999 is not present in astropy/io/fits/tests/data/table.fits. [astropy.io.fits.scripts.fitshead]
```

If this is deemed to be a worthwhile addition, I imagine having to add some documentation to `astropy/docs/io/fits/usage/scripts.rst`?