hdinsert

sofia_redux.toolkit.utilities.fits.hdinsert(header, key, value, comment=None, refkey='HISTORY', after=False)[source]

Insert or replace a keyword and value in the header

Note that the insert method of astropy.io.fits.header.Header appears to be broken in cases where a value is to be inserted after a certain keyword and before HISTORY. In these cases header.insert() inserts the new keyword after the first history card… which is bad. Therefore, we do the insertion using a more manual indexing.

In cases where both refkey and after are supplied, the after parameter will be evaluated first.

Parameters:
headerastropy.io.fits.header.Header
keystr

keyword name to insert or replace

value

The value for the keyword

commentstr, optional

If provided a new comment will be used. Otherwise, the previous comment will be used when a keyword value is being replaced.

refkeystr or int or None or 2-tuple, optional

The keyword before which the keyword should be inserted in cases where the new keyword does not yet exist in the header. By default new keywords will be placed before the first HISTORY card. If None, use the end of the header.

afterbool

If True, insert after refkey rather than before.

Returns:
None

The header will be modified in place