# 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
# Open the FITS file
# The files are assumed to be in same directory as the notebook
hdu = fits.open('lris_27877.fits')
# 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,:]
# 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.