A TableSet instance contains a Python list of individual instances of the Table class. The advantage of using a TableSet instead of building a Python list of Table instances manually is that ATpy allows reading and writing of groups of tables to file formats that support it (e.g. FITS and VO table files or SQL databases).
The easiest way to create a table set object is to call the TableSet class with no arguments:
tset = TableSet()
An instance of the Table class can be added to a set by using the append() method:
where t is an instance of the Table() class.
The read() method can be used to read in multiple tables from a file or database. This method automatically determines the file or database type and reads in the tables. For example, all the tables in a VO table can be read in using:
while all the tables in a FITS file can be read in using:
As for the Table() class, in some cases, read() will fail to determine the input type. In this case, or to override the automatically selected type, the input type can be specified using the type argument:
Any arguments passed to TableSet() when creating a table instance are passed to the read() method. This can be used to create a TableSet() instance and fill it with data in a single line. For example, the following:
tset = TableSet('somedata.xml')
is equivalent to:
tset = TableSet() tset.read('somedata.xml')
Single tables can be accessed through the TableSet.tables python list. For example, the first table in a set can be accessed with:
And all methods associated with single tables are then available. For example, the following shows how to run the describe method of the first table in a set:
As well as having keywords and comments associated with each Table, it is possible to have overall keywords and comments associated with a TableSet. Comments and keywords can be added to a table using the add_comment() and add_keyword() methods:
>>> tset.add_comment("This is a great table set") >>> tset.add_keyword("version", 314)