{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n=====================================================================\nAccessing data stored as a table in a multi-extension FITS (MEF) file\n=====================================================================\n\nFITS files can often contain large amount of multi-dimensional data and\ntables. This example opens a FITS file with information\nfrom Chandra's HETG-S instrument.\n\nThe example uses `astropy.utils.data` to download multi-extension FITS (MEF)\nfile, `astropy.io.fits` to investigate the header, and\n`astropy.table.Table` to explore the data.\n\n-------------------\n\n*By: Lia Corrales, Adrian Price-Whelan, and Kelle Cruz*\n\n*License: BSD*\n\n-------------------\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "source": [
        "Use `astropy.utils.data` subpackage to download the FITS file used in this\nexample. Also import `~astropy.table.Table` from the `astropy.table` subpackage\nand `astropy.io.fits`\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "from astropy.utils.data import download_file\nfrom astropy.table import Table\nfrom astropy.io import fits"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "Download a FITS file\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "event_filename = download_file('http://data.astropy.org/tutorials/FITS-tables/chandra_events.fits',\n                               cache=True)"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "Display information about the contents of the FITS file.\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "fits.info(event_filename)"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "Extension 1, EVENTS, is a Table that contains information about each X-ray\nphoton that hit Chandra's HETG-S detector.\n\nUse `~astropy.table.Table` to read the table\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "events = Table.read(event_filename, hdu=1)"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "Print the column names of the Events Table.\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "print(events.columns)"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "If a column contains unit information, it will have an associated\n`astropy.units` object.\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "print(events['energy'].unit)"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "Print the data stored in the Energy column.\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "print(events['energy'])"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }
  ], 
  "metadata": {
    "kernelspec": {
      "display_name": "Python 2", 
      "name": "python2", 
      "language": "python"
    }, 
    "language_info": {
      "mimetype": "text/x-python", 
      "nbconvert_exporter": "python", 
      "name": "python", 
      "file_extension": ".py", 
      "version": "2.7.11", 
      "pygments_lexer": "ipython2", 
      "codemirror_mode": {
        "version": 2, 
        "name": "ipython"
      }
    }
  }
}