{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "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\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\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from astropy.utils.data import get_pkg_data_filename\nfrom astropy.table import Table\nfrom astropy.io import fits" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Download a FITS file\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "event_filename = get_pkg_data_filename('tutorials/FITS-tables/chandra_events.fits')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Display information about the contents of the FITS file.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fits.info(event_filename)" ] }, { "cell_type": "markdown", "metadata": {}, "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\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "events = Table.read(event_filename, hdu=1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print the column names of the Events Table.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(events.columns)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If a column contains unit information, it will have an associated\n`astropy.units` object.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(events['energy'].unit)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print the data stored in the Energy column.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(events['energy'])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" } }, "nbformat": 4, "nbformat_minor": 0 }