Chandra X-Ray Observatory
Skip to the navigation links
Last modified: December 2013

AHELP for CIAO 4.9


Context: crates


The CrateKey object is used to represent a header item (keyword and value) for a file.




The CrateKey object stores a name, value, and optionally the unit and description string. They are used by Crates to represent header keywords.

Creating a key object

The get_key() and get_keyval() routines can be used to get a keyword from the header. They can also be created using the CrateKey() constructor:

chips> key = CrateKey()

- and then filled in using the following fields:

Field Description
value The value of the keyword (the Python type of the value is used to determine the storage type).
name The name of the keyword.
unit The units of the value, if set.
desc A description of the keyword, if set.

As an example, we create two keywords below, EXPOSURE and NORMFLAG:

chips> key1 = CrateKey()
chips> key2 = CrateKey()
chips> = "EXPOSURE"
chips> key1.value = 12234.86
chips> key1.unit = "s"
chips> key1.desc = "Exposure time"
chips> = "NORMFLAG"
chips> key2.value = False

Changing a keyword in a file

The add_key() routine would be used to add these to a Crate; the set_key() routine allows you to add keywords to a Crate without needing to create a CrateKey object. As an example

chips> import time
chips> cr = read_file('tbl.dat')
chips> set_key(cr, 'MODTIME', time.asctime(), desc='Modified date')
chips> cr.write('tbl.fits')

adds the keyword MODTIME in the file tbl.fits.

Viewing Crate Keys

They can also be viewed using print:

chips> print(key1)
   Name:   EXPOSURE
   Value:  12234.86
   Unit:   s
   Desc:   Exposure time

chips> print(key2)
   Name:   NORMFLAG
   Value:  False

Loading Crates

The Crates module is automatically imported into ChIPS and Sherpa sessions, otherwise use one of the following:

from pycrates import *


import pycrates


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

add_key, delete_key, get_key, get_key_names, get_keyval, key_exists, set_key, set_keyval

Last modified: December 2013
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email: Smithsonian Institution, Copyright © 1998-2017. All rights reserved.