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.utils.data import download_file
from astropy.table import Table
from astropy.io import fits

Download a FITS file

event_filename = download_file('http://data.astropy.org/tutorials/FITS-tables/chandra_events.fits',
                               cache=True)

Display information about the contents of the FITS file.

fits.info(event_filename)

Out:

Filename: /Users/erik/.astropy/cache/download/py3/26e9900d731d08997d99ada3973f4592
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)

Out:

<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)

Out:

eV

Print the data stored in the Energy column.

print(events['energy'])

Out:

energy
   eV
-------
13874.7
2621.19
12119.0
3253.04
14214.4
1952.72
3267.53
3817.04
2252.73
6154.11
    ...
4819.83
12536.9
2599.57
15535.8
6653.08
14362.5
14654.0
6652.83
9672.88
1875.94
Length = 483964 rows

Total running time of the script: ( 0 minutes 5.453 seconds)

Generated by Sphinx-Gallery