Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only keep Header values from the Primary that are not present in extension. #6489

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,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