.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/examples/io/fits-tables.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_examples_io_fits-tables.py: ===================================================================== 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* .. GENERATED FROM PYTHON SOURCE LINES 23-26 Use `astropy.utils.data` subpackage to download the FITS file used in this example. Also import `~astropy.table.Table` from the `astropy.table` subpackage and `astropy.io.fits` .. GENERATED FROM PYTHON SOURCE LINES 26-31 .. code-block:: Python from astropy.io import fits from astropy.table import Table from astropy.utils.data import get_pkg_data_filename .. GENERATED FROM PYTHON SOURCE LINES 32-33 Download a FITS file .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python event_filename = get_pkg_data_filename('tutorials/FITS-tables/chandra_events.fits') .. GENERATED FROM PYTHON SOURCE LINES 37-38 Display information about the contents of the FITS file. .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python fits.info(event_filename) .. rst-class:: sphx-glr-script-out .. code-block:: none 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] .. GENERATED FROM PYTHON SOURCE LINES 42-46 Extension 1, EVENTS, is a Table that contains information about each X-ray photon that hit Chandra's HETG-S detector. Use `~astropy.table.Table` to read the table .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: Python events = Table.read(event_filename, hdu=1) .. GENERATED FROM PYTHON SOURCE LINES 50-51 Print the column names of the Events Table. .. GENERATED FROM PYTHON SOURCE LINES 51-54 .. code-block:: Python print(events.columns) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 55-57 If a column contains unit information, it will have an associated `astropy.units` object. .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: Python print(events['energy'].unit) .. rst-class:: sphx-glr-script-out .. code-block:: none eV .. GENERATED FROM PYTHON SOURCE LINES 61-62 Print the data stored in the Energy column. .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: Python print(events['energy']) .. rst-class:: sphx-glr-script-out .. code-block:: none 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 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.306 seconds) .. _sphx_glr_download_generated_examples_io_fits-tables.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fits-tables.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fits-tables.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_