Astronomy Example 2

Downloading a "FITS" file

For examples, documentation, tutorials, etc, see Astropy at http://www.astropy.org

In [2]:
import numpy as np

import matplotlib as mpl
import matplotlib.pyplot as plt

from PIL import Image
from astropy.io import fits
from astropy.utils.data import get_pkg_data_filename
from astropy.visualization import astropy_mpl_style
In [3]:
# Following is an Ipython magic command that puts figures in the  notebook.
%matplotlib notebook
#%matplotlib

plt.style.use(astropy_mpl_style)
        
# M.L. modifications of matplotlib defaults using syntax of v.2.0 
# More info at http://matplotlib.org/2.0.0/users/deflt_style_changes.html
# 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
In [4]:
 hh_file = get_pkg_data_filename('tutorials/FITS-images/HorseHead.fits')
In [5]:
hdu_list = fits.open(hh_file)
hdu_list.info()
Filename: /home/phys310/.astropy/cache/download/py3/2c9202ae878ecfcb60878ceb63837f5f
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 [6]:
hh_data = hdu_list[0].data

print(type(hh_data))

print(hh_data.shape)
<class 'numpy.ndarray'>
(893, 891)
In [7]:
hdu_list.close()
In [8]:
plt.imshow(hh_data, cmap='gray')
plt.grid(color='w')
plt.colorbar();

Version information

version_information is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python for more information and instructions for package installation.

version_information is installed on the linux network at Bucknell

In [9]:
%load_ext version_information
In [10]:
%version_information numpy, matplotlib, astropy, PIL
Out[10]:
SoftwareVersion
Python3.7.7 64bit [GCC 7.3.0]
IPython7.16.1
OSLinux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core
numpy1.18.5
matplotlib3.3.0
astropy4.0.1.post1
PIL7.2.0
Fri Aug 07 11:14:28 2020 EDT
In [ ]: