{ } Raw JSON

bundles / astropy latest / astropy / io / fits / convenience / setval

function

astropy.io.fits.convenience:setval

source: /astropy/io/fits/convenience.py :301

Signature

def   setval ( filename keyword * args value = None comment = None before = None after = None savecomment = False ** kwargs )

Summary

Set a keyword's value from a header in a FITS file.

Extended Summary

If the keyword already exists, it's value/comment will be updated. If it does not exist, a new card will be created and it will be placed before or after the specified location. If no before or after is specified, it will be appended at the end.

When updating more than one keyword in a file, this convenience function is a much less efficient approach compared with opening the file for update, modifying the header, and closing the file.

Parameters

filename : path-like or file-like

Name of the FITS file, or file object If opened, mode must be update (rb+). An opened file object or GzipFile object will be closed upon return.

keyword : str

Keyword name

value : str, int, float, optional

Keyword value (default: None, meaning don't modify)

comment : str, optional

Keyword comment, (default: None, meaning don't modify)

before : str, int, optional

Name of the keyword, or index of the card before which the new card will be placed. The argument before takes precedence over after if both are specified (default: None).

after : str, int, optional

Name of the keyword, or index of the card after which the new card will be placed. (default: None).

savecomment : bool, optional

When True, preserve the current comment for an existing keyword. The argument savecomment takes precedence over comment if both specified. If comment is not specified then the current comment will automatically be preserved (default: False).

ext, extname, extver

The rest of the arguments are for HDU specification. See getdata for explanations/examples.

**kwargs

Any additional keyword arguments to be passed to astropy.io.fits.open. Note: This function automatically specifies do_not_scale_image_data = True when opening the file so that values can be retrieved from the unmodified header.

Aliases

  • astropy.io.fits.setval