Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Power law norm spectral model#
This model parametrises a power law spectral correction with a norm and tilt parameter.
Example plot#
Here is an example plot of the model:
from astropy import units as u
import matplotlib.pyplot as plt
from gammapy.modeling.models import (
Models,
PowerLawNormSpectralModel,
SkyModel,
TemplateSpectralModel,
)
energy_bounds = [0.1, 100] * u.TeV
energy = [0.3, 1, 3, 10, 30] * u.TeV
values = [40, 30, 20, 10, 1] * u.Unit("TeV-1 s-1 cm-2")
template = TemplateSpectralModel(energy, values)
norm = PowerLawNormSpectralModel(
norm=5,
reference=1 * u.TeV,
)
template.plot(energy_bounds=energy_bounds, label="Template model")
pwl_norm = template * norm
pwl_norm.plot(energy_bounds, label="Template model with PowerLaw norm correction")
plt.legend(loc="best")
plt.grid(which="both")

/home/runner/work/gammapy-docs/gammapy-docs/gammapy/.tox/build_docs/lib/python3.11/site-packages/gammapy/modeling/models/spectral.py:651: UserWarning: This axis already has a converter set and is updating to a potentially incompatible converter
ax.plot(energy.center, flux.quantity[:, 0, 0], **kwargs)
YAML representation#
Here is an example YAML file using the model:
components:
- name: power-law-norm-model
type: SkyModel
spectral:
type: CompoundSpectralModel
model1:
type: TemplateSpectralModel
parameters: []
energy:
data:
- 0.3
- 1.0
- 3.0
- 10.0
- 30.0
unit: TeV
values:
data:
- 40.0
- 30.0
- 20.0
- 10.0
- 1.0
unit: 1 / (TeV s cm2)
model2:
type: PowerLawNormSpectralModel
parameters:
- name: tilt
value: 0.0
- name: norm
value: 5.0
- name: reference
value: 1.0
unit: TeV
operator: mul
metadata:
creator: Gammapy 2.0.dev3116+gf591d5242
date: '2026-03-04T05:47:17.741924'
origin: null