Chandra X-Ray Observatory (CXC)
Skip to the navigation links
Last modified: December 2012

URL: http://cxc.harvard.edu/ciao/set_colvals.html
Jump to: Description · Examples · Bugs · See Also


AHELP for CIAO 4.5

set_colvals

Context: crates

Synopsis

Set the values of a column in a crate.

Syntax

set_colvals(crate, colname, values)
set_colvals(crate, colnum, values)

Description

  • crate - input table crate
  • colname - column name (case insensitive)
  • colnum - column number, where the first column is numbered 0
  • values - array of values (a Python list or Numpy array).

The set_colvals command sets the values of the specified column within the crate. To create an entirely new column, use the add_col command.

The value is only changed in the crate; the input file is unaffected. The write_file command ("ahelp write_file") can be used to save the modified crate to a file.

Example 1

chips> cr = read_file("evt2.fits")
chips> energy = copy_colvals(cr, "energy")
chips> nenergy = energy + 2.3 * np.random.random_sample(energy.shape)
chips> set_colvals(cr, "energy", nenergy)
chips> write_file(cr, "energy_evt2.fits")

Here we add on a random number between 0 and 2.3 (uniformly distributed) to each energy value. The new values are written out in the file energy_evt.fits.

More information on random-number support in NumPy can be found at http://docs.scipy.org/doc/numpy/reference/routines.random.html.

Example 2

chips> cr = read_file("table.fits")
chips> nrows = get_number_rows(cr)
chips> set_colvals(cr, 1, np.arange(nrows)+1)
chips> write_file(cr, "rowct.fits")

The second column in the crate (counting from 0) is edited to contain the row number value (starting count at 1). The edited crate is written out to the file rowct.fits.

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

contrib
add_colvals, set_key
crates
add_col, col_exists, copy_colvals, delete_col, get_col, get_col_names, get_colvals, get_number_cols, is_virtual, set_keyval, set_piximgvals

Last modified: December 2012
CXC logo

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