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 thenames=
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
anda_nerr
for the positive and negative error of columna
,b_err
the symmetric error of columnb
.)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 theREAD SERR
andREAD 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 thecomments
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 fileexample.qdp
containing the table above. There are four column names but seven data columns, why? Because theREAD SERR
andREAD TERR
commands say that there are three error columns.t.meta['initial_comments']
will contain the initial two comment lines in the file, whilet.meta['comments']
will containTable 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
andserr
commands are passed to the writer.Methods Summary
read
(table)Read the
table
and return the results in a format determined by theoutputter
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 theoutputter
attribute.The
table
parameter is any string or object that can be processed by the instanceinputter
. For the base Inputter classtable
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:
- table
python:str
, python:file-like object,python:list
Input table.
- table
- Returns:
- table
Table
Output table
- table