Spectra in (optical) Astronomy

Here we introduce a simple spectrum, the example taken from the optical, where it all started.

To quote Roger Wesson, the author of this particular spectrum:

The sample spectrum was extracted from a FORS2 observation of a planetary nebula with strong recombination lines. The extract covered Hβ, some collisionally excited lines of [Ar IV], and a number of recombination lines of O II, N II, N III and He II. I chose the spectrum so that it would contain some strong isolated lines and some weak blended lines, such that codes could be compared on the strong lines where user input should make minimal difference, and on the weak lines where subjective considerations come into play.

This particular spectrum was used in a comparison of codes that identify spectral lines


In [1]:
%matplotlib inline

In [2]:
# python 2-3 compatibility
from __future__ import print_function

Reading the data

The astropy package has an I/O package to simplify reading and writing a number of popular formats common in astronomy.


In [3]:
from astropy.io import ascii

We obtained a very simple ascii table with two columns, wavelength and intensity, of a spectrum at a particular point in the sky. The astropy module has some classes to deal with such ascii tables. Although this is not a very reliable way to store data, it is very simple and portable. Almost any software will be able to deal with such ascii files. Your favorite spreadsheet program probably prefers "csv" (comma-separated-values), where the space is replaced by a comma.


In [4]:
data = ascii.read('../data/extract.dat')
print(data)


 col1     col2   
------ ----------
4550.1  0.3311199
4550.8  0.4177661
4551.5  0.7227838
4552.2   1.203263
4552.9  0.9938312
4553.6  0.5458607
4554.3  0.3144122
4555.0  0.3755327
4555.7  0.5148661
4556.4  0.5114279
   ...        ...
4892.4  0.1860969
4893.1  0.1280223
4893.8 0.07695893
4894.5  0.1911669
4895.2  0.1888568
4895.9  0.1488285
4896.6 0.04962431
4897.3  0.1123619
4898.0  0.2072301
4898.7  0.1787372
4899.4  0.1468009
Length = 500 rows

In [5]:
x = data['col1']
y = data['col2']

Plotting the basics


In [6]:
import matplotlib.pyplot as plt

In [7]:
plt.plot(x,y)


Out[7]:
[<matplotlib.lines.Line2D at 0x7f57977117d0>]

There is a very strong line around 4865 Angstrom dominating this plot, and many weaker lines. If we rescale this plot and look what is near the baseline, we get to see these weaker lines much better:


In [8]:
plt.plot(x,y)
z = y*0.0
plt.plot(x,z)
plt.ylim(-0.5,2.0)


Out[8]:
(-0.5, 2.0)

Exercise : in the notebook you should see a little icon in the lower right of this plot that you can drag out and make the plot bigger, but notice it is simply enlarging some plot. There are no more details.

There is a fair amount of noise in this data, and you can also see the baseline is not 0. This means in this object there was some continuum emission, as astronomers call this. Without understanding more about the instrument, which is not the purpose of this excersize, you cannot say much more about separating the lines from the continuum.


In [ ]: