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

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


The Crates module provides data input and output routines for Python. 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.

# 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 = copy_colvals(cr, "time")
x = (t - t[0]) / 1e3
y = copy_colvals(cr,"rate")
dy = copy_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"))

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.



Last modified: 14 December 2016
Smithsonian Institute Smithsonian Institute

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