Note
Go to the end to download the full example code
Accessing data stored as a table in a multi-extension FITS (MEF) file#
FITS files can often contain large amount of multi-dimensional data and tables. This example opens a FITS file with information from Chandra’s HETG-S instrument.
The example uses astropy.utils.data
to download multi-extension FITS (MEF)
file, astropy.io.fits
to investigate the header, and
astropy.table.Table
to explore the data.
By: Lia Corrales, Adrian Price-Whelan, and Kelle Cruz
License: BSD
Use astropy.utils.data
subpackage to download the FITS file used in this
example. Also import Table
from the astropy.table
subpackage
and astropy.io.fits
from astropy.io import fits
from astropy.table import Table
from astropy.utils.data import get_pkg_data_filename
Download a FITS file
event_filename = get_pkg_data_filename('tutorials/FITS-tables/chandra_events.fits')
Display information about the contents of the FITS file.
fits.info(event_filename)
Filename: /home/user/.astropy/cache/download/url/333246bccb141ea3b4e86c49e45bf8d6/contents
No. Name Ver Type Cards Dimensions Format
0 PRIMARY 1 PrimaryHDU 30 ()
1 EVENTS 1 BinTableHDU 890 483964R x 19C [1D, 1I, 1I, 1J, 1I, 1I, 1I, 1I, 1E, 1E, 1E, 1E, 1J, 1J, 1E, 1J, 1I, 1I, 32X]
2 GTI 3 BinTableHDU 28 1R x 2C [1D, 1D]
3 GTI 2 BinTableHDU 28 1R x 2C [1D, 1D]
4 GTI 1 BinTableHDU 28 1R x 2C [1D, 1D]
5 GTI 0 BinTableHDU 28 1R x 2C [1D, 1D]
6 GTI 6 BinTableHDU 28 1R x 2C [1D, 1D]
Extension 1, EVENTS, is a Table that contains information about each X-ray photon that hit Chandra’s HETG-S detector.
Use Table
to read the table
events = Table.read(event_filename, hdu=1)
Print the column names of the Events Table.
print(events.columns)
<TableColumns names=('time','ccd_id','node_id','expno','chipx','chipy','tdetx','tdety','detx','dety','x','y','pha','pha_ro','energy','pi','fltgrade','grade','status')>
If a column contains unit information, it will have an associated
astropy.units
object.
print(events['energy'].unit)
eV
Print the data stored in the Energy column.
print(events['energy'])
energy
eV
---------
13874.715
2621.1938
12119.018
3253.0364
14214.382
1952.7239
3267.5334
3817.0366
2252.7295
6154.1094
...
4819.8286
12536.866
2599.5652
15535.768
6653.0815
14362.482
14653.954
6652.827
9672.882
1875.9359
Length = 483964 rows
Total running time of the script: (0 minutes 6.811 seconds)