aboutsummaryrefslogtreecommitdiffstats
path: root/acispy
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-02-26 12:52:19 +0800
committerAaron LI <aaronly.me@outlook.com>2017-02-26 12:52:19 +0800
commitbf57afb121e682a60190486a5622135604c8c3a0 (patch)
treee69fa5e40ae5d9ef24b04c0420e952345ac5c105 /acispy
parent667af94b53e94f80bfc7abf57edfdd5be254c7a6 (diff)
downloadchandra-acis-analysis-bf57afb121e682a60190486a5622135604c8c3a0.tar.bz2
acispy/header.py: Add 'read_keyword2()'
The 'read_keyword2()' uses 'astropy.io.fits' to manipulate the FITS header, and can access the raw/reserved FITS keywords that 'dmkeypar' cannot read.
Diffstat (limited to 'acispy')
-rw-r--r--acispy/header.py34
1 files changed, 31 insertions, 3 deletions
diff --git a/acispy/header.py b/acispy/header.py
index 0614cd6..6aa0ead 100644
--- a/acispy/header.py
+++ b/acispy/header.py
@@ -3,16 +3,25 @@
"""
Manipulate the FITS header keywords using CIAO tools
-``dmkeypar`` and ``dmhedit``.
+``dmkeypar`` and ``dmhedit``, as well as ``astropy.io.fits``.
"""
import subprocess
+from astropy.io import fits
+
def read_keyword(infile, keyword):
"""
- Read the specified header keyword, and return a dictionary
- with its value, unit, data type, and comment.
+ Read the specified header keyword using CIAO tool ``dmkeypar``,
+ and return a dictionary with its value, unit, data type, and comment.
+
+ NOTE
+ ----
+ The ``dmkeypar`` tool cannot read some raw/reserved keywords in FITS
+ header, e.g., ``BUNIT``. These raw header keywords can be obtained
+ using ``dmlist <infile> opt=header,raw``, or using the following
+ ``read_keyword2()``.
"""
DATATYPES = {
"real": float,
@@ -41,6 +50,25 @@ def read_keyword(infile, keyword):
"unit": unit, "comment": comment}
+def read_keyword2(infile, keyword):
+ """
+ Read the specified header keyword using ``astropy.io.fits``
+ and return a tuple of ``(value, comment)``.
+
+ NOTE
+ ----
+ Header of all extensions (a.k.a. blocks) are combined to locate
+ the keyword.
+ """
+ with fits.open(infile) as f:
+ h = fits.header.Header()
+ for hdu in f:
+ h.extend(hdu.header)
+ value = h[keyword]
+ comment = h.comments[keyword]
+ return (value, comment)
+
+
def write_keyword(infile, keyword, value, datatype=None,
unit=None, comment=None):
"""