About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: 20 May 2008
Hardcopy (PDF): A4 | Letter

Can I read in data from a file and then plot it?


The Crates module (S-Lang or Python help) provides data input and output routines for Python and S-Lang. It can be used to read in data from a file which can then be plotted - perhaps after manipulation - using ChIPS. The following code shows how the columns time, rate, and error can be plotted (after converting the time column from seconds to an offset in kiloseconds). In this example the input file is assumed to be a FITS binary table but ASCII tables can also be used.

# Python
#
# The following two lines are not needed when running ChIPS
# but are if the file is to be executed by python
from pycrates import *
from pychips.hlui import *

cr = read_file("lc.fits")
t = get_colvals(cr,"time")
x = (t - t[0]) / 1e3
y = get_colvals(cr,"rate")
dy = get_colvals(cr,"error")

add_curve(x, y, dy, ["line.style","none"])
set_plot_xlabel(r"\Delta T (ks)")
set_plot_ylabel("Rate (count s^{-1})")
set_plot_title(get_keyval(cr, "OBJECT"))
% S-Lang
%
% The following two lines are not needed when running ChIPS
% but are if the file is to be executed by slsh
require ("crates");
require ("chips_hlui");

variable cr, t, x, y, dy;
cr = read_file("lc.fits");
t = get_colvals(cr,"time");
x = (t - t[0]) / 1e3;
y = get_colvals(cr,"rate");
dy = get_colvals(cr,"error");

add_curve(x, y, dy, {"line.style","none"});
set_plot_xlabel("\Delta T (ks)"R);
set_plot_ylabel("Rate (count s^{-1})");
set_plot_title(get_keyval(cr, "OBJECT"));

The get_keyval call is used to extract the value of the OBJECT keyword from the FITS header of lc.fits, which is then used to create the title for the plot.



Hardcopy (PDF): A4 | Letter
Last modified: 20 May 2008


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-2004. All rights reserved.