Astropy: Tables
Documentation
For more information about the features presented below, you can read the astropy.table docs.
Creating tables
Iterating over tables
It is possible to iterate over rows or over columns. To iterate over rows, simply iterate over the table itself:
Rows can act like dictionaries, so you can access specific columns from a row:
You can also access rows by accessing a numerical item in the table:
Iterating over columns is also easy:
Accessing specific rows from a column object can also be done with the item notation:
Joining tables
Grouping and Aggregation
Masked tables
Writing data
Reading data
You can download the data used below here.
Practical Exercises
These exercises use the all-sky ROSAT catalog which you can download from here.
Level 1
Try and find a way to make a table of the ROSAT point source catalog that contains only the RA, Dec, and count rate. Hint: you can see what methods are available on an object by typing e.g. t.
and then pressing <TAB>
. You can also find help on a method by typing e.g. t.remove_column?
.
Level 2
Make an all-sky equatorial plot of the ROSAT sources, with all sources shown in black, and only the sources with a count rate larger than 2. shown in red (bonus points if you use an Aitoff projection!)
Level 3
Try and write out the ROSAT catalog into a format that you can read into another software package. For example, try and write out the catalog into CSV format, then read it into a spreadsheet software package (e.g. Excel, Google Docs, Numbers, OpenOffice).