<jupyter_start><jupyter_text>API example for the formal integralThere are currently two ways to invoke the calculation of the formal integral with tardis. The first is for the use in interactive shells and scripts and the second one for running tardis with the command line script `tardis`.Let's start with some common imports:<jupyter_code>%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'<jupyter_output>/home/stefan/anaconda2/envs/tardis/lib/python2.7/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated since IPython 4.0.You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)<jupyter_text>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.<jupyter_code>simulation = tardis.run_tardis(config_fname);<jupyter_output>[[1mtardis.plasma.standard_plasmas[0m][[1;37mINFO[0m   ]  Reading Atomic Data from /media/data/projects/tardis/tardis-code/tardis/../../data/tardis_example/kurucz_cd23_chianti_H_He.h5 ([1mstandard_plasmas.py[0m:72)
tardis.plasma.standard_plasmas - [1;37mINFO[0m - Reading Atomic Data from /media/data/projects/tardis/tardis-code/tardis/../../data/tardis_example/kurucz_cd23_chianti_H_He.h5
tardis.atomic - INFO - Read Atom Data with UUID=5ca3035ca8b311e3bb684437e69d75d7 and MD5=21095dd25faa1683f4c90c911a00c3f8
[[1mtardis.plasma.base  [0m][[1;34mDEBUG[0m  ]  Updating modules in the following order: ([1mbase.py[0m:195)
tardis.plasma.base - [1;34mDEBUG[0m - Updating modules in the following order:
[[1mtardis.montecarlo.base[0m][[1;34mDEBUG[0m  ]  Electron scattering switched on ([1mbase.py[0m:411)
tardis.montecarlo.base - [1;34mDEBUG[0m - Electron scattering switched on
[[1mtardis.simulation.base[0m][[1;37mINFO[0m   ]  Starting iteration 1/1 ([1mbase.py[0m:194)
t[...]<jupyter_text>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.<jupyter_code>wl = simulation.runner.spectrum.frequency
spectrum = simulation.runner.integrator.calculate_spectrum(wl)<jupyter_output><empty_output><jupyter_text>Here is a simple plot of the integrated spectrum (blue) in comparison with the virtual spectrum (green).<jupyter_code>fig = figure()
ax = plt.gca()
spectrum.plot(ax)
simulation.runner.spectrum_virtual.plot(ax)
fig.show()<jupyter_output><empty_output><jupyter_text>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'.<jupyter_code>config = Configuration.from_yaml(config_fname)
config['spectrum']<jupyter_output><empty_output><jupyter_text>Afterwards we run the tardis script in the shell and save the spectrum to /tmp/tardis_spec.txt<jupyter_code>!tardis $config_fname /tmp/tardis_spec.txt<jupyter_output>[[1mtardis.plasma.standard_plasmas[0m][[1;37mINFO[0m   ]  Reading Atomic Data from /media/data/projects/tardis/tardis-code/tardis/../../data/tardis_example/kurucz_cd23_chianti_H_He.h5 ([1mstandard_plasmas.py[0m:72)
tardis.plasma.standard_plasmas - [1;37mINFO[0m - Reading Atomic Data from /media/data/projects/tardis/tardis-code/tardis/../../data/tardis_example/kurucz_cd23_chianti_H_He.h5
tardis.atomic - INFO - Read Atom Data with UUID=5ca3035ca8b311e3bb684437e69d75d7 and MD5=21095dd25faa1683f4c90c911a00c3f8
[[1mtardis.plasma.base  [0m][[1;34mDEBUG[0m  ]  Updating modules in the following order: ([1mbase.py[0m:195)
tardis.plasma.base - [1;34mDEBUG[0m - Updating modules in the following order:
[[1mtardis.montecarlo.base[0m][[1;34mDEBUG[0m  ]  Electron scattering switched on ([1mbase.py[0m:411)
tardis.montecarlo.base - [1;34mDEBUG[0m - Electron scattering switched on
[[1mtardis.simulation.base[0m][[1;37mINFO[0m   ]  Starting iteration 1/1 ([1mbase.py[0m:194)
t[...]<jupyter_text>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.<jupyter_code>wl, lum = np.loadtxt('/tmp/tardis_spec.txt', unpack=True);
figure()
plot(wl, lum);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11093407687711611, 'fraction_numerical': 0.044811790479984064, 'mean_word_length': 6.184549356223176, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '126307', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1736, 'n_words': 437, 'path': 'docs/running/interaction/integrator.ipynb', 'repo_name': 'Harpreet1999/tardis', 'size': '5021'}