File: plot_template.py

package info (click to toggle)
gammapy 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,800 kB
  • sloc: python: 81,999; makefile: 211; sh: 11; javascript: 10
file content (42 lines) | stat: -rw-r--r-- 928 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
r"""
.. _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:

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)

# %%
# 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())