In [1]:
%pylab notebook
import tardis
from tardis.io.config_reader import Configuration
from tardis.simulation import Simulation
config_fname = tardis.__path__[0] + '/../../data/tardis_example/tardis_example_integral.yml'
We run tardis in an interactive shell the usual way. Afterwards, we can call simulation.runner.integrator.calculate_spectrum(frequency)
to create an integrated spectrum for any list of frequencies.
In [2]:
simulation = tardis.run_tardis(config_fname);
For simplicity we use the list of frequencies defined by the configuration. We could use any other list that is a astropy Quantity which can be transformed into a frequency (e.g. a list of wavelengths in angstrom works, too).
The integration returns a TARDISSpectrum
instance holding variables like the luminosity_density in nu and lambda.
In [3]:
wl = simulation.runner.spectrum.frequency
spectrum = simulation.runner.integrator.calculate_spectrum(wl)
Here is a simple plot of the integrated spectrum (blue) in comparison with the virtual spectrum (green).
In [4]:
fig = figure()
ax = plt.gca()
spectrum.plot(ax)
simulation.runner.spectrum_virtual.plot(ax)
fig.show()
When running the command line script, we can control the type of spectrum that is written to txt with the method
option of the spectrum
setting in the YAML. If omitted, the default value is 'virtual', however it can be set to 'real' for the spectrum of the real packets, or to 'integrated' for a spectrum from the formal integral approach.
Here we verify our method for the spectral generation is 'integrated'.
In [5]:
config = Configuration.from_yaml(config_fname)
config['spectrum']
Out[5]:
Afterwards we run the tardis script in the shell and save the spectrum to /tmp/tardis_spec.txt
In [6]:
!tardis $config_fname /tmp/tardis_spec.txt
Finally we plot the result and verify, that this looks indeed how a integrated spectrum should look like (no spread due to noise). As the run was done with only 10 000 packets, one would expect significant visible noise.
In [7]:
wl, lum = np.loadtxt('/tmp/tardis_spec.txt', unpack=True);
figure()
plot(wl, lum);