python4astronomers

A notebook following the first few steps in the python4astronomers tutorial.

Author: Lehman Garrison (lgarrison@cfa.harvard.edu)

Made for the CfA Jupyter Workshop at Wolbach Library, 12/7/2016

Download and plot the data


In [1]:
from astropy.extern.six.moves.urllib import request
import tarfile
url = 'http://python4astronomers.github.io/_downloads/core_examples.tar'
tarfile.open(fileobj=request.urlopen(url), mode='r|').extractall()

Let's see what files we just extracted:


In [2]:
%ls py4ast/core


3c120_stis.fits.gz  imgview.py

Now prep the notebook for plotting:


In [3]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

Parse the FITS file:


In [4]:
from astropy.io import fits
hdus = fits.open('py4ast/core/3c120_stis.fits.gz')
hdus


Out[4]:
[<astropy.io.fits.hdu.image.PrimaryHDU at 0x7f182d3213d0>,
 <astropy.io.fits.hdu.image.ImageHDU at 0x7f182d266890>,
 <astropy.io.fits.hdu.image.ImageHDU at 0x7f182d275b10>,
 <astropy.io.fits.hdu.image.ImageHDU at 0x7f182d27ed90>]

In [5]:
primary = hdus[0].data  # Primary (NULL) header data unit
img = hdus[1].data      # Intensity data
err = hdus[2].data      # Error per pixel
dq = hdus[3].data       # Data quality per pixel

And finally plot:


In [10]:
%matplotlib inline
plt.imshow(img, origin = 'lower', vmin = -10, vmax = 65)
plt.colorbar()


Out[10]:
<matplotlib.colorbar.Colorbar at 0x7f182654c7d0>

Success! Let's save to disk:


In [7]:
plt.savefig('3c120.png')

Did it work?


In [8]:
%ls


3c120.png  intro.ipynb  py4ast/  python4astronomers_jupyter.ipynb