Astronomy Example 2

Downloading a "FITS" file

For examples, documentation, tutorials, etc, see Astropy at

In [1]:
import scipy as sp

import matplotlib as mpl       # As of July 2017 Bucknell computers use v. 2.x 
import matplotlib.pyplot as plt

# Following is an Ipython magic command that puts figures in the  notebook.
# For figures in separate windows, comment out following line and uncomment
# the next line
# Must come before defaults are changed.
%matplotlib notebook

# As of Aug. 2017 reverting to 1.x defaults.
# In 2.x text.ustex requires dvipng, texlive-latex-extra, and texlive-fonts-recommended, 
# which don't seem to be universal
# See'classic')
# M.L. modifications of matplotlib defaults using syntax of v.2.0 
# More info at
# Changes can also be put in matplotlibrc file, or effected using mpl.rcParams[]
plt.rc('figure', figsize = (6, 4.5))            # Reduces overall size of figures
plt.rc('axes', labelsize=16, titlesize=14)
plt.rc('figure', autolayout = True)             # Adjusts supblot parameters for new size

from PIL import Image
from import fits
from import download_file
from astropy.visualization import astropy_mpl_style
In [2]:
hh_file = download_file('')
Downloading [Done]
In [3]:
hdu_list =
Filename: /usr/tmp/tmphb1p725z
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU     161   (891, 893)   int16   
  1  er.mask       1 TableHDU        25   1600R x 4C   [F6.2, F6.2, F6.2, F6.2]   

Here's how to access the image data; it's a numpy/scipy array.

In [4]:
hh_data = hdu_list[0].data


<class 'numpy.ndarray'>
(893, 891)
In [5]:
In [6]:
plt.imshow(hh_data, cmap='gray')

Version Information

version_information is from J.R. Johansson (jrjohansson at
See Introduction to scientific computing with Python:
for more information and instructions for package installation.

If version_information has been installed system wide (as it has been on Bucknell linux computers with shared file systems), continue with next cell as written. If not, comment out top line in next cell and uncomment the second line.

In [7]:
%load_ext version_information

Loading extensions from ~/.ipython/extensions is deprecated. We recommend managing extensions like any other Python packages, in site-packages.
In [8]:
%version_information scipy, matplotlib, astropy, pillow
Python3.6.1 64bit [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
OSLinux 3.10.0 327.36.3.el7.x86_64 x86_64 with redhat 7.2 Maipo
Tue Aug 01 14:37:34 2017 EDT
In [ ]: