astropy/astropy — pull request #2588 by barentsen (2014-06-01 21:56:27+00:00)
Title: Add option to `fitsheader` to extract a specific keyword

This PR implements the feature requested in #2555. That is, I have added an optional `--key` argument to the `fitsheader` script to allow one ore more specified keyword value(s) to be retrieved from the header of a FITS file.

The proposed behaviour is described below. Please review!

Updated usage info:
```
$ fitsheader -h
usage: fitsheader [-h] [-e HDU] [-k KEYWORD] [-c] filename [filename ...]

Print the header(s) of a FITS file. All HDU extensions are shown by default.
In the case of a compressed image, the decompressed header is shown.

positional arguments:
filename path to one or more FITS files

optional arguments:
-h, --help show this help message and exit
-e HDU, --ext HDU specify the HDU extension by name or number
-k KEYWORD, --keyword KEYWORD
retrieve the value for a specific keyword, or for a
comma-delimited list of keywords
-c, --compressed for compressed image data, show the true header which
describes the compression rather than the data
```

Example 1: extracting the value of the BITPIX keyword in HDU #0:
```
$ fitsheader --ext 0 --keyword BITPIX tests/data/test0.fits
16
```

Example 2: multiple keywords can be requested using a comma-delimited list. Values are printed in the requested order, one value per line:
```
$ fitsheader --ext 0 --keyword BITPIX,DATE-OBS,TIME-OBS tests/data/test0.fits
16
19/05/94
15:41:16
```

Example 3: when no single HDU is specified, the keyword is shown for each HDU. Again, one value per line:
```
$ fitsheader --keyword BITPIX tests/data/test0.fits
16
16
16
16
16
```

Example 4: when a keyword does not exist, a warning message is shown and a blank line is returned to stdout:
```
$ fitsheader --ext 2 --keyword BLABLA tests/data/test0.fits
WARNING: tests/data/test0.fits (HDU 2): Keyword BLABLA not found. [astropy.io.fits.scripts.fitsheader]

```

Is this what you had in mind, @bsipocz?