def open_image(infile):
"""
Open the FITS image and return its header and data, but requiring
the input image has only ONE frequency.
The input FITS image may have following dimensions:
* NAXIS=2: [Y, X]
* NAXIS=3: [FREQ=1, Y, X]
* NAXIS=4: [STOKES, FREQ=1, Y, X]
"""
with fits.open(infile) as f:
header = f[0].header
data = f[0].data
if ((data.ndim == 3 and data.shape[0] != 1) or
(data.ndim == 4 and data.shape[1] != 1)):
# NAXIS=3: [FREQ!=1, Y, X]
# NAXIS=4: [STOKES, FREQ!=1, Y, X]
raise ValueError("input file '{0}' has invalid dimensions: {1}".format(
infile, data.shape))
print("Read in FITS image from: %s" % infile)
return (header, data)
评论列表
文章目录