.. 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_constant_spectral.py:
.. _constant-spectral-model:
Constant Spectral Model
=======================
This model takes a constant value along the spectral range.
.. math:: \phi(E) = k
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 ConstantSpectralModel, Models, SkyModel
energy_range = [0.1, 100] * u.TeV
model = ConstantSpectralModel(const="1 / (cm2 s TeV)")
model.plot(energy_range)
plt.grid(which="both")
.. image:: /modeling/gallery/spectral/images/sphx_glr_plot_constant_spectral_001.png
:alt: plot constant spectral
: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="constant-model")
models = Models([model])
print(models.to_yaml())
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
components:
- name: constant-model
type: SkyModel
spectral:
type: ConstantSpectralModel
parameters:
- name: const
value: 1.0
unit: cm-2 s-1 TeV-1
.. _sphx_glr_download_modeling_gallery_spectral_plot_constant_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_constant_spectral.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_constant_spectral.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_