.. 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_piecewise_norm_spatial.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_piecewise_norm_spatial.py: .. _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 optionaly energy. .. GENERATED FROM PYTHON SOURCE LINES 13-16 Example plot ------------ Here is an example plot of the model: .. GENERATED FROM PYTHON SOURCE LINES 16-38 .. code-block:: Python 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) .. image-sg:: /user-guide/model-gallery/spatial/images/sphx_glr_plot_piecewise_norm_spatial_001.png :alt: plot piecewise norm spatial :srcset: /user-guide/model-gallery/spatial/images/sphx_glr_plot_piecewise_norm_spatial_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 39-42 YAML representation ------------------- Here is an example YAML file using the model: .. GENERATED FROM PYTHON SOURCE LINES 42-47 .. code-block:: Python bkg_model = FoVBackgroundModel(spatial_model=model, dataset_name="dataset") models = Models([bkg_model]) print(models.to_yaml()) .. rst-class:: sphx-glr-script-out .. code-block:: none 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 1.3.dev296+g18b65d5cc date: '2024-05-07T18:22:24.821261' origin: null .. _sphx_glr_download_user-guide_model-gallery_spatial_plot_piecewise_norm_spatial.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_piecewise_norm_spatial.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_piecewise_norm_spatial.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_piecewise_norm_spatial.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_