Last modified: December 2019

URL: https://cxc.cfa.harvard.edu/ciao/ahelp/cratekey.html
AHELP for CIAO 4.16

cratekey

Context: crates

Synopsis

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

Syntax

CrateKey()

Description

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:

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

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

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

Viewing Crate Keys

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

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

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