You may also refer to the following tutorial by AstoPy team http://www.astropy.org/astropy-tutorials/Quantities.html
In [1]:
from astropy import units as u
from astropy import constants as const
In [2]:
const.c
Out[2]:
In [3]:
const.m_e
Out[3]:
In [4]:
const.m_e.cgs
Out[4]:
In [5]:
10*u.g*const.c.cgs**2
Out[5]:
In [6]:
u.erg
Out[6]:
In [7]:
u.erg.decompose()
Out[7]:
In [8]:
from astropy.io import fits
from astropy.utils.data import download_file
In [9]:
image_file = download_file('http://data.astropy.org/tutorials/FITS-images/HorseHead.fits', cache=True)
We can open the fits file by fits.open() and check the info of the fits file by .info()
In [10]:
hdu_list = fits.open(image_file)
hdu_list.info()
We get the data by .data
In [11]:
image_data = hdu_list[0].data
image_data
Out[11]:
We get the header by .header
In [12]:
image_header = hdu_list[0].header
image_header.items
Out[12]:
Image header is similar to a dictionary, we can get individual header items by putting correspoding field:
In [13]:
image_header['CRVAL1'], image_header['CRVAL2']
Out[13]:
In [14]:
import matplotlib.pyplot as plt
%matplotlib inline
In [15]:
plt.imshow(image_data)
Out[15]:
In [16]:
plt.imshow(image_data,cmap='gray')
Out[16]:
In [17]:
plt.imshow(image_data,cmap='gray_r')
Out[17]:
In [18]:
# Noted the image is upside down
import numpy as np
plt.imshow(image_data,origin="lower")
Out[18]:
In [20]:
import aplpy
In [21]:
f = aplpy.FITSFigure(image_file,figsize=(16,9), dpi=100)
f.show_colorscale(cmap='gray')
In [22]:
# vim and vmax set the range of values to be shown
f = aplpy.FITSFigure(image_file,figsize=(16,9), dpi=100)
f.show_colorscale(cmap='jet', vmin=3e3, vmax=3e4)
In [23]:
f = aplpy.FITSFigure(image_file,figsize=(16,9), dpi=100)
# Background image
f.show_colorscale(cmap='gray')
# Contour
f.show_contour(image_file,levels=10,cmap='jet',smooth=3,linewidths=1.0)
# Title and colourbar
f.set_title('Horsehead Nebula')
f.add_colorbar()
In [ ]: