.. 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_spatial_plot_template.py:
.. _template-spatial-model:
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:
.. code-block:: default
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.unit = "sr^-1"
model = TemplateSpatialModel(m)
model.plot(add_cbar=True)
.. image:: /modeling/gallery/spatial/images/sphx_glr_plot_template_001.png
:alt: plot template
:class: sphx-glr-single-img
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
/Users/adonath/software/anaconda3/envs/gammapy-dev/lib/python3.7/site-packages/astropy/wcs/wcs.py:466: FITSFixedWarning: RADECSYS= 'FK5'
the RADECSYS keyword is deprecated, use RADESYSa.
colsel=colsel)
/Users/adonath/software/anaconda3/envs/gammapy-dev/lib/python3.7/site-packages/astropy/wcs/wcs.py:687: FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Invalid DATE-OBS format ' ' is too short'.
FITSFixedWarning)
/Users/adonath/software/anaconda3/envs/gammapy-dev/lib/python3.7/site-packages/astropy/wcs/wcs.py:687: FITSFixedWarning: 'celfix' made the change 'Success'.
FITSFixedWarning)
YAML representation
-------------------
Here is an example YAML file using the model:
.. code-block:: default
pwl = PowerLawSpectralModel()
template = TemplateSpatialModel(m)
model = SkyModel(spectral_model=pwl, spatial_model=template, name="pwl-template-model")
models = Models([model])
print(models.to_yaml())
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
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
frozen: true
spatial:
type: TemplateSpatialModel
frame: fk5
parameters: []
filename: null
normalize: true
unit: 1 / sr
.. _sphx_glr_download_modeling_gallery_spatial_plot_template.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.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_template.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_