Skip to content

Commit

Permalink
Merge pull request #6489 from MSeifert04/ccddata_fix_problem_with_hea…
Browse files Browse the repository at this point in the history
…der_combine_reader

Only keep Header values from the Primary that are not present in extension.
  • Loading branch information
crawfordsm authored and bsipocz committed Sep 26, 2017
1 parent a2f7a87 commit 04d2270
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ astropy.nddata

- Suppress errors during WCS creation in CCDData.read(). [#6500]

- Fixed a problem with ``CCDData.read`` when the extension wasn't given and the
primary HDU contained no ``data`` but another HDU did. In that case the header
were not correctly combined. [#6489]

astropy.samp
^^^^^^^^^^^^

Expand Down
6 changes: 5 additions & 1 deletion astropy/nddata/ccddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,11 @@ def fits_ccddata_reader(filename, hdu=0, unit=None, hdu_uncertainty='UNCERT',
for i in range(len(hdus)):
if hdus.fileinfo(i)['datSpan'] > 0:
hdu = i
hdr = hdr + hdus[hdu].header
comb_hdr = hdus[hdu].header.copy()
# Add header values from the primary header that aren't
# present in the extension header.
comb_hdr.extend(hdr, unique=True)
hdr = comb_hdr
log.info("first HDU with data is extension "
"{0}.".format(hdu))
break
Expand Down
7 changes: 4 additions & 3 deletions astropy/nddata/tests/test_ccddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,18 @@ def test_initialize_from_fits_with_ADU_in_header(tmpdir):

def test_initialize_from_fits_with_data_in_different_extension(tmpdir):
fake_img = np.random.random(size=(100, 100))
new_hdul = fits.HDUList()
hdu1 = fits.PrimaryHDU()
hdu2 = fits.ImageHDU(fake_img)
hdus = fits.HDUList([hdu1, hdu2])
filename = tmpdir.join('afile.fits').strpath
hdus.writeto(filename)
ccd = CCDData.read(filename, unit='adu')
with catch_warnings(FITSFixedWarning) as w:
ccd = CCDData.read(filename, unit='adu')
assert len(w) == 0
# ccd should pick up the unit adu from the fits header...did it?
np.testing.assert_array_equal(ccd.data, fake_img)
# check that the header is the combined header
assert hdu1.header + hdu2.header == ccd.header
assert hdu2.header + hdu1.header == ccd.header


def test_initialize_from_fits_with_extension(tmpdir):
Expand Down

0 comments on commit 04d2270

Please sign in to comment.