Note
Go to the end to download the full example code. or to run this example in your browser via Binder
Template spatial model#
This is a spatial model based on a 2D sky map provided as a template.
Example plot#
Here is an example plot of the model:
from gammapy.maps import Map
from gammapy.modeling.models import (
Models,
PowerLawSpectralModel,
SkyModel,
TemplateSpatialModel,
)
filename = "$GAMMAPY_DATA/catalogs/fermi/Extended_archive_v18/Templates/RXJ1713_2016_250GeV.fits"
m = Map.read(filename)
m = m.copy(unit="sr^-1")
model = TemplateSpatialModel(m, filename=filename)
model.plot(add_cbar=True)
/home/runner/work/gammapy-docs/gammapy-docs/gammapy/.tox/build_docs/lib/python3.9/site-packages/astropy/wcs/wcs.py:551: FITSFixedWarning: RADECSYS= 'FK5'
the RADECSYS keyword is deprecated, use RADESYSa.
wcsprm = _wcs.Wcsprm(
/home/runner/work/gammapy-docs/gammapy-docs/gammapy/.tox/build_docs/lib/python3.9/site-packages/astropy/wcs/wcs.py:803: FITSFixedWarning: 'celfix' made the change 'Success'.
warnings.warn(
YAML representation#
Here is an example YAML file using the model:
pwl = PowerLawSpectralModel()
template = TemplateSpatialModel(m, filename=filename)
model = SkyModel(spectral_model=pwl, spatial_model=template, name="pwl-template-model")
models = Models([model])
print(models.to_yaml())
Template file already exits, and overwrite is False
components:
- name: pwl-template-model
type: SkyModel
spectral:
type: PowerLawSpectralModel
parameters:
- name: index
value: 2.0
- name: amplitude
value: 1.0e-12
unit: cm-2 s-1 TeV-1
- name: reference
value: 1.0
unit: TeV
spatial:
type: TemplateSpatialModel
frame: fk5
parameters:
- name: lon_0
value: 258.388
unit: deg
- name: lat_0
value: -39.762199399999986
unit: deg
filename: /home/runner/work/gammapy-docs/gammapy-docs/gammapy-datasets/dev/catalogs/fermi/Extended_archive_v18/Templates/RXJ1713_2016_250GeV.fits
normalize: true
unit: 1 / sr
metadata:
creator: Gammapy 2.0.dev155+g9309a089d
date: '2024-12-18T16:14:17.582805'
origin: null