Python script to read and plot 1d spectra released by "The Keck Sample of Quiescent Galaxies" project.

The spectra are available from the Keck Observatory Archive at

https://koa.ipac.caltech.edu/Datasets/KSQG/

In [1]:
# Do set up
import numpy as np
from astropy.io import fits
from matplotlib import pyplot
import matplotlib.pyplot as plt
from scipy.ndimage import filters
In [2]:
# Open the FITS file
# The files are assumed to be in same directory as the notebook
hdu = fits.open('lris_27877.fits')
In [3]:
# read data and header
data = hdu[1].data
header = hdu[1].header

# Set up variables to plot -- flux, wavelength, and inverse variance (1./sigma^2)
flux = data['flux'][0,:]
wave = data['lambda'][0,:]
ivar = data['ivar'][0,:]
In [4]:
# Plot 1d spectrum

f=plt.figure(figsize=[15,5])
plt.plot(wave,filters.gaussian_filter1d(flux,3))
plt.plot(wave,np.sqrt((1./ivar)))
plt.axis([7100,10200,0,0.4])
plt.xlabel('Wavelength (A)')
plt.ylabel('Flux (arbitrary units)')
plt.show()

# If a divide by zero error occurs, it is caused by rows with ivar = 0.0.