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

CrateKey()

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

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:

>>> 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:

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

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

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

adds the keyword MODTIME in the file tbl.fits.

They can also be viewed using print:

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

>>> print(key2) Name: NORMFLAG Value: False Unit: Desc:

Loading Crates

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

from pycrates import *

or

import pycrates

See the bug pages on the CIAO website for an up-to-date listing of known bugs.

December 2019