Skip to the navigation links
Last modified: December 2009

AHELP for CIAO 4.2


Context: py.crates


Read FITS or ASCII data into a crate.




  • filename - name of the input file; FITS or ASCII format

The read_file command loads the specified file into the appropriate crate, either a TABLECrate or an IMAGECrate. The input file may be in FITS or ASCII format.

The read_pha, read_arf, and read_rmf routines can be used when the type of the dataset is known.

Users familiar with the CIAO Data Model should note that:

  • Crates reads one extension of the input file, not the whole dataset. The file that is written out will only contain the block which was read.
  • Crates does not retain the data subspace of the file.
  • Crates does not retain HISTORY or COMMENT blocks from the input file.

Example 1

>>> cr = read_file("image.fits")
>>> print get_crate_type(cr)

A file is read into the crate "cr", then the get_crate_type command is used to confirm it is an IMAGECrate.

Example 2

>>> cr = read_file("table.fits")
>>> print get_crate_type(cr)

Read a file and create a TABLECrate.

Example 3

>>> phacr = read_file("src.pi")
>>> print(get_crate_type(phacr))
>>> resp = read_file("src.arf")
>>> print(get_crate_type(resp))
>>> resp2 = read_file("src.rmf")
>>> print(get_crate_type(resp2))

Using the read_file command to read a PHA, ARF, or RMF file reads it in as a TABLECrate. The read_pha, read_arf, and read_rmf routines should be used to create a PHACrate, ARFCrate, or RMFCrate.

Example 4

>>> f = "evt2.fits[energy=500:7000,sky=region(src.reg)][bin sky=::1]"
>>> cr = read_file(f)
>>> s = get_piximgvals(cr).sum()
>>> print "Pixel sum=%d" % s
Pixel sum=2361

File names can include CIAO Data Model filtering and binning commands (e.g. see "ahelp dm"). In this case an energy and spatial filter are applied to an event file before being binned into an image. The pixel values are read in and then summed up.

Example 5

>>> a=read_file("myfile.dat")
>>> print get_col_names(a)
>>> s=get_colvals(a,"col1")

The read_file command is used to read the contents of the ASCII file myfile.dat into the TABLEcrate "a", which is then input to the get_col_names command to print the column names read from the file. The get_colvals command is used to store the "col1" data array to the variable "s".

Example 6

>>> a = read_file("myfile.dat[opt colnames=none]")

In this case, the ASCII kernel option 'opt colnames=none' tells the read_file command to skip the header information when reading the contents of the ASCII file myfile.dat into the TABLEcrate "a" (see "ahelp dmascii" for more information).


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

See Also

add_col, add_key, add_piximg, delete_col, delete_key, delete_piximg, read_arf, read_pha, read_rmf, write_arf, write_file, write_pha, write_rmf
make_table_crate, scale_image_crate, write_columns

Last modified: December 2009