          Set the values of a column in a crate.

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

Argument
Description
crate
The table crate.
colname
The column name (case insensitive).
colnum
The column number, where the first column is numbered 0.
values
An array of values; both Python lists or NumPy arrays can be used.

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.

Only the crate is changed; the input file is unaffected. The write_file command can be used to save the modified crate to a file.

>>> cr = read_file("evt2.fits")
>>> energy = copy_colvals(cr, "energy")
>>> rng = np.random.default_rng()
>>> nenergy = energy + 2.3 * rng.random(energy.shape)
>>> set_colvals(cr, "energy", nenergy)
>>> 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 https://numpy.org/doc/stable/reference/random/index.html.

>>> cr = read_file("table.fits")
>>> nrows = get_number_rows(cr)
>>> set_colvals(cr, 1, np.arange(nrows)+1)
>>> 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.

Changes in CIAO 4.13

A NumPy array can now be used to set the array values. Prior to CIAO 4.13 if a NumPy array had been used, rather than a Python list, the call would appear to have worked but not changed anything.

Components of a vector column - for example 'X' of 'SKY(X, y)' - can now be changed with set_colvals, where in earlier versions the call would appear to have worked but the data would not have been changed.

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

December 2023