QDP#

class astropy.io.ascii.QDP(table_id=None, names=None, err_specs=None, sep=None)[source]#

Bases: Basic

Quick and Dandy Plot table.

Example:

! Initial comment line 1
! Initial comment line 2
READ TERR 1
READ SERR 3
! Table 0 comment
!a a(pos) a(neg) b be c d
53000.5   0.25  -0.5   1  1.5  3.5 2
54000.5   1.25  -1.5   2  2.5  4.5 3
NO NO NO NO NO
! Table 1 comment
!a a(pos) a(neg) b be c d
54000.5   2.25  -2.5   NO  3.5  5.5 5
55000.5   3.25  -3.5   4  4.5  6.5 nan

The input table above contains some initial comments, the error commands, then two tables. This file format can contain multiple tables, separated by a line full of NO``s. Comments are exclamation marks, and missing values are single ``NO entries. The delimiter is usually whitespace, more rarely a comma. The QDP format differentiates between data and error columns. The table above has commands:

READ TERR 1
READ SERR 3

which mean that after data column 1 there will be two error columns containing its positive and engative error bars, then data column 2 without error bars, then column 3, then a column with the symmetric error of column 3, then the remaining data columns.

As explained below, table headers are highly inconsistent. Possible comments containing column names will be ignored and columns will be called col1, col2, etc. unless the user specifies their names with the names= keyword argument, When passing column names, pass only the names of the data columns, not the error columns. Error information will be encoded in the names of the table columns. (e.g. a_perr and a_nerr for the positive and negative error of column a, b_err the symmetric error of column b.)

When writing tables to this format, users can pass an err_specs keyword passing a dictionary {'serr': [3], 'terr': [1, 2]}, meaning that data columns 1 and two will have two additional columns each with their positive and negative errors, and data column 3 will have an additional column with a symmetric error (just like the READ SERR and READ TERR commands above)

Headers are just comments, and tables distributed by various missions can differ greatly in their use of conventions. For example, light curves distributed by the Swift-Gehrels mission have an extra space in one header entry that makes the number of labels inconsistent with the number of cols. For this reason, we ignore the comments that might encode the column names and leave the name specification to the user.

Example:

>               Extra space
>                   |
>                   v
>!     MJD       Err (pos)       Err(neg)        Rate            Error
>53000.123456   2.378e-05     -2.378472e-05     NO             0.212439

These readers and writer classes will strive to understand which of the comments belong to all the tables, and which ones to each single table. General comments will be stored in the initial_comments meta of each table. The comments of each table will be stored in the comments meta.

Example:

t = Table.read(example_qdp, format='ascii.qdp', table_id=1, names=['a', 'b', 'c', 'd'])

reads the second table (table_id=1) in file example.qdp containing the table above. There are four column names but seven data columns, why? Because the READ SERR and READ TERR commands say that there are three error columns. t.meta['initial_comments'] will contain the initial two comment lines in the file, while t.meta['comments'] will contain Table 1 comment

The table can be written to another file, preserving the same information, as:

t.write(test_file, err_specs={'terr': [1], 'serr': [3]})

Note how the terr and serr commands are passed to the writer.

Methods Summary

read(table)

Read the table and return the results in a format determined by the outputter attribute.

write(table)

Write table as list of strings.

Methods Documentation

read(table)[source]#

Read the table and return the results in a format determined by the outputter attribute.

The table parameter is any string or object that can be processed by the instance inputter. For the base Inputter class table can be one of:

  • File name

  • File-like object

  • String (newline separated) with all header and data lines (must have at least 2 lines)

  • List of strings

Parameters:
tablestr, file-like object, list

Input table.

Returns:
tableTable

Output table

write(table)[source]#

Write table as list of strings.

Parameters:
tableTable

Input table data.

Returns:
lineslist

List of strings corresponding to ASCII table