.. 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_template_spectral.py:
.. _template-spectral-model:
Template Spectral Model
=======================
This model is defined by custom tabular values.
The units returned will be the units of the values array provided at
initialization. The model will return values interpolated in
log-space, returning 0 for energies outside of the limits of the provided
energy array.
The class implementation follows closely what has been done in
`naima.models.TemplateSpectralModel`
Example plot
------------
Here is an example plot of the model:
.. code-block:: default
import numpy as np
from astropy import units as u
import matplotlib.pyplot as plt
from gammapy.modeling.models import Models, SkyModel, TemplateSpectralModel
energy_range = [0.1, 1] * u.TeV
energy = np.array([1e6, 3e6, 1e7, 3e7]) * u.MeV
values = np.array([4.4e-38, 2.0e-38, 8.8e-39, 3.9e-39]) * u.Unit("MeV-1 s-1 cm-2")
model = TemplateSpectralModel(energy=energy, values=values)
model.plot(energy_range)
plt.grid(which="both")
.. image:: /modeling/gallery/spectral/images/sphx_glr_plot_template_spectral_001.png
:class: sphx-glr-single-img
YAML representation
-------------------
Here is an example YAML file using the model:
.. code-block:: default
model = SkyModel(spectral_model=model, name="template-model")
models = Models([model])
print(models.to_yaml())
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
components:
- name: template-model
type: SkyModel
spectral:
type: TemplateSpectralModel
parameters:
- {name: norm, value: 1.0, unit: '', min: .nan, max: .nan, frozen: false,
error: 0}
- {name: tilt, value: 0.0, unit: '', min: .nan, max: .nan, frozen: true, error: 0}
- {name: reference, value: 1.0, unit: TeV, min: .nan, max: .nan, frozen: true,
error: 0}
energy:
data: [1000000.0, 3000000.0, 10000000.0, 30000000.0]
unit: MeV
values:
data: [4.4e-38, 2.0e-38, 8.8e-39, 3.9e-39]
unit: 1 / (cm2 MeV s)
.. _sphx_glr_download_modeling_gallery_spectral_plot_template_spectral.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_template_spectral.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_template_spectral.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_