| AHELP for CIAO 4.5 | set_key |
Context: crates |
Synopsis
Add a keyword to a crate given a name and a value.
Syntax
set_key(crate, keyname, keyval, unit=None, desc=None)
Description
- crate - input crate
- keyname - key name (case insensitive)
- keyval - the value of the keyword
- unit - the units of the keyword (optional).
- desc - the description of the keyword (optional).
Create, or replace, a keyword in the header of the crate. If the unit argument is not None then it is a string listing the units of the key. If desc is not None then it is used as the description of the key. If the keyword already exists, then set unit="" and desc="" to clear out the previous settings, otherwise they will be retained.
The add_key routine can be used to create a keyword from a CrateKey object.
The write_file command can be used to save the modified crate to a file.
Example 1
>>> cr = read_file("evt2.fits")
>>> set_key(cr, 'TIMEDEL', 0.00285, unit='s')Create a new key named "TIMEDEL" with a value of 0.00285 and units of seconds, then add it to the crate.
Example 2
from pycrates import *
cr = read_file('in.fits')
x = copy_colvals(cr, 'x')
z = copy_colvals(cr, 'z')
add_key(cr, 'XMEAN', x.mean())
add_key(cr, 'ZMAX', z.max(), unit='cm**2', desc='Max of Z')
cr.write('out.fits')Here we add the XMEAN and ZMAX keywords to a crate, the first with the mean of the x array and the second with the maximumn value of the z column. The ZMAX keyword has its units and description set as well.
Changes in CIAO 4.5
This function is new in CIAO 4.5.
Bugs
See the bug pages on the CIAO website for an up-to-date listing of known bugs.
Refer to the CIAO bug pages for an up-to-date listing of known issues.
See Also
- contrib
- add_keyval, set_key
- crates
- add_key, cratekey, delete_key, get_key, get_key_names, get_keyval, key_exists, set_colvals, set_keyval, set_piximgvals

![[CIAO Logo]](../imgs/ciao_logo_navbar.gif)