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

Skip the navigation links
Last modified: 18 June 2009

How do Sherpa 'load' commands handle ASCII files?


As of the CIAO 4.1.2 release, the 'load' functions used with ASCII files (load_ascii, load_data, load_table) have been updated to accept DM ASCII syntax and therefore recognize the column definitions in file headers.

Example syntax:

#S-Lang
sherpa> load_data("simptab.dat");
#Python
sherpa> load_data("simptab.dat")      
WARNING: Only found 1 column in simptab.dat, trying again with
Data Model syntax : simptab.dat[opt colnames=none]
Read simptab.dat successfully

In this case there were two columns in the file, though the header indicated only one. Sherpa tried again, appending "[opt colnames=none]" to the file name; both columns were found, and the data set was loaded successfully.

By default, if there is a header (i.e., the first N lines are comments, indicated by a '#' character), the last line of the header is assumed to be a list of columns, and only the first two columns are loaded into Sherpa to define x- and y-data arrays. However, if an ASCII file predates Sherpa's use of the ASCII kernel, and there are no column names contained in the last line of the header, then Sherpa will try to load the first two words in the line as columns. If only one word is contained in the last line, then by default only one column will be loaded.

If, for example, there are four columns in the ASCII file, but the last line of the header is:

# A B

then only the first two columns are read in; the first is named "A", and the second is named "B".

If the ASCII file format predates the use of the ASCII kernel, and the last line of the header does not indicate column names but is simply a comment with a single word,

# A

then by default only one column is loaded to Sherpa. As Sherpa expects there to be at least two columns in this situation, an error is returned.

Sherpa tries to catch when only one column has been loaded, and to try again to open all columns. If enough columns are found on this try, Sherpa loads them; if the file has only one column, an error is returned.

If there really is only one column:

#S-Lang
sherpa> load_data("onetab.dat");
#Python
sherpa> load_data("onetab.dat")      
WARNING: Only found 1 column in onetab.dat, trying again with
Data Model syntax : onetab.dat[opt colnames=none]
WARNING: Only found 1 column in onetab.dat, trying again with
Data Model syntax : onetab.dat[opt colnames=none]
IOError: Only found 1 column in onetab.dat, need at least 2

(The two warnings occur because first, load_table() (S-Lang or Python help) is tried, which with CRATES (S-Lang or Python help) can accommodate either FITS or ASCII tables; then load_ascii() (S-Lang or Python help) is tried; both attempts fail because there really is only one column; finally the exception is raised.)



Last modified: 18 June 2009


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.