File: plot_piecewise_norm_spatial.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 (46 lines) | stat: -rw-r--r-- 1,046 bytes parent folder | download
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
43
44
45
46
r"""
.. _piecewise-norm-spatial:

Piecewise norm spatial model
============================

This model parametrises a piecewise spatial correction
with a free norm parameter at each fixed node in longitude, latitude
and optionally energy.
"""

# %%
# Example plot
# ------------
# Here is an example plot of the model:

import numpy as np
from astropy import units as u
from gammapy.maps import MapCoord, WcsGeom
from gammapy.modeling.models import (
    FoVBackgroundModel,
    Models,
    PiecewiseNormSpatialModel,
)

geom = WcsGeom.create(skydir=(50, 0), npix=(120, 120), binsz=0.03, frame="galactic")
coords = MapCoord.create(geom.footprint)
coords["lon"] *= u.deg
coords["lat"] *= u.deg

model = PiecewiseNormSpatialModel(
    coords, norms=np.array([0.5, 3, 2, 1]), frame="galactic"
)

model.plot(geom=geom)


# %%
# YAML representation
# -------------------
# Here is an example YAML file using the model:

bkg_model = FoVBackgroundModel(spatial_model=model, dataset_name="dataset")
models = Models([bkg_model])

print(models.to_yaml())