Skip to content

Header assignment to CompImageHDU is not preserved on write #14081

Closed

Description

@eigenbrot

Consider:

>>> from astropy.io import fits
>>> ih = fits.ImageHDU()
>>> ih.header['test'] = 'right'

>>> ch = fits.CompImageHDU()
>>> ch.header['test'] = 'wrong'
>>> ch.header = ih.header  # Assign the CompImageHDU the header from the ImageHDU
>>> ch.header['test']
'right'  # This makes sense and is what I want

>>> ch.writeto('tmp.fits')
>>> chdl = fits.open('tmp.fits')
>>> chdl[1].header['test']
'wrong'  # This doesn't seem right

I'm trying to assign a Header object to the .header attribute of a CompImageHDU. This assignment works while the HDU is in memory, but as soon as it's written to disk it reverts to the old header.

I looked into it a little bit and it looks like maybe CompImageHDU needs a custom setter on its .header attribute?? That's just a guess though.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions