.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "user-guide/model-gallery/spectral/plot_piecewise_norm_spectral.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_spectral_plot_piecewise_norm_spectral.py: .. _piecewise-norm-spectral: Piecewise norm spectral model ============================== This model parametrises a piecewise spectral correction with a free norm parameter at each fixed energy node. .. GENERATED FROM PYTHON SOURCE LINES 12-15 Example plot ------------ Here is an example plot of the model: .. GENERATED FROM PYTHON SOURCE LINES 15-34 .. code-block:: Python from astropy import units as u import matplotlib.pyplot as plt from gammapy.modeling.models import ( Models, PiecewiseNormSpectralModel, PowerLawSpectralModel, SkyModel, ) energy_bounds = [0.1, 100] * u.TeV model = PiecewiseNormSpectralModel( energy=[0.1, 1, 3, 10, 30, 100] * u.TeV, norms=[1, 3, 8, 10, 8, 2], ) model.plot(energy_bounds, yunits=u.Unit("")) plt.grid(which="both") .. image-sg:: /user-guide/model-gallery/spectral/images/sphx_glr_plot_piecewise_norm_spectral_001.png :alt: plot piecewise norm spectral :srcset: /user-guide/model-gallery/spectral/images/sphx_glr_plot_piecewise_norm_spectral_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-38 YAML representation ------------------- Here is an example YAML file using the model: .. GENERATED FROM PYTHON SOURCE LINES 38-44 .. code-block:: Python model = model * PowerLawSpectralModel() model = SkyModel(spectral_model=model, name="piecewise-norm-model") models = Models([model]) print(models.to_yaml()) .. rst-class:: sphx-glr-script-out .. code-block:: none components: - name: piecewise-norm-model type: SkyModel spectral: type: CompoundSpectralModel model1: type: PiecewiseNormSpectralModel parameters: - name: norm_0 value: 1.0 - name: norm_1 value: 3.0 - name: norm_2 value: 8.0 - name: norm_3 value: 10.0 - name: norm_4 value: 8.0 - name: norm_5 value: 2.0 energy: data: - 0.1 - 1.0 - 3.0 - 10.0 - 30.0 - 100.0 unit: TeV interp: log model2: 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 operator: mul metadata: creator: Gammapy 1.3.dev241+g0271bebfc date: '2024-05-03T15:02:26.704218' origin: null .. _sphx_glr_download_user-guide_model-gallery_spectral_plot_piecewise_norm_spectral.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/spectral/plot_piecewise_norm_spectral.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_piecewise_norm_spectral.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_piecewise_norm_spectral.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_