Plotting a Spectrum

This notebook explains how to read and plot a spectrum for the cv_standard file found in the examples. Before running the python commands, you need to run the model from the command line. I suggest running the following commands, after you have compiled python:

mkdir cv_test
cd cv_test
cp $PYTHON/examples/basic/cv_standard.pf .
py cv_standard </code>

The model will take about 5 minutes to run on a single core. It will not converge snd the spectrum will be a bit noisy, but will give us a model to use as an example.

The simplest way to make a quick look spectrum plot is using the plot_spec.py routine in $PYTHON/py_progs. In this example, I will assume py_progs has been added to $PATH and to $PYTHONPATH. plot_spec.py can be run from the command line using

plot_spec.py [-wmin 850 -wmax 1850 -smooth 21] cv_standard

where the flags control the minimum and maximum wavelengths. Alternatively, it can be run from within python by doing:

[14]:
%matplotlib inline
import plot_spec
wmin, wmax = 850,1800
smooth = 21
plot_spec.do_all_angles(fname, smooth, wmin, wmax)
[14]:
'cv_standard.png'
../_images/output_plot_spectrum_1_1.png

You may, however, wish to get more direct access to the data, which can be done easily by reading in the cv_standard.spec file, for example using astropy. In the next code block, we read in the spectrum file and print out the columns.

[15]:
import matplotlib.pyplot as plt
import astropy.io.ascii as io

fname = "cv_standard"
s = io.read("{}.spec".format(fname))

print (s.colnames)
['Freq.', 'Lambda', 'Created', 'WCreated', 'Emitted', 'CenSrc', 'Disk', 'Wind', 'HitSurf', 'Scattered', 'A10P0.50', 'A28P0.50', 'A45P0.50', 'A62P0.50', 'A80P0.50']

The first two columns are: * Freq.: frequency in Hz * Lambda: wavelength in Angstroms

The next set of columns correspond to: * Created: total spectrum of all of the photons paakets as created, that is before having been translated through the wind * WCreated: spectrum of the photons that are created in the wind before translation * Emitted: is the emergent spectrun after the photons have been translated through the wind * CenSrc: is the emergent spectrum from photons bundles originating on the Star or BL, * Disk: spectrum due to photons starting in the disk * Wind: spectrum due to photons starting in the wind * HitSurf: photons that did not escape the system but ran into a boundary

The remaining columns show the spectrum extracted at various angles, where A45P0.50 denotes an inclination of 45 degrees with respect to the polar axis, and a phase of 0.50 relative to inferior conjunction. Phase only matters if a companion is present.

Units: The units depend on whether flambda or fnu has been requested by the user, but correspond to CGS units either in per Angstrom or per Hz.

We can now plot one of the spectra.

[16]:
angle = 45
field = "A{:.0f}P0.50".format(angle)
plt.plot(s["Lambda"], s[field])
[16]:
[<matplotlib.lines.Line2D at 0x12194cf90>]
../_images/output_plot_spectrum_5_1.png

We can also plot the components contributing to the total escaping spectrum in the requested wavelength range using the plot_tot.py script. Note that this script reads the cv_standard.log_spec_tot file and plots the flobal SED in \(\nu L_\nu\) units as a function of \(\nu\). This file can also be read using astropy but excludes the angle columns.

[20]:
import plot_tot
plot_tot.doit(fname, smooth)
The Created luminosity was  4.4784868888122e+34
The emitted luminosity was  3.8596360000753657e+34
../_images/output_plot_spectrum_7_1.png