In this notebook we create a simple astromodels spectrum and then apply EBL attenuation, as a function of redshift and energy.
The EBLattenuation class in astromodels relies directly on the ebltable package by Manuel Meyer, see ebltable .
In [1]:
from threeML import *
In [2]:
# define power law spectrum
sourceName = 'Mrk421'
spectrum = Powerlaw()
#put it into a PS model, in this context primarily in order to establish units
source1 = PointSource(sourceName, ra=166.11, dec=38.21, spectral_shape=spectrum)
#and set parameters:
spectrum.piv = 1. * u.TeV
spectrum.K = 1.e-11 / (u.TeV * u.cm**2 * u.s)
spectrum.index = -2.2
In [3]:
#define attenuated spectrum:
ebl = EBLattenuation()
spectrumEBL = spectrum * ebl
source2 = PointSource(sourceName, ra=166.11, dec=38.21, spectral_shape=spectrumEBL)
#show new parameter names:
spectrumEBL.display()
In [4]:
#set redshift:
spectrumEBL.redshift_2 = 0.031*u.dimensionless_unscaled
Currently, the 3ML implementation selects the Dominguez model for optical depth by default.
In the next cell, we also define EBL attenuation for a different model.
In [5]:
#new EBL with different model:
ebl2 = EBLattenuation()
ebl2.set_ebl_model('gilmore')
spectrumEBL_Gil = spectrum*ebl2
spectrumEBL_Gil.redshift_2 = 0.031*u.dimensionless_unscaled
source3 = PointSource(sourceName, ra=166.11, dec=38.21, spectral_shape=spectrumEBL_Gil)
In [6]:
#use matplotlib to plot both spectra:
import matplotlib.pyplot as plt
import numpy as np
energies = np.logspace(-1.,2.,100)*u.TeV
#factor 1e9 to convert to TeV^-1
plt.loglog(energies,spectrum(energies)*1e9,label="intrinsic")
plt.loglog(energies,spectrumEBL(energies)*1e9,label="with Dominguez EBL attenuation")
plt.loglog(energies,spectrumEBL_Gil(energies)*1e9,label="with Gilmore EBL attenuation")
plt.legend(loc=1)
plt.xlim(0.2,100.)
plt.ylim(1e-19,1e-9)
plt.xlabel("Energy [TeV]")
plt.ylabel(r"Flux (ph cm$^{-2}$ s$^{-1}$ TeV$^{-1}$)")
plt.show()