Note
Go to the end to download the full example code. or to run this example in your browser via Binder
Piecewise norm spatial model#
This model parametrises a piecewise spatial correction with a free norm parameter at each fixed node in longitude, latitude and optionaly 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)
<WCSAxes: >
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())
components:
- type: FoVBackgroundModel
datasets_names:
- dataset
spectral:
type: PowerLawNormSpectralModel
parameters:
- name: norm
value: 1.0
- name: tilt
value: 0.0
- name: reference
value: 1.0
unit: TeV
spatial:
type: PiecewiseNormSpatialModel
frame: galactic
parameters:
- name: norm_0
value: 0.5
- name: norm_1
value: 3.0
- name: norm_2
value: 2.0
- name: norm_3
value: 1.0
lon:
data:
- -308.21500000000003
- -308.21500000000003
- -311.78499999999997
- -311.78499999999997
unit: deg
lat:
data:
- -1.785
- 1.785
- 1.785
- -1.785
unit: deg
metadata:
creator: Gammapy 2.0.dev40+g95c0a5676
date: '2024-11-22T14:02:26.159515'
origin: null