.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_modeling_gallery_spectral_plot_absorbed.py:
.. _absorption-spectral-model:
EBL Absorbption Spectral Model
==============================
This model evaluates absorbed spectral model.
The EBL absorption factor given by
.. math::
\exp{ \left ( -\alpha \times \tau(E, z) \right )}
where :math:`\tau(E, z)` is the optical depth predicted by the model
(`~gammapy.modeling.models.Absorption`), which depends on the energy of the gamma-rays and the
redshift z of the source, and :math:`\alpha` is a scale factor
(default: 1) for the optical depth.
Example plot
------------
Here is an example plot of the model:
.. code-block:: default
from astropy import units as u
import matplotlib.pyplot as plt
from gammapy.modeling.models import (
EBLAbsorptionNormSpectralModel,
Models,
PowerLawSpectralModel,
SkyModel,
)
# Here we illustrate how to create and plot EBL absorption models for a redshift of 0.5
# sphinx_gallery_thumbnail_number = 1
redshift = 0.5
dominguez = EBLAbsorptionNormSpectralModel.read_builtin("dominguez", redshift=redshift)
franceschini = EBLAbsorptionNormSpectralModel.read_builtin(
"franceschini", redshift=redshift
)
finke = EBLAbsorptionNormSpectralModel.read_builtin("finke", redshift=redshift)
plt.figure()
energy_range = [0.08, 3] * u.TeV
opts = dict(energy_range=energy_range, energy_unit="TeV", flux_unit="")
franceschini.plot(label="Franceschini 2008", **opts)
finke.plot(label="Finke 2010", **opts)
dominguez.plot(label="Dominguez 2011", **opts)
plt.ylabel(r"Absorption coefficient [$\exp{(-\tau(E))}$]")
plt.xlim(energy_range.value)
plt.ylim(1e-4, 2)
plt.title(f"EBL models (z={redshift})")
plt.grid(which="both")
plt.legend(loc="best")
# Spectral model corresponding to PKS 2155-304 (quiescent state)
index = 3.53
amplitude = 1.81 * 1e-12 * u.Unit("cm-2 s-1 TeV-1")
reference = 1 * u.TeV
pwl = PowerLawSpectralModel(index=index, amplitude=amplitude, reference=reference)
# The power-law model is multiplied by the EBL norm spectral model
redshift = 0.117
absorption = EBLAbsorptionNormSpectralModel.read_builtin("dominguez", redshift=redshift)
model = pwl * absorption
energy_range = [0.1, 100] * u.TeV
plt.figure()
model.plot(energy_range)
plt.grid(which="both")
plt.ylim(1e-24, 1e-8)
.. rst-class:: sphx-glr-horizontal
*
.. image:: /modeling/gallery/spectral/images/sphx_glr_plot_absorbed_001.png
:alt: EBL models (z=0.5)
:class: sphx-glr-multi-img
*
.. image:: /modeling/gallery/spectral/images/sphx_glr_plot_absorbed_002.png
:alt: plot absorbed
:class: sphx-glr-multi-img
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
/Users/adonath/github/adonath/gammapy/gammapy/utils/interpolation.py:163: RuntimeWarning: overflow encountered in log
return np.log(values)
/Users/adonath/github/adonath/gammapy/gammapy/utils/interpolation.py:163: RuntimeWarning: overflow encountered in log
return np.log(values)
YAML representation
-------------------
Here is an example YAML file using the model:
.. code-block:: default
model = SkyModel(spectral_model=model, name="absorbed-model")
models = Models([model])
print(models.to_yaml())
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
components:
- name: absorbed-model
type: SkyModel
spectral:
type: CompoundSpectralModel
model1:
type: PowerLawSpectralModel
parameters:
- name: index
value: 3.53
- name: amplitude
value: 1.81e-12
unit: cm-2 s-1 TeV-1
- name: reference
value: 1.0
unit: TeV
frozen: true
model2:
type: EBLAbsorptionNormSpectralModel
parameters:
- name: alpha_norm
value: 1.0
frozen: true
- name: redshift
value: 0.117
frozen: true
filename: /Users/adonath/Desktop/gammapy-tutorials/datasets/ebl/ebl_dominguez11.fits.gz
operator: mul
.. _sphx_glr_download_modeling_gallery_spectral_plot_absorbed.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: plot_absorbed.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_absorbed.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_