.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "user-guide/model-gallery/spatial/plot_template.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_user-guide_model-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. .. GENERATED FROM PYTHON SOURCE LINES 11-14 Example plot ------------ Here is an example plot of the model: .. GENERATED FROM PYTHON SOURCE LINES 14-31 .. code-block:: Python 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) .. image-sg:: /user-guide/model-gallery/spatial/images/sphx_glr_plot_template_001.png :alt: plot template :srcset: /user-guide/model-gallery/spatial/images/sphx_glr_plot_template_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /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( .. GENERATED FROM PYTHON SOURCE LINES 32-35 YAML representation ------------------- Here is an example YAML file using the model: .. GENERATED FROM PYTHON SOURCE LINES 35-43 .. code-block:: Python 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()) .. rst-class:: sphx-glr-script-out .. code-block:: none 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 1.3.dev222+g8af9dbfc9 date: '2024-05-01T14:12:22.258143' origin: null .. _sphx_glr_download_user-guide_model-gallery_spatial_plot_template.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/gammapy/gammapy-webpage/main?urlpath=lab/tree/notebooks/dev/user-guide/model-gallery/spatial/plot_template.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_template.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_template.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_