Skip to the navigation links
Last modified: December 2009

URL: http://cxc-newtest.cfa.harvard.edu/ciao4.2/make_table_crate.sl.html
AHELP for CIAO 4.2

make_table_crate

Context: sl.crates_contrib

Synopsis

Create a TABLE Crate from a set of arrays (columns).

Syntax

crate = make_table_crate( col1, ..., coln [; colnames=NULL] );

Description

This routine provides a quick means of creating a TABLE Crate from a set of arrays.

Loading the routine

The routine can be loaded into a ChIPS or Sherpa session by saying:

require ("crates_utils");

Column content

The data to add to the Crate is given as the col1 to coln arguments; they should be S-Lang arrays (e.g. [1,2,3]), they can be multi-dimensional (e.g. for vector columns), and can include string vectors. Each column should contain a single datatype, and all will be padded to the length of the longest array. The padding is 0 for numeric columns and "" or "IND" for string arrays.

Column names

If the optional colnames argument is not given then the columns will be named "col1" to "coln", where n is the number of columns. To use your own names, supply an array of strings to the colnames argument. This array must contain at least as many values as there are columns (extra elements are ignored).

Writing the data out to file

The write_file() command can be used to write the data out to file in FITS binary or ASCII formats. If you do not need to add metadata to the crate then the write_columns() routine can also be used.

Example 1

chips> a = [1:5];
chips> b = 2.3 * a^2;
chips> c = ["src a", "src b", "", "multiple sources", "x"];
chips> cr = make_table_crate(a, b, c);
chips> print (get_col_names(cr));
['col1' 'col2' 'col3']
chips> write_file(cr, "src.fits");
chips> write_file(cr, "src.dat[opt kernel=text]");

A table crate is created (cr) that contains the three arrays, stored as columns "col1", "col2", and "col3". The crate is written out to the file "src.fits", which is in binary FITS format, and "src.dat", which is in ASCII format using the TEXT/SIMPLE format (see "ahelp dmascii" for more information). The contents of src.dat are

chips> !cat src.dat
#TEXT/SIMPLE
# col1 col2 col3
1 2.300000000000 "src a"
2 9.200000000000 "src b"
3 20.70000000000 ""
4 36.80000000000 "multiple sources"
5 57.50000000000 x

and the column listing for "src.fits" is:

chips> !dmlist src.fits cols
 
-----------------------------------------------------------
Columns for Table Block TABLE
-----------------------------------------------------------
 
ColNo  Name       Unit        Type             Range
   1   col1                    Int4           -                    
   2   col2                    Real8          -Inf:+Inf            
   3   col3                    String[16]                          

Example 2

chips> cr = make_table_crate(a, b, c; colnames=["x", "y", "comment"]);

This time the column names are set to "x", "y", and "comment".

Example 3

chips> x = [1:4];
chips> y = _reshape([1:10], [5,2]);
chips> cr = make_table_crate(x, y; colnames=["x", "y"]);
chips> key = CrateKey;
chips> key.name = "CREATOR";
chips> add_key(cr, key);
chips> set_keyval(cr, "CREATOR", "Me");
chips> write_file(cr, "example.fits");

Here we highlight

  • handling multi-dimensional arrays (y),
  • dealing with arrays of different length (x has 4 scalars and y has 5 pairs),
  • and adding metadata to the Crate.

The output file looks like:

chips> !dmlist example.fits data,clean
#  x          y[2]
          1                  1 2
          2                  3 4
          3                  5 6
          4                  7 8
          0                 9 10

and the header keyword CREATOR has been set:

chips> !dmkeypar example.fits CREATOR echo+
Me

Bugs

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

See Also

sl.crates
add_col, add_key, add_piximg, delete_col, delete_key, delete_piximg, read_arf, read_file, read_pha, read_rmf, write_arf, write_file, write_pha, write_rmf
sl.crates_contrib
scale_image_crate, write_columns

Last modified: December 2009